乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 138|回复: 8

从选择集中加入实体

[复制链接]

30

主题

125

帖子

30

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
218
发表于 2016-1-22 12:00:12 | 显示全部楼层 |阅读模式
  1. public void start()
  2.         {
  3.             Document acadDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  4.             Database acadDb = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
  5.             Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  6.             int i = 1, z = 1;
  7.             using (Transaction tr = acadDoc.TransactionManager.StartTransaction())
  8.             {
  9.                 try
  10.                 {
  11.                     ObjectIdCollection coll = clsSelection.Sset3dPolyline();
  12.                     foreach (ObjectId id in coll)
  13.                     {
  14.                         //ed.WriteMessage("\n" + i++ + " Entiy: " + id.ObjectClass.DxfName + " Typ: " + id.ObjectClass.Name);
  15.                         Polyline3d pol = id.GetObject(OpenMode.ForRead) as Polyline3d;
  16.                         ObjectId oId = pol.ObjectId;
  17.                         Point3d sPt = pol.StartPoint;
  18.                         Point3d ePt = pol.EndPoint;
  19.                         foreach (ObjectId id2 in coll)
  20.                         {
  21.                             Polyline3d pol2 = id2.GetObject(OpenMode.ForRead) as Polyline3d;
  22.                             Point3d sPt2 = pol.StartPoint;
  23.                             Point3d ePt2 = pol.EndPoint;
  24.                             bool test1 = id != id2;
  25.                             bool test2 = sPt.Equals(sPt2);
  26.                             bool test3 = sPt2.Equals(ePt);
  27.                             bool test4 = ePt2.Equals(sPt);
  28.                             //if (test1 && test2 || test3 || test4)
  29.                             //{
  30.                             //pol.JoinEntity(pol2);

大家好!
我想尝试用JoinEntity()方法连接多段线。我的想法是在一个选择集中收集所有的三维折线,然后函数寻找在不同三维折线的起点或/和终点的实体(三维折线)。我在想什么,在Lisp中,它有能力通过ssget-function选择不同的对象。我不知道,怎么办。网?!所以也许有可能找到正确的三维折线来连接它们?!

本帖以下内容被隐藏保护;需要你回复后,才能看到!

游客,如果您要查看本帖隐藏内容请回复
回复

使用道具 举报

15

主题

687

帖子

169

银币

中流砥柱

Rank: 25

铜币
582
发表于 2016-1-22 14:15:57 | 显示全部楼层
您好,
也许您可以从PolylineSegmentCollection中获得一些灵感。GeometryExtensions中的Join()方法。
回复

使用道具 举报

30

主题

125

帖子

30

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
218
发表于 2016-1-23 04:46:52 | 显示全部楼层
嗨,Gile!
谢谢。
我在C:\Windows\Microsoft.NET\Framework中没有找到引用Geometry扩展。我必须在哪里寻找它们?!
对不起,瞎了
回复

使用道具 举报

15

主题

687

帖子

169

银币

中流砥柱

Rank: 25

铜币
582
发表于 2016-1-23 04:50:50 | 显示全部楼层
点击我回复中的链接。
回复

使用道具 举报

30

主题

125

帖子

30

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
218
发表于 2016-1-23 05:17:16 | 显示全部楼层
伟大的工作Gile,我必须阅读 - 它非常适合2D绘图对象 - 我尝试了你的函数“mjoin”与GeometryExtensions
回复

使用道具 举报

30

主题

125

帖子

30

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
218
发表于 2016-1-23 06:41:26 | 显示全部楼层
嗨,吉尔!
1...它有什么理由为什么不在以下位置使用 JoinEntity:Autodesk.AutoCAD.DatabaseServices.Entity.JoinEntity(Autodesk.AutoCAD.DatabaseServices.Entity)
2...对我来说很难理解(在Acad API中有几个月的时间经验)类GeometryExtensions中的所有metods,你能解释一下,你如何加入例如Polylines(在你的情况下2d)
3...如果我尝试为Polyline3d设置PolylineSegmentCollection,我必须收集哪些属性我不确定
如何在AcadDB中命令“mjoin”中加入新的Polylines, 您是否正在删除并构建新的Polyline2d?!
抱歉有不好的问题,我是新手
A 第一次试用
  1. public PolylineSegmentCollection(Polyline3d pline)
  2.         {
  3.             ObjectId[] vertices = pline.Cast().ToArray();
  4.             //PolylineVertex3d[] vertices = pline.Cast().ToArray();
  5.             int n = vertices.Length - 1;
  6.             for (int i = 0; i ().ToArray();
  7.                 ed.WriteMessage("\nNumber of vertexes: {0}", verts.Length);
  8.                 for (int i = 0; i < verts.Length; i++)
  9.                 {
  10.                     PolylineVertex3d vt = tr.GetObject(verts[i], OpenMode.ForRead) as PolylineVertex3d;
  11.                     coll.Add(new Point3d(vt.Position[0], vt.Position[1], vt.Position[2]));
  12.                 }
  13.                 tr.Commit();
  14.             }
  15.             return coll;
  16.         }
  17.         [CommandMethod("xx")]
  18.         static public void Append3dPolylines()
  19.         {
  20.             Document doc = Application.DocumentManager.MdiActiveDocument;
  21.             Editor ed = doc.Editor;
  22.             Database db = doc.Database;
  23.             Point3dCollection collPoint3d = null;
  24.             Point3dCollection allPoint3d = null;
  25.             PromptEntityOptions peo1 = new PromptEntityOptions("\nSelect source polyline : ");
  26.             peo1.SetRejectMessage("\nInvalid selection...");
  27.             peo1.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline3d), true);
  28.             PromptEntityResult res = ed.GetEntity(peo1);
  29.             if (PromptStatus.OK != res.Status)
  30.                 return;
  31.             using (Transaction trans = db.TransactionManager.StartTransaction())
  32.             {
  33.                                                BlockTable BlkTbl = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
  34.                                 BlockTableRecord BlkTblRec = trans.GetObject(BlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
  35.                                 Polyline3d newPoly = new Polyline3d();
  36.                                 BlkTblRec.AppendEntity(newPoly);
  37.                                 trans.AddNewlyCreatedDBObject(newPoly, true);
  38.                 try
  39.                 {
  40.                     collPoint3d = GetVertex(res);
  41.                     allPoint3d = new Point3dCollection();
  42.                     foreach (Point3d pt in collPoint3d)
  43.                     {
  44.                         allPoint3d.Add(pt);
  45.                     }
  46.                     while (true)
  47.                     {
  48.                         PromptEntityOptions peo2 = new PromptEntityOptions("\nSelect polyline to join : ");
  49.                         peo2.SetRejectMessage("\nInvalid selection...");
  50.                         peo2.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline3d), true);
  51.                         res = ed.GetEntity(peo2);
  52.                         switch (res.Status)
  53.                         {
  54.                             case PromptStatus.OK:
  55.                                 collPoint3d = GetVertex(res);
  56.                                 foreach (Point3d pt in collPoint3d)
  57.                                 {
  58.                                     allPoint3d.Add(pt);
  59.                                 }
  60.                                 break;
  61.                             case PromptStatus.Cancel:
  62.                                 foreach (Point3d pt in allPoint3d)
  63.                                 {
  64.                                     PolylineVertex3d vertex = new PolylineVertex3d(pt);
  65.                                     newPoly.AppendVertex(vertex);
  66.                                     trans.AddNewlyCreatedDBObject(vertex, true);
  67.                                 }
  68.                                 ed.WriteMessage("\nNew 3dPolyline created!");
  69.                                 return;
  70.                         }
  71.                     }
  72.                 }
  73.                 catch (System.Exception ex)
  74.                 {
  75.                     ed.WriteMessage(ex.Message);
  76.                 }
  77.                 trans.Commit();
  78.             }
  79.         }

回复

使用道具 举报

15

主题

687

帖子

169

银币

中流砥柱

Rank: 25

铜币
582
发表于 2016-1-23 09:38:12 | 显示全部楼层
也许这个试验也应该在Selectionset中工作。选择3dPolyline简单,如果在start或endpoint
之后选择3dPolyline也没关系。请测试它,也许您知道它如何在Selectionset中工作。在那里,它必须检查start或endpoint
  1.         [CommandMethod("join3d")]
  2.         static public void join3d()
  3.         {
  4.             Document document = Application.DocumentManager.MdiActiveDocument;
  5.             Editor ed = document.Editor;
  6.             Database db = document.Database;
  7.             PromptEntityOptions peo1 = new PromptEntityOptions("\nSelect source polyline : ");
  8.             peo1.SetRejectMessage("\nInvalid selection...");
  9.             peo1.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline), true);
  10.             peo1.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline2d), true);
  11.             peo1.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline3d), true);
  12.             PromptEntityResult res = ed.GetEntity(peo1);
  13.             if (PromptStatus.OK != res.Status)
  14.                 return;
  15.             ObjectId srcId = res.ObjectId;
  16.             while (true)
  17.             {
  18.                 PromptEntityOptions peo2 = new PromptEntityOptions("\nSelect polyline to join : ");
  19.                 peo2.SetRejectMessage("\nInvalid selection...");
  20.                 peo2.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline), true);
  21.                 peo2.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline2d), true);
  22.                 peo2.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline3d), true);
  23.                 res = ed.GetEntity(peo2);
  24.                 switch (res.Status)
  25.                 {
  26.                     case PromptStatus.OK:
  27.                         ObjectId joinId = res.ObjectId;
  28.                         try
  29.                         {
  30.                             using (Transaction trans = db.TransactionManager.StartTransaction())
  31.                             {
  32.                                 Entity srcPLine = trans.GetObject(srcId, OpenMode.ForRead) as Entity;
  33.                                 Entity addPLine = trans.GetObject(joinId, OpenMode.ForRead) as Entity;
  34.                                 srcPLine.UpgradeOpen();
  35.                                 srcPLine.JoinEntity(addPLine);
  36.                                 addPLine.UpgradeOpen();
  37.                                 addPLine.Erase();
  38.                                 trans.Commit();
  39.                             }
  40.                         }
  41.                         catch (System.Exception ex)
  42.                         {
  43.                             ed.WriteMessage(ex.Message);
  44.                         }
  45.                         break;
  46.                     case PromptStatus.Cancel:
  47.                         ed.WriteMessage("\nFinished!");
  48.                         return;
  49.                 }
  50.             }
  51.         }

中的3dPolyline
回复

使用道具 举报

30

主题

125

帖子

30

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
218
发表于 2016-1-25 05:12:52 | 显示全部楼层
ErrorStatus=AlreadyInDB
我收到此异常,无法理解。有人能理解并解决吗
在poly中。附加顶点(vex3d);不对劲。
  1. using (Transaction tr = db.TransactionManager.StartTransaction())
  2.                 {
  3.                     try
  4.                     {
  5.                         Polyline3d poly = new Polyline3d();
  6.                         btr.AppendEntity(poly);
  7.                         tr.AddNewlyCreatedDBObject(poly, true);
  8.                         foreach (Polyline3DPoints segs in psc)
  9.                         {
  10.                             Entity pline = (Entity)tr.GetObject(segs.ObjectID, OpenMode.ForWrite);
  11.                             foreach (ObjectId vId in (Polyline3d)pline)
  12.                             {
  13.                                 PolylineVertex3d vex3d = (PolylineVertex3d)tr.GetObject(vId, OpenMode.ForRead);
  14.                                 poly.AppendVertex(vex3d);
  15.                                 tr.AddNewlyCreatedDBObject(vex3d, true);
  16.                             }
  17.                         }
  18.                     }
  19.                     catch (System.Exception ex)
  20.                     { }
  21.                     tr.Commit();

回复

使用道具 举报

30

主题

125

帖子

30

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
218
发表于 2016-1-25 05:31:05 | 显示全部楼层
您好,
您必须为新的Polyline3d(多边形)创建新的polylinevertex3d。现在,您正在尝试将不同的多段线(psc、pline)顶点(vId)设置为新的
我不知道psc集合中有什么,但我预计会有Polyline3d的集合。
-Veli
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-2-4 21:58 , Processed in 0.160370 second(s), 70 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表