![]() |
【转帖】c#生成关联填充的方法
c#生成关联填充的方法
www.dimcax.com c#生成关联填充的方法 , , c#要生成有关联性的填充,以前推荐的是调用arx的方法,但是非常麻烦。 本论坛的超级版主ahlzl经过不懈的努力,终于找到了纯粹的用c#来实现关联填充的方法,详见下面的代码。 using system; using autodesk.autocad.databaseservices; using autodesk.autocad.geometry; using autodesk.autocad.runtime; namespace associativehatch { public class commands { [commandmethod("test")] public void associativehatch() { database db = hostapplicationservices.workingdatabase; line lineent1 = new line(new point3d(0, 0, 0), new point3d(1000, 0, 0)); line lineent2 = new line(new point3d(1000, 0, 0), new point3d(800, 600, 0)); line lineent3 = new line(new point3d(800, 600, 0), new point3d(0, 0, 0)); circle circleent = new circle(new point3d(500, loops = new objectidcollection[2]; loops.setvalue(loops1, 0); loops.setvalue(loops2, 1); hatch hatchent; objectid hatentid = addhatch(out hatchent, 0, "angle", math.pi / 3, 10); using (transaction tr = db.transactionmanager.starttransaction()) { hatchent = (hatch)tr.getobject(hatentid, openmode.forwrite); hatchent.associative = true; for (int i = 0; i < loops.length; i++) { hatchent.appendloop(hatchlooptypes.default, loops); } tr.commit(); } } private objectid addhatch(out hatch hatchent, hatchpatterntype pattype, string patname, double patternangle, double patternscale) { hatch ent = new hatch(); ent.hatchobjecttype = hatchobjecttype.hatchobject; database db = hostapplicationservices.workingdatabase; using (transaction trans = db.transactionmanager.starttransaction()) { blocktable bt = (blocktable)trans.getobject (db.blocktableid, openmode.forread); blocktablerecord btr = (blocktablerecord)trans.getobject (bt[blocktablerecord.modelspace], openmode.forwrite); objectid entid = btr.appendentity(ent); trans.addnewlycreateddbobject(ent, true); ent.setdatabasedefaults(); ent.patternangle = patternangle; ent.patternscale = patternscale; ent.sethatchpattern(pattype, patname); hatchent = ent; trans.commit(); return entid; } } private objectid appendentity(entity ent) { database db = hostapplicationservices.workingdatabase; objectid entid; using (transaction trans = db.transactionmanager.starttransaction()) { blocktable bt = (blocktable)trans.getobject(db.blocktableid, openmode.forread); blocktablerecord btr = (blocktablerecord)trans.getobject (bt[blocktablerecord.modelspace], openmode.forwrite); entid = btr.appendentity(ent); trans.addnewlycreateddbobject(ent, true); trans.commit(); } return entid; } } } 复制代码 具体的原因和注意事项,还请卢老大来补充。 好东西!牛 vb c# vlisp autocad gis 我用 在 估计 |
| 所有的时间均为北京时间。 现在的时间是 07:24 PM. |