- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2014-5-21 12:58:34
来自手机
|
显示全部楼层
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using GeometryExtensions;
using AcAp = Autodesk.AutoCAD.ApplicationServices.Application;
namespace GeometryExtensionsTestCommands
{
public class MjoinCommand
{
[CommandMethod("mjoin")]
public void PolyJoin()
{
Document doc = AcAp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
TypedValue[] filter = {
new TypedValue(-4,"<OR"),
new TypedValue(0, "ARC,ELLIPSE,LINE,LWPOLYLINE"),
new TypedValue(-4, "<AND"),
new TypedValue(0, "SPLINE"),
new TypedValue(-4, "&"),
new TypedValue(70, 8),
new TypedValue(-4, "AND>"),
new TypedValue(-4, "OR>")};
PromptSelectionResult psr = ed.GetSelection(new SelectionFilter(filter));
if (psr.Status != PromptStatus.OK) return;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTableRecord btr =
(BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
PolylineSegmentCollection psc = new PolylineSegmentCollection();
Plane plane = new Plane(Point3d.Origin, Vector3d.ZAxis);
foreach (ObjectId id in psr.Value.GetObjectIds())
{
Entity ent = (Entity)tr.GetObject(id, OpenMode.ForRead);
switch (ent.GetType().Name)
{
case "Arc":
Arc arc = (Arc)ent;
psc.Add(new PolylineSegment(
new CircularArc2d(
arc.Center.Convert2d(plane),
arc.Radius,
arc.StartAngle,
arc.EndAngle,
Vector2d.XAxis,
false)));
break;
case "Ellipse":
Ellipse el = (Ellipse)ent;
psc.AddRange(new PolylineSegmentCollection(el));
break;
case "Line":
Line l = (Line)ent;
psc.Add(new PolylineSegment(
new LineSegment2d(
l.StartPoint.Convert2d(plane),
l.EndPoint.Convert2d(plane))));
break;
case "Polyline":
Polyline pl = (Polyline)ent;
psc.AddRange(new PolylineSegmentCollection(pl));
break;
case "Spline":
try
{
Spline spl = (Spline)ent;
psc.AddRange(new PolylineSegmentCollection((Polyline)spl.ToPolyline()));
}
catch { }
break;
default:
break;
}
}
foreach (PolylineSegmentCollection segs in psc.Join())
{
Polyline pline = segs.ToPolyline();
btr.AppendEntity(pline);
tr.AddNewlyCreatedDBObject(pline, true);
}
tr.Commit();
}
}
}
} |
|