- 积分
- 11099
- 明经币
- 个
- 注册时间
- 2005-2-20
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2010-12-14 16:04:40
|
显示全部楼层
[CommandMethod("tt2")]
public void testfunction2()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed =doc.Editor;
Database db = HostApplicationServices.WorkingDatabase;
SelectionFilter sf = new SelectionFilter(new TypedValue[] { new TypedValue(0,"Line,Circle") });
PromptSelectionResult psr = ed.GetSelection(sf);
if (psr.Status != PromptStatus.OK)
return;
using (Transaction tr=db.TransactionManager.StartTransaction())
{
BlockTableRecord curSpace=tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
foreach (ObjectId id in psr.Value.GetObjectIds())
{
Entity ent = tr.GetObject(id, OpenMode.ForRead) as Entity;
if (ent.GetType() == typeof(Line))
{
Line l = ent as Line;
Point3d pt1 = l.StartPoint;
Point3d pt2 = l.EndPoint;
Circle c1 = new Circle(pt1, Vector3d.ZAxis, 1);
Circle c2 = new Circle(pt2, Vector3d.ZAxis, 1);
curSpace.AppendEntity(c1);
curSpace.AppendEntity(c2);
tr.AddNewlyCreatedDBObject(c1, true);
tr.AddNewlyCreatedDBObject(c2, true);
}
else
{
Circle c = ent as Circle;
Point3d pt = c.Center;
Circle c1 = new Circle(pt, Vector3d.ZAxis, 1);
curSpace.AppendEntity(c1);
tr.AddNewlyCreatedDBObject(c1, true);
}
}
tr.Commit();
}
} |
|