2016-10-31 126 views
3

我正在嘗試查找掃描折線的頂點點。 所以我有一個固體,它是通過沿着三維多段線掃一圈創建的。 它看起來像這樣:image of sweeped solid在AutoCAD中獲取實體的子實體頂點點

Googeling上週的整個星期五,我想我必須玩subentity部分。我發現如何改變subentity邊緣的顏色,但不能爲基因找不到如何訪問幾何

這是我到目前爲止的嘗試,但正如我注意到在底部我我有點失去了存在:

[CommandMethod("SubEntExample")] 
    public void SubEntExample() 
    { 
     Document doc = Application.DocumentManager.MdiActiveDocument; 
     Database db = doc.Database; 
     Editor ed = doc.Editor; 

     PromptEntityOptions peo = new PromptEntityOptions("\nSelect a 3D solid: "); 
     peo.SetRejectMessage("\nInvalid selection..."); 
     peo.AddAllowedClass(typeof(Solid3d), true); 

     PromptEntityResult per = ed.GetEntity(peo); 

     if (per.Status != PromptStatus.OK) 
      return; 

     using (Transaction Tx = db.TransactionManager.StartTransaction()) 
     { 
      Solid3d solid = Tx.GetObject(per.ObjectId, OpenMode.ForWrite) as Solid3d; 

      ObjectId[] ids = new ObjectId[] { per.ObjectId }; 

      FullSubentityPath path = new FullSubentityPath(ids, new SubentityId(SubentityType.Null, IntPtr.Zero)); 

      List<SubentityId> subEntIds = new List<SubentityId>(); 

      using (Autodesk.AutoCAD.BoundaryRepresentation.Brep brep = 
       new Autodesk.AutoCAD.BoundaryRepresentation.Brep(path)) 
      {      
       foreach (Autodesk.AutoCAD.BoundaryRepresentation.Edge edge in brep.Edges) 
       { 
        subEntIds.Add(edge.SubentityPath.SubentId); 
       }      
      } 

      foreach (SubentityId subentId in subEntIds) 
      { 

       *** here i am lost *** 

      } 
      Tx.Commit(); 
     } 
    } 
+0

如何將實體導出到DXF並查看文本文件中數據的組成?它可能會向你解釋子實體的機制。我手邊沒有具體的案件知識,但是,如果他們是「身份證」,那麼你接下來要「打開」這些身份證的什麼?這些將返回提供座標數據的合適對象。但這是一個猜測。查看DXF可能會顯示更多信息。也許你可以把它添加到你的問題。 –

回答

0

我的第一個解決方案涉及讓所有的夾具和決定哪些是相關的,但感謝來自互聯網(:))有點幫助我想出了一個辦法更好的解決方案

/// <summary> 
    /// Checks if there are boundaryreps that are marked as elliptical or circular arcs 
    /// returns true if we found at least 2 of those points 
    /// also stores the points in a referenced Point3dCollection 
    /// </summary> 
    /// <param name="solid"></param> 
    /// <param name="pts"></param> 
    /// <returns></returns> 
    private bool GetSweepPathPoints(Solid3d solid, ref Point3dCollection pts) 
    { 
     // create boundary rep for the solid 
     using (Brep brep = new Brep(solid)) 
     { 
      // get edges of the boundary rep 
      BrepEdgeCollection edges = brep.Edges; 
      foreach (Edge edge in edges) 
      { 
       // get the nativ curve geometry of the edges and then 
       // check if it is a circle 
       // for more info look at: 
       // http://adndevblog.typepad.com/autocad/2012/08/retrieving-native-curve-geometry-using-brep-api.html 
       Curve3d curv = ((ExternalCurve3d)edge.Curve).NativeCurve; 
       if (curv is CircularArc3d) 
       { 
        // transform curved arch into circle and add it to the colecction 
        // (if not in it alreadz) 
        CircularArc3d circle = curv as CircularArc3d; 
        if (!pts.Contains(circle.Center)) pts.Add(circle.Center); 
       } 
      } 
     } 
     return (pts.Count > 1) ? true : false; 
    } 

我以下面的方式調用整個事件

  Point3dCollection pts = new Point3dCollection(); 
      // only do the whole thing if we face a swept solid 
      if (GetSweepPathPoints(sld, ref pts)) 
      { 
       for (int i = 0; i < pts.Count; i++) 
       { 
        ed.WriteMessage("\nPt[{0}] = {1}", i, pts[i]); 
       } 
      }