![]() |
【转帖】avoiding to read block definitions as entities
avoiding to read block definitions as entities
avoiding to read block definitions as entities hello, i'm new at dwgdirect. i'm trying to read dwg files from within an application. i've meet a problem when the dwg file contains a block definition and does not contain a reference to it. i've used the following code in order to read all the entities present in the dwg file: oddbblocktableptr pblocks = theapp.pdb->getblocktableid().safeopenobject(); oddbsymboltableiteratorptr pblkiter = pblocks->newiterator(); for(pblkiter->start(); !pblkiter->done();pblkiter->step()) { oddbblocktablerecordptr pblock = pblkiter->getrecordid().safeopenobject(); oddbobjectiteratorptr pentiter = pblock->newiterator(); ... ... the problem i meet is that this code reads all the entities visible in the dwg file plus the entities that compound the block definition,and there is no reference to that block definition in the file. i can assume that all dwg files that my application must read are "model space" dwg files, so my question is if the following modification to the above code is enough to be sure of reading all the entities visible and only the visible entities in a dwg file: oddbblocktableptr pblocks = theapp.pdb->getblocktableid().safeopenobject(); oddbsymboltableiteratorptr pblkiter = pblocks->newiterator(); odstring odstringnombrebloque; for (pblkiter->start(); !pblkiter->done(); pblkiter->step()) { oddbblocktablerecordptr pblock = pblkiter->getrecordid().safeopenobject(); odstringnombrebloque = pblkiter->getrecord()->getname(); if(odstringnombrebloque == "*model_space") { oddbobjectiteratorptr pentiter = pblock->newiterator(); ... ... 1. your modified code version will loop through all model space entities but model space may contain insertions of other blocks (block references) and you may need to process such blocks (inserted into model space). 2. oddbdatabase class has method getmodelspaceid(). it's better to use it instead of looping through all blocks and comparing block name with a string constant. btw, if r14 file is loaded model space block may have name "*model_space" - uppercased. sergey slezkin thanks for your answer, sergey. now, i have another question. when i use the following code: oddbvoidptrarray pvoidblockreference; oddbentityptr pentidadesblockreference; odresult odres; odres = pblockreference ->explode(pvoidblockreference); ... ... how must i do in order to obtain a valid oddbentityptr from the oddbvoidptrarray? you can use: oddbentityptr pent = pvoidblockreference[index]; another option is to avoid creating temporary objects using the following code: oddbblocktablerecordptr pblockrec = preference->blocktablerecord()->safeopenobject(); oddbobjectiteratorptr pentiter = pblockrec->newiterator(); // now you can process entities in block. but they are not transformed by block reference parameters. trasformation can be get: odgematrix3d xform = preference->blocktransform(); sergey slezkin the two ways you suggested work perfectly. thanks a lot. see you. |
所有的时间均为北京时间。 现在的时间是 06:30 PM. |