![]() |
【转帖】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. |