- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
[CommandMethod("IntLineCurve","ilw", CommandFlags.Modal | CommandFlags.UsePickSet | CommandFlags.Redraw )]
public void IntersectTestIn()
{
Database db = HostApplicationServices.WorkingDatabase;
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
PromptEntityOptions peo = new PromptEntityOptions("\nSelect a Line >>");
peo.SetRejectMessage("\nYou have to select the Line only >>");
peo.AddAllowedClass(typeof(Line), false);
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;
Line line = (Line)ent as Line;
if (line == null) return;
peo = new PromptEntityOptions("\nSelect a curve: ");
peo.SetRejectMessage("\nYou have to select the curve only >>");
peo.AddAllowedClass(typeof(Curve), false);
res = ed.GetEntity(peo);
if (res.Status != PromptStatus.OK)
return;
ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead);
if (ent == null)
return;
Curve pline = (Curve)ent as Curve;
if (pline == null) return;
Point3dCollection pts = new Point3dCollection();
line.IntersectWith(pline, Intersect.OnBothOperands, pts, 0, 0);//<-- A2010
if (pts.Count == 0) return;
List<Point3d> points = new List<Point3d>();
foreach (Point3d p in pts)
points.Add(p);
Point3d sp = line.StartPoint;
points.Sort(delegate(Point3d p1, Point3d p2)
{
return Convert.ToInt32(
Convert.ToDouble(sp.DistanceTo(p1).CompareTo(
Convert.ToDouble(sp.DistanceTo(p2)))));
}
);
pts = new Point3dCollection(points.ToArray());
DBObjectCollection objs = line.GetSplitCurves(pts);
List<DBObject> lstobj = new List<DBObject>();
foreach (DBObject dbo in objs)
lstobj.Add(dbo);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
int i=1;
foreach (DBObject dbo in objs)
{
Line ln = dbo as Line;
if (!ln.IsWriteEnabled)
ln.UpgradeOpen();
ln.SetPropertiesFrom(line);
ln.ColorIndex=i;
btr.AppendEntity(ln);
tr.AddNewlyCreatedDBObject(ln, true);
if (i > 255)
{
i = 1;
}
else
{
i += 1;
}
}
if (!line.IsWriteEnabled)
line.UpgradeOpen();
line.Erase();
line.Dispose();
ed.Regen();
tr.Commit();
}
} |
|