请问用鼠标点击一条直线如何以鼠标点击坐标将这条线断成2条直线
请问用鼠标点击一条直线如何以鼠标点击坐标将这条线断成2条直线。其中一条线的起始坐标为原来直线的起始坐标,结束坐标为鼠标点击坐标,另一条线的起始坐标为鼠标点击坐标结束坐标为原来直线的结束坐标。 第一次搞AutoCAD二次开发,哪为高手教下小弟啊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();
}
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();
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();
} 回复 sailorcwx 的帖子
大哥,你给我的代码怎么用啊,怎么我调试到
Line lineObject = tr.GetObject(selectResult.ObjectId, OpenMode.ForWrite) as Line;
就报错弹出了啊 仅支持直线,其余线及优化处理你自己来做。在autocad2011+vs2010上测试通过 回复 sailorcwx 的帖子
程序中是用Polyline画的线,也是一样用么 回复 sailorcwx 的帖子
Polyline lineObject = tr.GetObject(selectResult.ObjectId, OpenMode.ForWrite) as Polyline;
还是直接退出了,请问是怎么回事 本帖最后由 chmenf087 于 2011-4-22 23:12 编辑
算了吧,这个用lisp比.net简单好多哦
(defun c:spL (/ e entt pt1 pnt vent closePnt)
(vl-load-com)
(setq omd (getvar "osmode") entt (entsel "\nPlease pick:"))
(setq e (car entt) vent (vlax-ename->vla-object e) pt1 (cadr entt) closePnt (vlax-curve-getclosestpointto vent pt1))
(vl-cmdf "Break" entt "F" closepnt closepnt)
(setvar "osmode" omd)
) 回复 sclkkk 的帖子
不过不支持圆和椭圆 回复 chmenf087 的帖子
没办法啊,老板就要用.NET
页:
[1]
2