- 积分
- 11099
- 明经币
- 个
- 注册时间
- 2005-2-20
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2011-4-21 11:56:42
|
显示全部楼层
[CommandMethod("t1")]
public void test1()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptEntityOptions selectPrompt = new PromptEntityOptions("");
PromptEntityResult selectResult = ed.GetEntity(selectPrompt);
if (selectResult.Status != PromptStatus.OK)
return;
Transaction tr=HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction();
Line lineObject = tr.GetObject(selectResult.ObjectId, OpenMode.ForWrite) as Line;
Point3d pt = selectResult.PickedPoint;
pt = lineObject.GetClosestPointTo(pt, false);
Point3dCollection breakPoints=new Point3dCollection();
breakPoints.Add(pt);
DBObjectCollection resultObjects=lineObject.GetSplitCurves(breakPoints);
BlockTableRecord btr = tr.GetObject(HostApplicationServices.WorkingDatabase.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
foreach (DBObject obj in resultObjects)
{
btr.AppendEntity((Entity)obj);
tr.AddNewlyCreatedDBObject(obj, true);
}
lineObject.Erase();
tr.Commit();
tr.Dispose();
}
[CommandMethod("t2")]
public void test2()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptPointOptions pointPrompt = new PromptPointOptions("");
PromptPointResult pointResult = ed.GetPoint(pointPrompt);
if (pointResult.Status != PromptStatus.OK)
return;
Point3d pt = pointResult.Value;
PromptSelectionResult lineResult= ed.SelectCrossingWindow(pt, pt);
if (lineResult.Status != PromptStatus.OK)
return;
ObjectId lineId = lineResult.Value.GetObjectIds()[0];
Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction();
Line lineObject = tr.GetObject(lineId, OpenMode.ForWrite) as Line;
Point3dCollection breakPoints = new Point3dCollection();
breakPoints.Add(pt);
DBObjectCollection resultObjects = lineObject.GetSplitCurves(breakPoints);
BlockTableRecord btr = tr.GetObject(HostApplicationServices.WorkingDatabase.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
foreach (DBObject obj in resultObjects)
{
btr.AppendEntity((Entity)obj);
tr.AddNewlyCreatedDBObject(obj, true);
}
lineObject.Erase();
tr.Commit();
tr.Dispose();
} |
|