Author Topic: Getting subentity vertex points of solid in AutoCAD  (Read 3365 times)

0 Members and 1 Guest are viewing this topic.

Smirzor

  • Guest
Getting subentity vertex points of solid in AutoCAD
« on: October 31, 2016, 11:12:57 AM »
I am trying to find the vertex points of a swept polyline. So i have a solid that was created by sweeping a circle along a 3D polyline. It looks like that:


Googeling the whole of friday last week i think i have to play around with the subentity part. I found out how to change the color of the subentity edges for instance, but couldnt for christs sake not find out how to access the geometric

This is what i tried out so far, but as i noted right at the bottom i am kinda lost there. (or am i completly on the wrong path with subentity)

(long story short, I want to get the coordinates of the vertices of the 3D solid that was swept from a 3dpolyline by using a circle)

Code: [Select]
    [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();
        }
    }

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Getting subentity vertex points of solid in AutoCAD
« Reply #1 on: November 11, 2016, 07:37:46 PM »
_SURFEXTRACTCURVE  gives you isolines that may be handy

Alexander Rivilis

  • Bull Frog
  • Posts: 214
  • Programmer from Kyiv (Ukraine)
Re: Getting subentity vertex points of solid in AutoCAD
« Reply #2 on: November 13, 2016, 06:51:49 PM »
IMHO I've answered to Smirzor: https://forums.autodesk.com/t5/net/getting-subentity-vertex-points-of-swept-solid/m-p/6662855#M50857
Code - C#: [Select]
  1. using System;
  2. using Autodesk.AutoCAD.Runtime;
  3. using Autodesk.AutoCAD.ApplicationServices;
  4. using Autodesk.AutoCAD.DatabaseServices;
  5. using Autodesk.AutoCAD.Geometry;
  6. using Autodesk.AutoCAD.EditorInput;
  7. using Autodesk.AutoCAD.BoundaryRepresentation;
  8.  
  9. // This line is not mandatory, but improves loading performances
  10. [assembly: CommandClass(typeof(GetSweepAxis.MyCommands))]
  11.  
  12. namespace GetSweepAxis
  13. {
  14.  
  15.   public class MyCommands
  16.   {
  17.  
  18.     [CommandMethod("FindCylinderAxis")]
  19.     public void FindCylinderAxis()
  20.     {
  21.       Document doc = Application.DocumentManager.MdiActiveDocument;
  22.       Editor ed = doc.Editor;
  23.       PromptEntityOptions peo = new PromptEntityOptions("Pick a 3DSOLID: ");
  24.       peo.SetRejectMessage("\nA 3d solid must be selected.");
  25.       peo.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Solid3d), true);
  26.       PromptEntityResult per = ed.GetEntity(peo);
  27.       if (per.Status != PromptStatus.OK)
  28.         return;
  29.  
  30.       using (Transaction tr = doc.Database.TransactionManager.StartTransaction())
  31.       {
  32.         Solid3d sld = tr.GetObject(per.ObjectId, OpenMode.ForRead, false) as Solid3d;
  33.         Point3d axisPt1 = Point3d.Origin;
  34.         Point3d axisPt2 = Point3d.Origin;
  35.         Point3dCollection pts = new Point3dCollection();
  36.         if (GetCylinderAxis(sld, ref  pts))
  37.         {
  38.           for (int i = 0; i < pts.Count; i++)
  39.           {
  40.             ed.WriteMessage("\nPt[{0}] = {1}", i, pts[i]);
  41.           }
  42.         }
  43.         else
  44.         {
  45.           ed.WriteMessage("\nNot a sweeped solid");
  46.         }
  47.         tr.Commit();
  48.       }
  49.     }
  50.  
  51.     private bool GetCylinderAxis(Solid3d solid, ref Point3dCollection pts)
  52.     {
  53.       using (Brep brep = new Brep(solid))
  54.       {
  55.         BrepEdgeCollection edges = brep.Edges;
  56.         foreach (Edge edge in edges)
  57.         {
  58.           Curve3d curv = ((ExternalCurve3d)edge.Curve).NativeCurve;
  59.           if (curv is CircularArc3d)
  60.           {
  61.             CircularArc3d circle = curv as CircularArc3d;
  62.             if (!pts.Contains(circle.Center)) pts.Add(circle.Center);
  63.           }
  64.           else if (curv is EllipticalArc3d)
  65.           {
  66.             EllipticalArc3d circle = curv as EllipticalArc3d;
  67.             if (!pts.Contains(circle.Center)) pts.Add(circle.Center);
  68.           }
  69.         }
  70.       }
  71.       return (pts.Count > 1) ? true : false;
  72.     }
  73.   }
  74. }

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Getting subentity vertex points of solid in AutoCAD
« Reply #3 on: November 15, 2016, 08:58:35 PM »
Oh that is nice

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2139
  • class keyThumper<T>:ILazy<T>
Re: Getting subentity vertex points of solid in AutoCAD
« Reply #4 on: November 15, 2016, 10:05:28 PM »
Oh that is nice

Yes, it is , isn't it.

Thanks Alexander
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

lamarn

  • Swamp Rat
  • Posts: 636
Re: Getting subentity vertex points of solid in AutoCAD
« Reply #5 on: November 16, 2016, 01:53:25 AM »
Any possibility to test it using a .dll file?
Design is something you should do with both hands. My 2d hand , my 3d hand ..

Alexander Rivilis

  • Bull Frog
  • Posts: 214
  • Programmer from Kyiv (Ukraine)
Re: Getting subentity vertex points of solid in AutoCAD
« Reply #6 on: November 21, 2016, 09:06:56 AM »
Any possibility to test it using a .dll file?
Sorry but I did not understand this question.  :-(