- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
[CommandMethod("copyseg")]
public void copySegment()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
PromptEntityOptions peo = new PromptEntityOptions("\nSelect the segment to copy: ");
peo.SetRejectMessage("\nYou have to select polyline only!");
peo.AllowNone = false;
peo.AllowObjectOnLockedLayer = false;
peo.AddAllowedClass(typeof(Polyline), true);
PromptEntityResult per = ed.GetEntity(peo);
if (per.Status == PromptStatus.OK)
{
ObjectId objId = per.ObjectId;
try
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
Polyline pline = tr.GetObject(objId, OpenMode.ForRead, false) as Polyline;
if (pline != null)
{
BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId,OpenMode.ForWrite, false) as BlockTableRecord;
Point3d pickPt = pline.GetClosestPointTo((Point3d)per.PickedPoint, false);
double param = pline.GetParameterAtPoint(pickPt);
int index = (int)param;
double swid= pline.GetStartWidthAt(index);
double ewid = pline.GetEndWidthAt(index);
SegmentType stype= pline.GetSegmentType(index);
if (stype == SegmentType.Line)
{
LineSegment2d lineseg= pline.GetLineSegment2dAt(index);
Polyline spoly = new Polyline();
Point2d sp = lineseg.StartPoint;
Point2d ep = lineseg.EndPoint;
spoly.AddVertexAt(0, sp, 0, swid, ewid);
spoly.AddVertexAt(1, ep,0,swid,ewid);
spoly.ColorIndex = 1;
btr.AppendEntity(spoly);
tr.AddNewlyCreatedDBObject(spoly, true);
}
if (stype == SegmentType.Arc)
{
CircularArc2d arcseg = pline.GetArcSegment2dAt(index);
Polyline spoly = new Polyline();
Point2d sp = arcseg.StartPoint;
Point2d ep = arcseg.EndPoint;
double boo = pline.GetBulgeAt(index);
spoly.AddVertexAt(0, sp, boo, swid, ewid);
spoly.AddVertexAt(1, ep, boo, swid, ewid);
spoly.ColorIndex = 2;
btr.AppendEntity(spoly);
tr.AddNewlyCreatedDBObject(spoly, true);
}
}
tr.Commit();
}
}
catch (System.Exception ex)
{
ed.WriteMessage("\nError: {0}\nTrace: {1}" , ex.Message , ex.StackTrace);
}
}
} |
|