![]() |
【转帖】插图块??
插图块??
插图块?? 请问:用arx怎么插入一个图块(不用cad的命令)!谢谢! 给段代码你自己参考参考 如果你要插入外部图块,也就是说,要将另一张dwg图形插入,建议使用acdbdatabase::insert()函数,以下代码用于插入acdbblockreference对象,即块参考。 void addblockwithattributes() { acgepoint3d basepoint; //插入基点 if(acedgetpoint(null,"\n请输入图块插入点:",asdblarray(basepoint))!= rtnorm) return; double textangle; //属性文字旋转角度 if(acedgetangle(asdblarray(basepoint),"\n属性文字旋转角度:", &textangle)!= rtnorm) return; double textheight; //属性文字高度 if(acedgetdist(asdblarray(basepoint),"\n属性文字高度:", textheight)!= rtnorm) return; // 定义要插入的图块id acdbobjectid blockid; defineblockwithattributes(blockid, basepoint,textheight, textangle); // 第一步,给新的块参考对象分配内存 acdbblockreference *pblkref = new acdbblockreference; // 第二步,定义好的图块id赋给块参考对象 pblkref->setblocktablerecord(blockid); // 若使用ucs,建立ucs与wcs之间的转换 struct resbuf to, from; from.restype = rtshort; from.resval.rint = 1; // ucs to.restype = rtshort; to.resval.rint = 0; // wcs acgevector3d normal(0.0, 0.0, 1.0); acedtrans(&(normal.x), &from, &to, adesk::ktrue,&(normal.x)); // 设置块参考对象的插入点 pblkref->setposition(basepoint); // 指定lcs角度为0. pblkref->setrotation(0.0); pblkref->setnormal(normal); // 第三步,打开当前acdb数据库模型空间块表记录 acdbblocktable *pblocktable; acdbhostapplicationservices()->workingdatabase()->getsymboltable(pblocktable, acdb::kforread); acdbblocktablerecord *pblocktablerecord; pblocktable->getat(acdb_model_space, pblocktablerecord, acdb::kforwrite); pblocktable->close(); // 向模型空间添加块参考对象 acdbobjectid newentid; pblocktablerecord->appendacdbentity(newentid, pblkref); pblocktablerecord->close(); //以上是新建块参考对象的方法,以下读出块表并设置属性值 // 第四步,打开块表记录 acdbblocktablerecord *pblockdef; acdbopenobject(pblockdef, blockid, acdb::kforread); // 建立块表记录浏览器,遍历块表 acdbblocktablerecorditerator *piterator; pblockdef->newiterator(piterator); acdbentity *pent; acdbattributedefinition *pattdef; for (piterator->start(); !piterator->done();piterator->step()) { piterator->getentity(pent, acdb::kforread); // 保证对象是块参考对象,且属性非常量 pattdef = acdbattributedefinition::cast(pent); if (pattdef != null && !pattdef->isconstant()) { // 因属性非常量,需要定义一个属性对象 acdbattribute *patt = new acdbattribute(); patt->setpropertiesfrom(pattdef); patt->setinvisible(pattdef->isinvisible()); basepoint = pattdef->position(); basepoint += pblkref->position().asvector(); patt->setposition(basepoint); patt->setheight(pattdef->height()); patt->setrotation(pattdef->rotation()); patt->settag("tag"); patt->setfieldlength(25); char *pstr = pattdef->tag(); patt->settag(pstr); free(pstr); patt->setfieldlength(pattdef->fieldlength()); // 输入属性值 patt->settextstring("assigned attribute value"); acdbobjectid attid; pblkref->appendattribute(attid, patt); patt->close(); } pent->close(); // 不要忘记释放内存 } delete piterator; pblockdef->close(); pblkref->close(); } 非常感谢 非常感谢!!! 还有没有别的方法? 还有没有别的方法? 供参考 acdbentity* copyfromid(acdbobjectid objid) { acdbentity *pret=null; static acdbobjectid modelspaceid; if (modelspaceid.isnull()) { acdbblocktable *pblktbl; getblocktable(pblktbl, acdb::kforread); pblktbl->getat(acdb_model_space, modelspaceid); pblktbl->close(); } acdbobjectidarray objids; objids.append(objid); acdbidmapping idmap; wblockcloneobjects(objids, modelspaceid, idmap, acdb::kdrcignore); acdbidpair idpair(objid, acdbobjectid::knull, false, false); if (idmap.compute(idpair) == true && idpair.value() != null) { acdbopenobject(pret, idpair.value(), acdb::kforwrite); } return pret; } 该成员函数实现在不同的数据库中复制对象。参数中objid是另一个图形数据库的对象id返回的pret是已经存在于this图形数据库的实体。 leeyeafu版主你好,初学arx,请多指点: defineblockwithattributes(blockid, basepoint,textheight, textangle); //未定义 谢谢 qq:19154480 msn:freejustinji@hotmail.com e-mail:justin3@citiz.net 请问leeyeafu版主,插入块的时候,如何使块分解插入到当前图形中? qq:19154480 msn:freejustinji@hotmail.com e-mail:justin3@citiz.net 请问版主 上面那个程序的 头文件是 什么? 谢谢 |
| 所有的时间均为北京时间。 现在的时间是 03:55 PM. |