help with finding insertblock and its attribs
help with finding insertblock and its attribs
i am migrating a dll from opendwg tk to dwgdirect 1.08. the part i am working on right now, takes all entities from paperspace, then modelspace, and whenever we find an insertblock entity we list its attributes. from what i can understand, once you have an insert block with the attribsfollow flag, all following entities are attributes until you meet an end sequence.
[code]
//old code
//this code is executed in a loop and breaks out when we have an end block entitiy
int cscanattrib:

rocessentity(void)
{
if (!adgetentity(madtb->blkh.entitylist,madenhd,maden))
return(0);
if (madenhd->enttype == ad_ent_insert && maden->insert.attribsfollow)
for (int i = 0; i < matchcount;i++)
insert = 1;
return(1);
if (madenhd->enttype == ad_ent_seqend)
insert = 0;
if (madenhd->enttype == ad_ent_attrib && insert)
fprintf(outf,"%s,%s,%s\n",blockname,maden->attrib.tag,maden->attrib.attval);
return (madenhd->enttype != ad_ent_endblk);
}
</pre><hr></blockquote>
i am trying to do the same thing but in dwgdirect. never mind most of the code, especially what's in comments. the problem is that none of my entities are gotten as insertblocks, but rather as referenceblocks. also i am left wondering why the hell would i bother looking for an end sequence once i have my insert block since i can just get an attribute itterator from it.
[code]
int cscanattrib:

rocessentity(void)
{
//process entity is called in a loop, and pentiter points to the current entity
//get the entity in a pointer
oddbentityptr pent = pentiter->objectid().safeopenobject();
//check if entity is insert block
if (pent->iskindof(oddbminsertblock::desc()))
//first we have to check if it is a block reference
//if (pent->iskindof(oddbblockreference::desc()))
{
oddbblockreferenceptr pblockref = pentiter->entity();
oddbminsertblockptr pminsert = oddbminsertblock::cast(pblockref);
//afxmessagebox(pblockref->isa()->name());
//if (pblockref->iskindof(oddbminsertblock::desc()))
//if (pminsert->iskindof(oddbblockreference::desc()))
if (!pminsert.isnull())
{
// cast the entity as a insert block ptr
//oddbminsertblockptr pminsert = oddbminsertblock::cast(pblockref);
//check if block contains attributes
int attrcount = 0;
oddbobjectiteratorptr pattr = pblockref->attributeiterator();
for (; !pattr->done(); pattr->step())
{
if (!pattr.isnull())
attrcount++;
}
//if contains attributes, then loop in the list of blocks
if (attrcount > 0)
{
insert = 1;
return(1);
}
}
}
//check if entity is sequence end
if ( pent->iskindof(oddbsequenceend::desc()))
insert = 0;
//check if entity is attrib and if insert is > 0
if (pent->iskindof(oddbattribute::desc()) && insert)
{
//cast entity as attribute pointer
oddbattributeptr pattr = pentiter->entity();
//print attribute to file
fprintf(outf, "%s,%s,%s\n", blockname, pattr->tag(), pattr->textstring());
}
// return 1 or -1 if entity is not acdbblockend
return pent->iskindof(oddbblockend::desc());
}
</pre><hr></blockquote>
i am looking for any kind of help, i am sure this is a walk in the park for some of you guys, unfortunately due to the poor amount of documentation available, i am left scratching my head over most of my problems (or rather beating it against the walls)
thanks in advance
entity iterator obtained by oddbblocktablerecord::newiterator() will never return you blockbegin, blockend, seqend or attribute (unlike odt).
attributes should be accessed via oddbblockreference::attributeiterator()
since oddbminsertblock is derived from oddbblockreference pent->iskindof(oddbblockreference: esc()) should return true for both oddbblockreference and oddbminsertblock
sergey slezkin
attributeiterator returns nothing
using dwgdirect 1.08, i'm creating a block reference ("block insert") entity, then using the oddbblockreference::attributeiterator() to loop thru the attributes "attached" to this block reference entity (with the intention of then prompting the user for values for these attributes).
however, the attributeiterator returns nothing, even when there are attribute definition entities in the block associated with this block reference (tested by creating a block with attribute entities in autocad).
from the dwgdirect reference doc, i'm not completely sure whether i should be adding these attribute entities to the block reference manually (using appendattribute() ), or whether they are added automatically when the block reference is created.
<code>
oddbblockreferenceptr pblockref = oddbblockreference::createobject();
// must set refrenced blockid before appending to db!!!
pblockref->setdatabasedefaults(pdb);
pblockref->setblocktablerecord(blockid);
pblockref->setposition(p1);
pblockref->setlayer(pdb->getclayer());
pspace->appendoddbentity(pblockref);
// scaling code cut out here
// test - check out attached attributes
trace0(":::blockref attribs:\n");
oddbobjectiteratorptr poi = pblockref->attributeiterator();
while( !poi->done() )
{
oddbentityptr pent = poi->entity();
trace1(" blockref attrib: %08x \n", pent->objectid());
poi->step();
}
</code>
also, dwgdirect renders the attributes in a block reference where the "constant" flag is set, otherwise not.
any suggestions appreciated.
regards,
james
you need to add non-constsnt attributes to block reference "manually":
void appendattributestoblockref(oddbblockreference *pblkref, oddbobjectid insblkid)
{
// check for attribute definition
odgematrix3d xform = pblkref->blocktransform();
oddbblocktablerecordptr pinsblock = insblkid.safeopenobject();
// correct transform matrix by base point
oddbblocktablerecordptr pbr = pblkref->blocktablerecord().openobject();
odgepoint3d basept(pbr->origin());
xform *= odgematrix3d::translation(odgepoint3d::korigin - basept);
// walk through the block and looking for att.def
if (pinsblock->hasattributedefinitions())
{
// get attribute entities from this block
oddbobjectiteratorptr pit = pinsblock->newiterator();
while (!pit->done())
{
oddbentityptr pentity = pit->entity();
if ( pentity->iskindof(oddbattributedefinition::desc()) )
{
oddbattributedefinitionptr pattdef;
pattdef = pentity;
if (!pattdef->isconstant())
{
oddbattributeptr pattr = oddbattribute::createobject();
pattr->setattributefromblock(pattdef, xform);
// set attribute value here
pblkref->appendattribute(pattr);
}
}
pit->step();
} // end of while (!pit->done())
} // end of if (pinsblock->hasattributedefinitions())
return;
}
sergey slezkin
thanks sergey - it works great
[code]
int cscanattrib:

rocessentity(void)
{
//process entity is called in a loop, and pentiter points to the current entity
//get the entity in a pointer
oddbentityptr pent = pentiter->objectid().safeopenobject();
//check if entity is insert block
if (pent->iskindof(oddbminsertblock::desc()))
//first we have to check if it is a block reference
//if (pent->iskindof(oddbblockreference::desc()))
{
oddbblockreferenceptr pblockref = pentiter->entity();
oddbminsertblockptr pminsert = oddbminsertblock::cast(pblockref);
jeff/sergey,
i'd like to use a code segment from your example above in my application program. i'm checking to see if the entity is a block reference and if it is set the ptr to it.
// open the entity
oddbentityptr pent = id.safeopenobject();
// check if entity is block reference
if(pent->iskindof(oddbblockreference::desc()))
{
oddbblockreferenceptr pblockref = pent->entity();
oddbminsertblockptr pminsert = oddbminsertblock::cast (pblockref);
}
i've got a question regarding this line from above:
oddbblockreferenceptr pblockref = pentiter->entity();
what is "->"? how can i get this line to compile? i've tried to compile this line of code but get compile errors.
thanks,
lhashimoto