查看单个帖子
旧 2009-04-20, 10:45 AM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】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
我用

估计
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)