- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
[CommandMethod("ExtendCurve", "exc", CommandFlags.Modal)]
static public void testExtendCurve()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
try
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
PromptEntityOptions peo = new PromptEntityOptions("\nSelect boundary edge... >>");
PromptEntityResult exres;
exres = ed.GetEntity(peo);
if (exres.Status != PromptStatus.OK)
return;
Entity exent = (Entity)tr.GetObject(exres.ObjectId, OpenMode.ForRead);
if (exent == null)
return;
Curve excur = exent as Curve;
peo = new PromptEntityOptions("\nSelect curve to extend >>");
PromptEntityResult res;
res = ed.GetEntity(peo);
if (res.Status != PromptStatus.OK)
return;
Entity ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead);
if (ent == null)
return;
if (ent.GetRXClass().DxfName == "SPLINE")
{
ed.WriteMessage("\nCould not extend the spline");
return;
}
Curve cur = ent as Curve;
Point3dCollection pts = new Point3dCollection();
cur.IntersectWith(excur, Intersect.ExtendThis, pts, 0, 0);
if (pts.Count == 0)
{
ed.WriteMessage("\nCurves aren't intersects each other");
return;
}
Point3d pt = pts[0];// ought be to correct this point with circle and closed polyline
if (!cur.IsWriteEnabled)
cur.UpgradeOpen();
Point3d pp = cur.GetClosestPointTo(res.PickedPoint, false);
bool sofar = false;
if (pp.DistanceTo(pt) < pt.DistanceTo(cur.EndPoint))
sofar = true;
if (sofar)
{
cur.Extend(true, pt);
}
else
{
cur.Extend(false, pt);
}
tr.Commit();
}
}
catch (System.Exception ex)
{
ed.WriteMessage(ex.Message );
}
} |
|