![]() |
【转帖】在当前图中插入另外一个dwg文件,插入后无法显示图形
在当前图中插入另外一个dwg文件,插入后无法显示图形
www.dimcax.com 在当前图中插入另外一个dwg文件,插入后无法显示图形 你的代码只是在当前图形数据库的块表中加入02.dwg及其包含的块,如果要在当前图形中显示02.dwg,你必须插入02.dwg这个块,也就是说生成02.dwg块的一个块索引。 c#最适合开发autocad,因为它拥有vb容易的特点,却具有vc++的强大功能。 那么我该如何填写代码来实现其显示呢?请给我一些建议吧,谢谢. 我记得将直线之类的实体插入到当前数据库中时,就是直接使用添加命令,也没有创建索引,这两者有什么不同吗? 我是初学者,问的问题如果有些幼稚,请见谅.3q 呵呵,把你找到的答案贴出来吧,可能对别人有帮助,谢谢!! c#最适合开发autocad,因为它拥有vb容易的特点,却具有vc++的强大功能。 public void insertblock() { string sourcefilename = @"g:\学习\civil3d学习资料\test\dwg\02.dwg"; //要插入的文件路径 string newblockname = "oftenusedblock"; //新的块表记录名 try { //using (database sourcedatabase = getdatabasefromfile(sourcefilename)) //{ // //把源数据库模型空间中的实体插入到当前数据库的一个新的块表记录中 // hostapplicationservices.workingdatabase.insert(newblockname, sourcedatabase, false); //} dbtransman tm = db.transactionmanager; using (transaction ta= tm.starttransaction()) { database sourcedatabase = getdatabasefromfile(sourcefilename); //把源数据库模型空间中的实体插入到当前数据库的一个新的块表记录中 objectid idbtr =hostapplicationservices.workingdatabase.insert(newblockname, sourcedatabase, false); //create a ref to the block blocktable bt = (blocktable)tm.getobject(db.blocktableid, openmode.forread); blocktablerecord btr = (blocktablerecord)tm.getobject(bt[blocktablerecord.modelspace], openmode.forwrite); using (blockreference bref = new blockreference(point3d.origin, idbtr)) { btr.appendentity(bref); ta.addnewlycreateddbobject(bref, true); } ta.commit(); } } catch (system.exception e) { application.showalertdialog(e.message); } } getdatabasefromfile是在什么类中的啊?怎么我找不到的? 学习中。。 学习来了。。呵。。顶 getdatabasefromfile是一个方法 getdatabasefromfile(string filename) { database db = new database(false, true); acadappser.document doc = acadappser.application.documentmanager.mdiactivedocument; editor ed = doc.editor; try { //新建一个数据库对象以读取dwg文件 if (file.exists(filename)) { objectidcollection list = new objectidcollection(); //读dwg文件 db.readdwgfile(filename, fileshare.read, true, null); //为了让插入块的函数在多个图形文件打开的情况下起作用,你必须使用下面的函数把dwg文件关闭 db.closeinput(true); } } catch (exception ex) { ed.writemessage("\nerror during copyfromotherdwg: " + ex.message); } } |
所有的时间均为北京时间。 现在的时间是 02:02 PM. |