几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » AutoCAD二次开发 » DirectDWG
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


 
 
主题工具 搜索本主题 显示模式
旧 2009-05-05, 12:06 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】help with finding insertblock and its attribs

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-&gt;objectid().safeopenobject();
//check if entity is insert block
if (pent-&gt;iskindof(oddbminsertblock::desc()))
//first we have to check if it is a block reference
//if (pent-&gt;iskindof(oddbblockreference::desc()))
{
oddbblockreferenceptr pblockref = pentiter-&gt;entity();
oddbminsertblockptr pminsert = oddbminsertblock::cast(pblockref);
//afxmessagebox(pblockref-&gt;isa()-&gt;name());
//if (pblockref-&gt;iskindof(oddbminsertblock::desc()))
//if (pminsert-&gt;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-&gt;attributeiterator();
for (; !pattr-&gt;done(); pattr-&gt;step())
{
if (!pattr.isnull())
attrcount++;
}
//if contains attributes, then loop in the list of blocks
if (attrcount &gt; 0)
{
insert = 1;
return(1);
}
}
}
//check if entity is sequence end
if ( pent-&gt;iskindof(oddbsequenceend::desc()))
insert = 0;
//check if entity is attrib and if insert is &gt; 0
if (pent-&gt;iskindof(oddbattribute::desc()) && insert)
{
//cast entity as attribute pointer
oddbattributeptr pattr = pentiter-&gt;entity();
//print attribute to file
fprintf(outf, "%s,%s,%s\n", blockname, pattr-&gt;tag(), pattr-&gt;textstring());
}
// return 1 or -1 if entity is not acdbblockend
return pent-&gt;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-&gt;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-&gt;objectid().safeopenobject();
//check if entity is insert block
if (pent-&gt;iskindof(oddbminsertblock::desc()))
//first we have to check if it is a block reference
//if (pent-&gt;iskindof(oddbblockreference::desc()))
{
oddbblockreferenceptr pblockref = pentiter-&gt;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-&gt;entity();
oddbminsertblockptr pminsert = oddbminsertblock::cast (pblockref);
}
i've got a question regarding this line from above:
oddbblockreferenceptr pblockref = pentiter-&gt;entity();
what is "-&gt"? how can i get this line to compile? i've tried to compile this line of code but get compile errors.
thanks,
lhashimoto
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭



所有的时间均为北京时间。 现在的时间是 12:44 PM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多