![]() |
【转帖】urgent - Block Is Not Defined Error In Autocad
urgent - block is not defined error in autocad
urgent - block is not defined error in autocad when i try to add block from one database to other empty database i got an error of undefined block error when i open it into autocad 2007. when i audit the oddbdatabase it shows me ok. i added herewith that block file for reference. i added herewith code for reference. *************************************** ** add objects (drawingframe, header, tolerancetable etc.) into the main database. @param objectname describe name of the drawing object. @param path describe path of template file for the drawing object. @param xposition describe x position of block. @param yposition describe y position of block. @param orientation describe orientation of block. @return void */ bool templategenerator::addobject(const char *objectname, const char *path, double xposition, double yposition, double orientation) { if (pdatabase.isnull()) { return false; } oddbdatabaseptr pobjectdatabase; pobjectdatabase = templatehandler.readfile(path, true, false, oda ::ksharedenyno); if (pobjectdatabase.isnull()) { return false; } oddbblocktableptr pblocks = pobjectdatabase->getblocktableid().safeopenobject (oddb::kforwrite); oddbsymboltableiteratorptr pblkiter = pblocks->newiterator(); int count = 0; for (pblkiter->start(); !pblkiter->done(); pblkiter->step()) { oddbblocktablerecordptr pms = pblkiter->getrecordid().safeopenobject(oddb ::kforwrite); oddbobjectiteratorptr pentiter = pms->newiterator(); for (pentiter->start(); !pentiter->done(); pentiter->step()) { oddbentityptr pent = pentiter->entity(oddb::kforwrite); oddbblockreferenceptr pref = oddbblockreference::cast(pent); if (!pref.isnull()) { oddbblocktablerecordptr pchildblock = pref->blocktablerecord() .safeopenobject(oddb::kforwrite); if (pchildblock->getname() != objectname) { ostringstream oss; oss << objectname; oss << count; string val = oss.str(); pchildblock->setname(val.c_str()); count++; } } } } oddbobjectid blockid = pdatabase->insert(objectname, pobjectdatabase, true); oddbobjectid blocktableid = pdatabase->getblocktableid(); oddbsymboltableptr pblocktable = blocktableid.safeopenobject(); oddbblocktablerecordptr pmainblock = pblocktable->getat("*model_space", oddb ::kforwrite); addinsert(pdatabase, pmainblock, blockid, xposition, yposition, orientation); pobjectdatabase.release(); pobjectdatabase = 0; return true; } ************************************************** /** internal function. insert block in database with specified position and orientation. @param pdb describe main database. @param pblock describe table of blocks. @param blockid describe blockid of block which needs to be added. @param xposition describe x position of block. @param yposition describe y position of block. @param orientation describe orientation of block. @return void */ void addinsert(oddbdatabase *pdb, // owning database oddbblocktablerecord *pblock, // block to which insert will be added const oddbobjectid &blockid, // id of block to be inserted double xposition, double yposition, double orientation) { oddbobjectid brefid; // create the new insert entity. oddbblockreferenceptr pblkref = oddbblockreference::createobject(); // add the entity to the parent block. brefid = pblock->appendoddbentity(pblkref); // set the remaining entity properties. pblkref->setblocktablerecord(blockid); pblkref->setscalefactors(odgescale3d(1.0, 1.0, 1.0)); pblkref->setposition(odgepoint3d(xposition, yposition, 0)); //convert orientation/rotation into radian. pblkref->setrotation(orientation *(m_pi / 180.0)); } ************************************************** ****** earlier it was working perfectly when i used header block without attributes. let me know what is the problem.. regards, ravindra ghetia attached files more info a0-a4_header_h1_en_new.dxf new block with attributes... a0-a4_header_h1_en.dxf old block without attributes.. please help.. ravindra ghetia it is not working code is working for all other blocks which do not have attributes. but it is not working with block which i specified here with. i received undefined block error when i opened it into autocad. |
所有的时间均为北京时间。 现在的时间是 09:44 PM. |