高级会员
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
|
【转帖】求助 :如何制作无名块?
求助 :如何制作无名块?
求助 :如何制作无名块?
如何制作无名块?块中的实体要保留其属性,如赋有材质的话要保留。
哪位知道的话,望能提供一点原代码,谢谢!!
此问题已解决,抄出来与大家分享一下。blockname=“*u”即为无名块,设为其它值即为有名块。
void getucstowcsoriginmatrix(acgematrix3d& m,const acgepoint3d& wcsbasept, acdbdatabase* db,double angle)
{
assert(db != null);
acgematrix3d tmpmat;
if (acdbucsmatrix(tmpmat, db))
{
acgepoint3d origin;
acgevector3d xdir, ydir, zdir;
tmpmat.getcoordsystem(origin, xdir, ydir, zdir);
origin += wcsbasept.asvector();
xdir.rotateby(angle,zdir);
ydir.rotateby(angle,zdir);
m.settoaligncoordsys(origin, xdir, ydir, zdir,
acgepoint3d::korigin, acgevector3d::kxaxis,
acgevector3d::kyaxis, acgevector3d::kzaxis);
}
else
{
assert(0);
m = acgematrix3d::kidentity;
}
}
acad::errorstatus cloneandxformobjects(acdbdatabase* db, acdbobjectidarray entstoclone,const acdbobjectid& ownerblockid,
const acgematrix3d& xformmat)
{
assert(db != null);
acdbidmapping idmap;
acad::errorstatus es = db->deepcloneobjects(
const_cast<acdbobjectidarray&>(entstoclone),
const_cast<acdbobjectid&>(ownerblockid), idmap);
if (es != acad::eok)
{
return es;
}
acdbentity* clonedent;
acdbidpair idpair;
acdbidmappingiter iter(idmap);
for (iter.start(); !iter.done(); iter.next())
{
if (!iter.getmap(idpair)) return acad::einvalidinput;
if (idpair.iscloned())
{
es = acdbopenacdbentity(clonedent, idpair.value(), acdb::kforwrite);
if (es == acad::eok)
{
if (idpair.isprimary())
{
clonedent->transformby(xformmat);
}
clonedent->close();
}
}
}
return acad::eok;
}
acad::errorstatus definenewanonymousblock(acdbblocktablerecord*& newblkrec,acdbobjectid& newblkrecid, acdbdatabase* db)
{
assert(db != null);
acdbblocktable* blktbl;
acad::errorstatus es = db->getsymboltable(blktbl, acdb::kforwrite);
if (es != acad::eok) return es;
newblkrec = new acdbblocktablerecord;
newblkrec->setpathname("");
es = newblkrec->setname(_t("*u"));
if (es == acad::eok) es = blktbl->add(newblkrecid, newblkrec);
if (es != acad::eok)
{
delete newblkrec;
newblkrec = null;
}
blktbl->close();
return es;
}
acdbobjectid fdm_makeblock(cstring blockname,acdbobjectidarray entidarray,const acgepoint3d &basept,double angle,const acgescale3d &scale)
{
acdbobjectid newblkrecid;
acdbblocktablerecord* newblkrec;
if (definenewanonymousblock(newblkrec, newblkrecid, acdbhostapplicationservices()->workingdatabase()) == acad::eok)
{
newblkrec->setname(blockname);
newblkrec->setorigin(acgepoint3d::korigin);
newblkrec->close();
acgematrix3d matrix;
getucstowcsoriginmatrix(matrix,basept,acdbcurdwg(),angle);
if (cloneandxformobjects(acdbhostapplicationservices()->workingdatabase(), entidarray, newblkrecid, matrix) == acad::eok)
{
acdbobjectid referenceid=acdbobjectid::knull;
acdbblockreference *preference=new acdbblockreference;
preference->setblocktablerecord(newblkrecid);
preference->setposition(basept);
preference->setrotation(angle);
preference->setscalefactors(scale);
if(fdm_addtomodelspace(referenceid,preference)==acad::eok)
{
eraseentity(entidarray);
preference->close();
return referenceid;
}
}
}
return acdbobjectid::knull;
}
此问题已解决,抄出来与大家一起分享。 blockname设为"*u"为无名块,设为其它值为有名块。
void getucstowcsoriginmatrix(acgematrix3d& m,const acgepoint3d& wcsbasept, acdbdatabase* db,double angle)
{
assert(db != null);
acgematrix3d tmpmat;
if (acdbucsmatrix(tmpmat, db))
{
acgepoint3d origin;
acgevector3d xdir, ydir, zdir;
tmpmat.getcoordsystem(origin, xdir, ydir, zdir);
origin += wcsbasept.asvector();
xdir.rotateby(angle,zdir);
ydir.rotateby(angle,zdir);
m.settoaligncoordsys(origin, xdir, ydir, zdir,
acgepoint3d::korigin, acgevector3d::kxaxis,
acgevector3d::kyaxis, acgevector3d::kzaxis);
}
else
{
assert(0);
m = acgematrix3d::kidentity;
}
}
acad::errorstatus cloneandxformobjects(acdbdatabase* db, acdbobjectidarray entstoclone,const acdbobjectid& ownerblockid,
const acgematrix3d& xformmat)
{
assert(db != null);
acdbidmapping idmap;
acad::errorstatus es = db->deepcloneobjects(
const_cast<acdbobjectidarray&>(entstoclone),
const_cast<acdbobjectid&>(ownerblockid), idmap);
if (es != acad::eok)
{
return es;
}
acdbentity* clonedent;
acdbidpair idpair;
acdbidmappingiter iter(idmap);
for (iter.start(); !iter.done(); iter.next())
{
if (!iter.getmap(idpair)) return acad::einvalidinput;
if (idpair.iscloned())
{
es = acdbopenacdbentity(clonedent, idpair.value(), acdb::kforwrite);
if (es == acad::eok)
{
if (idpair.isprimary())
{
clonedent->transformby(xformmat);
}
clonedent->close();
}
}
}
return acad::eok;
}
acad::errorstatus definenewanonymousblock(acdbblocktablerecord*& newblkrec,acdbobjectid& newblkrecid, acdbdatabase* db)
{
assert(db != null);
acdbblocktable* blktbl;
acad::errorstatus es = db->getsymboltable(blktbl, acdb::kforwrite);
if (es != acad::eok) return es;
newblkrec = new acdbblocktablerecord;
newblkrec->setpathname("");
es = newblkrec->setname(_t("*u"));
if (es == acad::eok) es = blktbl->add(newblkrecid, newblkrec);
if (es != acad::eok)
{
delete newblkrec;
newblkrec = null;
}
blktbl->close();
return es;
}
acdbobjectid fdm_makeblock(cstring blockname,acdbobjectidarray entidarray,const acgepoint3d &basept,double angle,const acgescale3d &scale)
{
acdbobjectid newblkrecid;
acdbblocktablerecord* newblkrec;
if (definenewanonymousblock(newblkrec, newblkrecid, acdbhostapplicationservices()->workingdatabase()) == acad::eok)
{
newblkrec->setname(blockname);
newblkrec->setorigin(acgepoint3d::korigin);
newblkrec->close();
acgematrix3d matrix;
getucstowcsoriginmatrix(matrix,basept,acdbcurdwg(),angle);
if (cloneandxformobjects(acdbhostapplicationservices()->workingdatabase(), entidarray, newblkrecid, matrix) == acad::eok)
{
acdbobjectid referenceid=acdbobjectid::knull;
acdbblockreference *preference=new acdbblockreference;
preference->setblocktablerecord(newblkrecid);
preference->setposition(basept);
preference->setrotation(angle);
preference->setscalefactors(scale);
if(fdm_addtomodelspace(referenceid,preference)==acad::eok)
{
eraseentity(entidarray);
preference->close();
return referenceid;
}
}
}
return acdbobjectid::knull;
}
|