![]() |
如何从外部dwg文件插入实体到原坐标,并获取所插入的每个实体的id?
如何从外部dwg文件插入实体到原坐标,并获取所插入的每个实体的id?
www.dimcax.com 如何从外部dwg文件插入实体到原坐标,并获取所插入的每个实体的id? , 如何从外部dwg文件插入实体到原坐标,并获取所插入的每个实体的id? 我知道将外部文件作为一个块插入; 也可以将外部文件只加入到当前模型空间; 但是无法实现:将外部文件的实体复制到当前模型空间,并获取每个实体的id(因为需要对所复制的实体作修改); 请教一下高手,如何实现?; 说思路或提供代码都可以,非常感谢! 补充一下 我的开发环境是vs attname, string[] attvalue) { acadappser.document doc = acadappser.application.documentmanager.mdiactivedocument; editor ed = doc.editor; try { if (!file.exists(filename)) { //filename = hostapplicationservices.current.findfile(filename, doc.database, findfilehint.default); ed.writemessage("\n 不存在文件:" + filename + "\n"); return; } using (database db = new database(false, true)) //从文件读取时第一个为false ,第二个表 不关联到当前文档, { //读dwg文件 db.readdwgfile(filename, fileshare.read, true, null); //为了让插入块的函数在多个图形文件打开的情况下起作用,你必须使用下面的函数把dwg文件关闭 db.closeinput(true); objectidcollection list = new objectidcollection(); using (acadappser.documentlock doclock = doc.lockdocument()) //多文档要先这样 { using (transaction trans = doc.transactionmanager.starttransaction()) { //把源数据库模型空间中的实体插入到当前数据库的一个新的块表记录中 objectid idbtr = doc.database.insert(blockname, db, false); //打开块表 blocktable bt = (blocktable)trans.getobject(doc.database.blocktableid, openmode.forread); //打开块表记录 blocktablerecord btrinserted = (blocktablerecord)trans.getobject(bt[blockname], openmode.forwrite); //获取blockname块的遍历器,以实现对块中对象的访问 blocktablerecordenumerator //system.collections.ienumerator iterator = btrinserted.getenumerator(); //这句是遍历的另一方法 foreach (objectid id in btrinserted) { list.add(id); entity ent = trans.getobject(id, openmode.forwrite) as entity; ent.layer = layername; blocktablerecord btr = (blocktablerecord)trans.getobject(bt[blocktablerecord.modelspace], openmode.forwrite); btr.appendentity(ent ); //在当前空间加入创建的块参照 trans.addnewlycreateddbobject(ent, true); //通知事务处理加入创建的块参照 } } } } } catch (exception ex) { ed.writemessage("\nerror during insertblockrefwithattfromdwgfile: " + ex.message); } } 在执行到这一句: btr.appendentity(ent ); 会报错 请教是什么原因? |
| 所有的时间均为北京时间。 现在的时间是 10:30 PM. |