- UID
- 799518
- 积分
- 8
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2020-5-4
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
这个代码能读取二维多段线第一个顶点坐标,怎么才能读取所有顶点的坐标呢?
求教
- using Autodesk.AutoCAD.Runtime;
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.Geometry;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace 二维多段线实验
- {
- public class Class1
- {
- [CommandMethod("Pl2d")]
- public static void Pl2d()
- {
- // 获取当前文档和数据库,启动事务
- Document acDoc = Application.DocumentManager.MdiActiveDocument;
- Database acCurDb = acDoc.Database;
- using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
- {
- // 以读模式打开块表
- BlockTable acBlkTbl;
- acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
- OpenMode.ForRead) as BlockTable;
- // 以写模式打开块表记录模型空间
- BlockTableRecord acBlkTblRec;
- acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
- OpenMode.ForWrite) as BlockTableRecord;
- // 创建 2D 多段线
- Polyline2d acPoly2d = new Polyline2d();
- // 将新对象添加到块表记录和事务
- acBlkTblRec.AppendEntity(acPoly2d);
- acTrans.AddNewlyCreatedDBObject(acPoly2d, true);
- // 先将多段线添加到块表记录,然后才能给它添加顶点
- Point3dCollection acPts2dPoly = new Point3dCollection();
- acPts2dPoly.Add(new Point3d(1, 1, 0));
- acPts2dPoly.Add(new Point3d(2, 2, 0));
- acPts2dPoly.Add(new Point3d(3, 2, 0));
- acPts2dPoly.Add(new Point3d(3, 3, 0));
- acPts2dPoly.Add(new Point3d(4, 3, 0));
- foreach (Point3d acPt3d in acPts2dPoly)
- {
- Vertex2d acVer2d = new Vertex2d(acPt3d, 0,0, 0, 0);
- acPoly2d.AppendVertex(acVer2d);
- acTrans.AddNewlyCreatedDBObject(acVer2d, true);
- }
- // 获取 2D 多段线的第 1 个坐标
- Point3dCollection acPts3d = new Point3dCollection();
- Vertex2d acFirstVer = null;
- foreach (ObjectId acObjIdVert in acPoly2d)
- {
- acFirstVer = acTrans.GetObject(acObjIdVert, OpenMode.ForRead) as Vertex2d;
- acPts3d.Add(acFirstVer.Position);
- break;
- }
- // 获取 2D 多段线的第 1 个顶点
- // Z 坐标值用 Elevation 属性值
- Point3d pFirstVer = new Point3d(acFirstVer.Position.X,
- acFirstVer.Position.Y,
- acPoly2d.Elevation);
-
- Application.ShowAlertDialog("The first vertex has the following " +
- "coordinates:" + "\nOCS: " + pFirstVer.ToString());
-
- acTrans.Commit();
- }
- }
-
- }
- }
|
|