![]() |
【转帖】how to copy properly a dimension entity
how to copy properly a dimension entity?
how to copy properly a dimension entity? here is a sample code which i run in odamfcappdll (dwgdirect 1.12.1) code: oddbentityptr getnewdim() { oddbrotateddimensionptr pdim = oddbrotateddimension::createobject(); pdim->setxline1point(odgepoint3d(0,0,0)); pdim->setxline2point(odgepoint3d(10,0,0)); pdim->setdimlinepoint(odgepoint3d(5,5,0)); return pdim; } void cdwgview::ontestcommandsdimensionbug() { try { oddbdatabase* pdb = getdocument(); // create a line in the model space oddbobjectid ident; { oddbblocktablerecordptr pblock = pdb->getmodelspaceid().safeopenobject(oddb::kforwrite); ident = pblock->appendoddbentity( getnewdim() ); } // create a copy of that line oddbobjectid idcopiedent; { oddbobjectidarray ids; ids.push_back(ident); oddbidmappingptr pmapping = oddbidmapping::createobject(); pdb->deepcloneobjects(ids,pdb->getmodelspaceid(),*pmapping); oddbidpair idpair(ident); pmapping->compute(idpair); idcopiedent = idpair.value(); oda_assert(!idcopiedent.isnull()); } // translate the copy { oddbentityptr pent = idcopiedent.safeopenobject(oddb::kforwrite); pent->transformby(odgematrix3d::translation(odgevector3d(0,10,0))); } getdocument()->updateallviews(null); } catch(oderror& e) { theapp.reporterror("error", e); } //catch } it should create 2 dimension at different positions, but rather that, the 2 dimensions are created at the position of the translated dimension only! if the drawing is opened in acad, it is very strange - select all and the stretch points of the first dimension are drawn but no dimension there. is there a way to avoid this? best regards chudomir the reason of the problem is that after cloning you get both dimensions referencing the same dimension block. as a result modifuing any dimension causes recomputing of the same block and it effects appearance of both ones. probably this should be fixed in deepclone(). as a work around you can set to null dimblockid in the clone and new block will be created. sergey slezkin |
所有的时间均为北京时间。 现在的时间是 11:05 PM. |