I'm trying to create a generic function to insert blocks with attributes, but i need more information about sds_cmd function or just a simple example.
i'll post a example of my generic function.
tks
Fábio[/list]
generic function
#2Code: Select all
void Sh_Sds_Functions::prepareListInsert( const wchar_t *entityName,sds_point ponto,sds_real escalax,sds_real escalay,sds_real angulo,array<ListaGenerica^>^ lista)
{
struct sds_resbuf * root; // This won't change, or we would lose the list in memory
struct sds_resbuf * conductor; // This will point to each node as it traverses the list
root = sds_newrb(SDS_RTSTR); // Sets it to actually point to something
root->rbnext = 0; // Otherwise it would not work well
root->restype = 0;
root->resval.rstring = L"INSERT";
conductor = root; // The conductor points to the first node
if ( conductor != 0 ) {
while ( conductor->rbnext != 0)
conductor = conductor->rbnext;
}
conductor->rbnext = sds_newrb(SDS_RTENAME); // Creates a node at the end of the list
conductor = conductor->rbnext; // Points to that node
conductor->rbnext = 0; // Prevents it from going any further
conductor->restype = 2;
conductor->resval.rstring = (wchar_t *)entityName;
conductor->rbnext = sds_newrb(SDS_RTPOINT); // Creates a node at the end of the list
conductor = conductor->rbnext; // Points to that node
conductor->rbnext = 0; // Prevents it from going any further
conductor->restype = 10;
conductor->resval.rpoint[0] = ponto[0];
conductor->resval.rpoint[1] = ponto[1];
conductor->resval.rpoint[2] = ponto[2];
conductor->rbnext = sds_newrb(SDS_RTREAL); // Creates a node at the end of the list
conductor = conductor->rbnext; // Points to that node
conductor->rbnext = 0; // Prevents it from going any further
conductor->restype = 41;
conductor->resval.rreal = escalax;
conductor->rbnext = sds_newrb(SDS_RTREAL); // Creates a node at the end of the list
conductor = conductor->rbnext; // Points to that node
conductor->rbnext = 0; // Prevents it from going any further
conductor->restype = 42;
conductor->resval.rreal = escalay;
conductor->rbnext = sds_newrb(SDS_RTREAL); // Creates a node at the end of the list
conductor = conductor->rbnext; // Points to that node
conductor->rbnext = 0; // Prevents it from going any further
conductor->restype = 50;
conductor->resval.rreal = angulo;
for (int i = 0;i < lista->Length; i++)
{
conductor->rbnext = sds_newrb(lista[i]->pTipo); // Creates a node at the end of the list
conductor = conductor->rbnext; // Points to that node
conductor->rbnext = 0; // Prevents it from going any further
conductor->restype = lista[i]->pTipo;
switch (lista[i]->pTipo)
{
case RTSTR:
{
conductor->resval.rstring = (wchar_t*)lista[i]->pValorString;
break;
}
case RTSHORT:
{
conductor->resval.rint = lista[i]->pValorInteiro;
break;
}
case RTREAL:
{
Math^ math;
sds_real valorReal = math->Round((lista[i]->pValorReal),2);
conductor->resval.rreal = valorReal;
break;
}
}
}
conductor->rbnext = sds_newrb(SDS_RTNONE); // Creates a node at the end of the list
conductor = conductor->rbnext; // Points to that node
conductor->rbnext = 0; // Prevents it from going any further
insertBlock(root);
}
void Sh_Sds_Functions::insertBlock(struct sds_resbuf *prbCmdList )
{
sds_cmd(prbCmdList);
sds_relrb(prbCmdList);
}
Any ideas ?
insercao de bloco atributado...
#3Eu uso este código para inserir um bloco atributado...
Pode ser adaptado para um número variável de atributos...
Se quiser alterar, compartilhe o resultado...
struct sds_resbuf *rb = NULL;
sds_point pa = { 100.0, 100.0, 0.0};
rb = sds_buildlist(RTDXF0, "TESTE",
10, pa,
40, 1.0,
50, 0.0,
0);
InsertBlock(rb,
"Este é o atributo A",
"Este é o argumento B",
"E finalmente este é o argumento C para esta inserção");
// a função:
void InsertBlockAtributado(struct sds_resbuf *rb, char *A, char *B, char *C)
// troque os argumentos dos atributos por
// sua lista de atributos e ajuste o código
{
while (rb->restype != 0) rb = rb->rbnext;
char blk[31] = "";
strcpy_s(blk, 31, rb->resval.rstring);
if (is_debug)
sds_printf("\n-> Nome do bloco = %s", blk);
while (rb->restype != 10) rb = rb->rbnext;
sds_point p10;
p10[0] = rb->resval.rpoint[0];
p10[1] = rb->resval.rpoint[1];
p10[2] = rb->resval.rpoint[2];
while (rb->restype != 40) rb = rb->rbnext;
sds_real escala;
escala = rb->resval.rreal;
if (is_debug)
sds_printf("\n-> Escala do bloco = %4.3f", escala);
while (rb->restype != 50) rb = rb->rbnext;
sds_real angulo;
angulo = rb->resval.rreal;
if (is_debug)
sds_printf("\n-> Angulo do bloco = %4.3f", angulo);
sds_relrb(rb);
if (is_debug)
sds_printf("\n-> Atributos = %s, %s, %s", A, B, C);
// Utilizando sds_command no lugar de sds_cmd
// Bom desligar a variável OSMODE
sds_command(RTSTR, "_.INSERT",
RTSTR, blk,
RT3DPOINT, p10,
RTREAL, escala,
RTREAL, escala,
RTREAL, angulo,
RTNONE);
// Lembrar de ligar a variável ATTREQ
// Agora passamos os atributos...
// Você poderá alterar para uma lista com um número variável de atributos e
// passá-los com um for(...)
sds_command(RTSTR, A,
RTSTR, B,
RTSTR, C,
RTNONE);
sds_retvoid();
}
Pode ser adaptado para um número variável de atributos...
Se quiser alterar, compartilhe o resultado...
struct sds_resbuf *rb = NULL;
sds_point pa = { 100.0, 100.0, 0.0};
rb = sds_buildlist(RTDXF0, "TESTE",
10, pa,
40, 1.0,
50, 0.0,
0);
InsertBlock(rb,
"Este é o atributo A",
"Este é o argumento B",
"E finalmente este é o argumento C para esta inserção");
// a função:
void InsertBlockAtributado(struct sds_resbuf *rb, char *A, char *B, char *C)
// troque os argumentos dos atributos por
// sua lista de atributos e ajuste o código
{
while (rb->restype != 0) rb = rb->rbnext;
char blk[31] = "";
strcpy_s(blk, 31, rb->resval.rstring);
if (is_debug)
sds_printf("\n-> Nome do bloco = %s", blk);
while (rb->restype != 10) rb = rb->rbnext;
sds_point p10;
p10[0] = rb->resval.rpoint[0];
p10[1] = rb->resval.rpoint[1];
p10[2] = rb->resval.rpoint[2];
while (rb->restype != 40) rb = rb->rbnext;
sds_real escala;
escala = rb->resval.rreal;
if (is_debug)
sds_printf("\n-> Escala do bloco = %4.3f", escala);
while (rb->restype != 50) rb = rb->rbnext;
sds_real angulo;
angulo = rb->resval.rreal;
if (is_debug)
sds_printf("\n-> Angulo do bloco = %4.3f", angulo);
sds_relrb(rb);
if (is_debug)
sds_printf("\n-> Atributos = %s, %s, %s", A, B, C);
// Utilizando sds_command no lugar de sds_cmd
// Bom desligar a variável OSMODE
sds_command(RTSTR, "_.INSERT",
RTSTR, blk,
RT3DPOINT, p10,
RTREAL, escala,
RTREAL, escala,
RTREAL, angulo,
RTNONE);
// Lembrar de ligar a variável ATTREQ
// Agora passamos os atributos...
// Você poderá alterar para uma lista com um número variável de atributos e
// passá-los com um for(...)
sds_command(RTSTR, A,
RTSTR, B,
RTSTR, C,
RTNONE);
sds_retvoid();
}
#4
simplificando...
void InsertBlock2(int i, char *nome, sds_real escala, sds_real angulo, sds_point p10, char *a[])
{
sds_command(RTSTR, "_.INSERT",
RTSTR, nome,
RT3DPOINT, p10,
RTREAL, escala,
RTREAL, escala,
RTREAL, angulo,
RTNONE);
int cn;
for(cn=0; cn<i; cn++)
sds_command(RTSTR, a[cn], RTNONE);
sds_retvoid();
}
[/code]
void InsertBlock2(int i, char *nome, sds_real escala, sds_real angulo, sds_point p10, char *a[])
{
sds_command(RTSTR, "_.INSERT",
RTSTR, nome,
RT3DPOINT, p10,
RTREAL, escala,
RTREAL, escala,
RTREAL, angulo,
RTNONE);
int cn;
for(cn=0; cn<i; cn++)
sds_command(RTSTR, a[cn], RTNONE);
sds_retvoid();
}
[/code]
#5
aproveitei e inseri duas funções na minha biblioteca...
void InsertBlock(char *blk,
sds_point p10,
sds_real escala,
sds_real angulo)
{
struct sds_resbuf osmode;
osmode.restype = RTSHORT;
sds_getvar("OSMODE", &osmode);
sds_command(RTSTR, "OSMODE",
RTSHORT, 0,
RTSTR, "_.INSERT",
RTSTR, blk,
RT3DPOINT, p10,
RTREAL, escala,
RTREAL, escala,
RTREAL, angulo,
RTNONE);
sds_setvar("OSMODE", &osmode);
sds_retvoid();
}
void InsertBlockA(char *blk,
sds_point p10,
sds_real escala,
sds_real angulo,
int i,
char *a[])
{
struct sds_resbuf attreq, osmode;
attreq.restype = RTSHORT;
osmode.restype = RTSHORT;
sds_getvar("ATTREQ", &attreq);
sds_getvar("OSMODE", &osmode);
sds_command(RTSTR, "ATTREQ",
RTSHORT, 1,
RTSTR, "OSMODE",
RTSHORT, 0,
RTSTR, "_.INSERT",
RTSTR, blk,
RT3DPOINT, p10,
RTREAL, escala,
RTREAL, escala,
RTREAL, angulo,
RTNONE);
int cn;
for(cn=0; cn<i; cn++)
sds_command(RTSTR, a[cn], RTNONE);
sds_setvar("ATTREQ", &attreq);
sds_setvar("OSMODE", &osmode);
sds_retvoid();
}
void InsertBlock(char *blk,
sds_point p10,
sds_real escala,
sds_real angulo)
{
struct sds_resbuf osmode;
osmode.restype = RTSHORT;
sds_getvar("OSMODE", &osmode);
sds_command(RTSTR, "OSMODE",
RTSHORT, 0,
RTSTR, "_.INSERT",
RTSTR, blk,
RT3DPOINT, p10,
RTREAL, escala,
RTREAL, escala,
RTREAL, angulo,
RTNONE);
sds_setvar("OSMODE", &osmode);
sds_retvoid();
}
void InsertBlockA(char *blk,
sds_point p10,
sds_real escala,
sds_real angulo,
int i,
char *a[])
{
struct sds_resbuf attreq, osmode;
attreq.restype = RTSHORT;
osmode.restype = RTSHORT;
sds_getvar("ATTREQ", &attreq);
sds_getvar("OSMODE", &osmode);
sds_command(RTSTR, "ATTREQ",
RTSHORT, 1,
RTSTR, "OSMODE",
RTSHORT, 0,
RTSTR, "_.INSERT",
RTSTR, blk,
RT3DPOINT, p10,
RTREAL, escala,
RTREAL, escala,
RTREAL, angulo,
RTNONE);
int cn;
for(cn=0; cn<i; cn++)
sds_command(RTSTR, a[cn], RTNONE);
sds_setvar("ATTREQ", &attreq);
sds_setvar("OSMODE", &osmode);
sds_retvoid();
}
obrigado
#6E.fernal obrigado pela ajuda novamente. Utilizei o a função que você postou e funcionou perfeitamente.
Estou usando a versão 7.1.1596.O.S do Intellicad.
Está acontecendo um erro muito estranho. A primeira vez que ele insere o bloco ele insere perfeitamente, porém quando vou inserir o mesmo bloco a segunda vez somente alterando os pontos de inserção está dando erro no comando insert. na versão anterior do intellicad, não acontecia esse erro. Eles modificam deliberadamente as libs do sds ?
Abs
Fabio
Estou usando a versão 7.1.1596.O.S do Intellicad.
Está acontecendo um erro muito estranho. A primeira vez que ele insere o bloco ele insere perfeitamente, porém quando vou inserir o mesmo bloco a segunda vez somente alterando os pontos de inserção está dando erro no comando insert. na versão anterior do intellicad, não acontecia esse erro. Eles modificam deliberadamente as libs do sds ?
Abs
Fabio
Resolvido
#8O que aconteceu foi simples, mas na hora deu uma dor de cabeça.
Eu inseria o bloco usando o path + nome do arquivo completo. Na versão anterior ele incluia sem problemas. Na versão atual eles inseriram uma pergunta, eles identificavam o bloco existente e se era necessário sobreescrever o bloco. Agora apenas utilizo o nome do bloco sem mais informações de arquivo e extensão do arquivo. Coisas do aprendizado diário.
Mesmo assim mais uma vez obrigado pela ajuda.
Abs
Fábio
Eu inseria o bloco usando o path + nome do arquivo completo. Na versão anterior ele incluia sem problemas. Na versão atual eles inseriram uma pergunta, eles identificavam o bloco existente e se era necessário sobreescrever o bloco. Agora apenas utilizo o nome do bloco sem mais informações de arquivo e extensão do arquivo. Coisas do aprendizado diário.
Mesmo assim mais uma vez obrigado pela ajuda.
Abs
Fábio