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

几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 (http://www.dimcax.com/hust/index.php)
-   DirectDWG (http://www.dimcax.com/hust/forumdisplay.php?f=89)
-   -   【转帖】name of block (http://www.dimcax.com/hust/showthread.php?t=17291)

yang686526 2009-05-06 06:18 PM

【转帖】name of block
 
name of block
name of block
hi there,
i inserted a block (created an instance of a block) in dwg file. i am trying to get the name of the block using following code:
...
oddbentityptr pent = pentiter->entity(oddb::kforread);
oddbblocktablerecordptr pblock = pent->blockid().safeopenobject();
strcpy(entname, pblock->getname());
...
but all i get is the model_space block name. anyone can tell me how i get the block name this entity belongs to?
thanks,
al
i assume you have created a oddbblockreference (block insert) entity in the model space. however, the blockid() is a method of any entity, and it returns the block which contains that entity - in this case the oddbblockreference entity is contained by the model space so that the block name will be "*model_space" or whatever.
you need to cast the entity to a oddbblockreference and use its method blocktablerecord():
...
oddbentityptr pent = pentiter->entity(oddb::kforread);
oddbblockreferenceptr pref = pent->cast(oddbblockreference::desc());
if (pref != 0) {
oddbblocktablerecordptr pblock = pref->blocktablerecord().safeopenobject();
strcpy(entname, pblock->getname());
}
...
best regards
chudomir
chudomir
thank you for the answer. i think it is the right path.
however, after i called these two lines:
oddbentityptr pent = pentiter->entity(oddb::kforread);
oddbblockreferenceptr pref = pent->cast(oddbblockreference::desc());
the pref is null for that entity. by the way, i went to the dwg to make sure the entity has a block reference. do you have any idea the reason?
thank you,
al
chudomir
i modified the code a little bit. it works.
i casted it like this:
oddbblockreferenceptr pref = oddbblockreference::cast(pent);
thank you for the help,
al


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