.NET

Reply
Contributor
wein3967
Posts: 17
Registered: ‎02-29-2012
Message 1 of 11 (266 Views)
Accepted Solution

Identify Solid3d Object as Box or Cylinder

266 Views, 10 Replies
02-14-2014 09:40 AM

I am trying to determine, via VB.NET, what a particular solid is in a selection set. I already separate out the solid3d objects from everything else (e.g., lines, circles). I was just wondering if there is a "simple" way to figure out if each solid is a box or cylinder. It seems like AutoCAD doesn't really make that distinction internally and just considers them solids. I've done some complicated slicing and such in the past, but I am hoping I may have missed something simpler and perhaps more elegant. Thanks for any ideas.

Valued Mentor
gasty1001
Posts: 450
Registered: ‎04-11-2010
Message 2 of 11 (255 Views)

Re: Identify Solid3d Object as Box or Cylinder

02-14-2014 12:17 PM in reply to: wein3967

Hi,

 

If you only need to filter cubes and cylinders, you can check the bounding box of each shape, and compare its volume  to the volume of the solid (from the mass properties), if they are the same (may be using some tolerance) then it's a cube or a rectangular prism. I don't know of another way to identify geometric shapes than to get geometric properties and try to match them with known shapes.

 

Gaston Nunez

Contributor
wein3967
Posts: 17
Registered: ‎02-29-2012
Message 3 of 11 (249 Views)

Re: Identify Solid3d Object as Box or Cylinder

02-14-2014 12:28 PM in reply to: gasty1001

Gaston,

 

Thanks for the suggestion. I was/am actually currently just looking at trying out an approach like that. As far as I've worked it out, it may serve the purpose for my "ideal cases" (boxes and cylinders aligned orthographically). However, I'll need to think about how to assess boxes and cylinders that may be rotated along one or more axes. Thanks again. 

*Expert Elite*
dgorsman
Posts: 5,116
Registered: ‎10-12-2006
Message 4 of 11 (237 Views)

Re: Identify Solid3d Object as Box or Cylinder

02-14-2014 02:52 PM in reply to: wein3967

Is this for any solid, or just for the ones you create?  If the latter, then you could simply flag them with extra information at the time of creation.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
Adopt. Adapt. Overcome. Or be overcome.
A good question will be halfway to a good answer.


*Expert Elite*
_gile
Posts: 2,077
Registered: ‎04-29-2006
Message 5 of 11 (215 Views)

Re: Identify Solid3d Object as Box or Cylinder

02-15-2014 02:28 AM in reply to: dgorsman

Hi,

 

For solid analysis, you can use the Boundary Representation, Brep class (have to reference the acdbmgdbrep.dll).

For example a cylinder Brep must have  a single Complex, 3 faces and 2 circular edges of the same radius.

 

Here's a little snippet which evaluates if a solid is a non truncated cylinder (both faces are circular and parallel)

 

        private bool IsCylinder(Solid3d solid)
        {
            using (Brep brep = new Brep(solid))
            {
                if (brep.Complexes.Count() != 1)
                    return false;
                if (brep.Faces.Count() != 3)
                    return false;
                BrepEdgeCollection edges = brep.Edges;
                if (edges.Count() != 2)
                    return false;
                CircularArc3d[] circles = brep.Edges
                    .Select(edge => ((ExternalCurve3d)edge.Curve).NativeCurve as CircularArc3d)
                    .Where(circle => circle != null)
                    .ToArray();
                if (circles.Length != 2)
                    return false;
                return 
                    circles[0].Radius == circles[1].Radius && 
                    circles[0].Normal.IsParallelTo(circles[1].Normal);
            }
        }

 

Gilles Chanteau
Contributor
wein3967
Posts: 17
Registered: ‎02-29-2012
Message 6 of 11 (207 Views)

Re: Identify Solid3d Object as Box or Cylinder

02-15-2014 12:03 PM in reply to: dgorsman

dgorsman,

 

The majority of the time it is for solids (boxes and cylinder othogonally aligned to an axis) that we draw. Occasionally, we get files from other people and we run it through our VB.NET code to see what comes through and what needs to be redrawn/removed. Flagging items as they are created sounds like a good idea, however, I am not familiar enough with that to know what the would entail coding-wise (for me) and drawing-wise (for the CAD guys).

Contributor
wein3967
Posts: 17
Registered: ‎02-29-2012
Message 7 of 11 (205 Views)

Re: Identify Solid3d Object as Box or Cylinder

02-15-2014 12:08 PM in reply to: _gile

_gile,

 

The Boundary Representation class is a good idea. I have actually used it before, but it didn't occur to me that I might be able to implement it here. Once I get the Volume Comparision version working, I will try a Brep version as well. At the end of the day, the fastest one would be preferred (typically have a solids count up to 200,000). But there is something to be said for flexibility (potentailly correcting mal-aligned solids programatically) and a code path that others can follow. Thanks.

*Expert Elite*
dgorsman
Posts: 5,116
Registered: ‎10-12-2006
Message 8 of 11 (166 Views)

Re: Identify Solid3d Object as Box or Cylinder

02-18-2014 07:25 AM in reply to: wein3967

Compared to BREP, solid analysis, and even creating your own solids, adding Dictionaries and Xrecords is dirt simple.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
Adopt. Adapt. Overcome. Or be overcome.
A good question will be halfway to a good answer.


Contributor
wein3967
Posts: 17
Registered: ‎02-29-2012
Message 9 of 11 (155 Views)

Re: Identify Solid3d Object as Box or Cylinder

02-18-2014 11:55 AM in reply to: dgorsman

dgorsman,

 

I am curious has to how you would generally envision that being implemented. I mean, would I need to write custom tools for making cylinders and boxes so that the Dictionaries and Xrecords were created as the solids are created? Or, would I end up putting the burden on the CAD guys by having them manually add the appropraite Xrecord to each object they make (don't think that would be terribly productive). At some point, someone or something has to determine the shape (box or cylinder) and the direction (x, y, z, for cylinders).

 

Assuming that this was implemented, it would be beneficial going forward. There are, of course, many past and current models which would not have these special records. So, some code processing will still be necessary for older stuff as well as models provided to us by 3rd parties. Thanks.

*Expert Elite*
dgorsman
Posts: 5,116
Registered: ‎10-12-2006
Message 10 of 11 (146 Views)

Re: Identify Solid3d Object as Box or Cylinder

02-18-2014 02:11 PM in reply to: wein3967

If you already have something coded up to create your objects from a select set of data, then you are most of the way there.  Once you have the object and the inputs used to create that object, you pass them to another method which attaches the required data to the newly created object.  If you are hijacking the basic AutoCAD solid creation tools... not so easy, to the point where building your own tools makes control easier.

 

You've also identified a common problem in development: what do we do with legacy objects when something new is done?  In general, its a good idea to plan for the future before rolling something out.  You may identify areas which would better be handled now rather than trying to wrangle a square data into a round hole later on.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
Adopt. Adapt. Overcome. Or be overcome.
A good question will be halfway to a good answer.


You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community