绑定CAD实体到AS单元
程序员文章站
2024-03-18 18:32:58
...
可以通过AS单元的用户自定义属性:UserAttribute【0-9】储存10个cad实体的信息,比如ID或者句柄,实现CAD实体到AS单元之间的关联绑定。
一、获取CAD实体句柄
acEnt = acTrans.GetObject(result.ObjectId, OpenMode.ForWrite) as Entity;
string string_Handle = acEnt.Handle.ToString(); //获取句柄并转换成字符串
arc = acTrans.GetObject(acEnt.ObjectId, OpenMode.ForWrite) as Arc;
string string_Handle = arc.ToString(); //获取句柄并转换成字符串
二、将CAD实体句柄存储在AS单元的用户自定义属性:UserAttribute中
IPolyBeam polyBeam = m_Joint.CreatePolyBeam(sectionClass, sectionSize, (Role)beamRole, polyline, vecRefOrientation, zVec);
polyBeam.UserAttribute[1]=string_Handle;
或者
beam = obj as Autodesk.AdvanceSteel.Modelling.StraightBeam;
beam.SetUserAttribute(1,string_Handle);
三、读取AS单元中的用户自定义属性:UserAttribute值(CAD实体句柄)
string string_Handle = polyBeam.UserAttribute[0];
或者
string string_Handle = beam.getAttributeStatus(0).ToString();
四、将CAD句柄(字符串)转换成实体ID
public ObjectId GetObjectId(Database db, string handleString)
{
long l = Convert.ToInt64(handleString, 16);
Handle handle = new Handle(l);
return db.GetObjectId(false, handle, 0);
}
五、通过ID访问CAD实体
acEnt = acTrans.GetObject(result.ObjectId, OpenMode.ForWrite) as Entity;
arc = acTrans.GetObject(acEnt.ObjectId, OpenMode.ForWrite) as Arc;
上一篇: String与实体类bean之间的转换
下一篇: 【spring】第五课工厂
推荐阅读