Does anyone have a handle snippet of code for getting the ID of a revolved shape? Essentially I am looking for a generic code that would do the following:
Is is revolved: Yep {got this figured already}
Then get the Id of the revolved shape
If it's 0, then it's solid,
If it's <> 0, then RevolvedId
Solved! Go to Solution.
Solved by danny.lewisA9QBW. Go to Solution.
Solved by WCrihfield. Go to Solution.
'it' as in a body?
RevolvedId as in the body type? Solid/surface/whatever else?
I guess after identifying that the body is revolved, the fact that it is revolved doesn't matter anymore, so you just need the body Id right?
Hopefully this clears things up a bit... this is what I would want the code to find the ID of. This is my 'tester' that I'm using, so I can't just pull parameters. I want the code to measure and interpret the ID of the revolved solid/shape regardless of how the users draw (and regardless the parameters) of the revolved shape
If the ID dimension is always going to be a cylindrical face (even if not complete circle), and not a angled like a cone or rounded, then a simple code like this might work for you.
It loops through each body, then each face of each body, checking if the face is cylindrical shaped, then defines its geometry as a mathematical (transient) cylinder, then gets its radius (x2 for Dia.) then adds that Diameter to a list. At the end, it compares all the diameters in the list to find the smallest one, and returns that as the ID.
It's a very simple code, and could probably use a few checks to avoid possible errors, but works for my test part.
I have the math to return Inches, so you can delete the "/2.54" if you want centimeters.
Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oDs As New List(Of Double)
For Each oBody As SurfaceBody In oPDef.SurfaceBodies
For Each oFace As Face In oBody.Faces
If oFace.SurfaceType = SurfaceTypeEnum.kCylinderSurface Then
Dim oCyl As Cylinder = oFace.Geometry
oDs.Add((oCyl.Radius * 2)/2.54)
End If
Next
Next
Dim oSmallestID As Double = oDs.Min
MsgBox("The smallest ID of all Cylindrical surfaces found = " & oSmallestID.ToString)
Wesley Crihfield
(Not an Autodesk Employee)
Awesome...
plus your approach with the cylinders works for revolved shapes that are just an arc and is easily tweaked to show the OD as well (updated code below):
Dim oPDoc As PartDocument = ThisApplication.ActiveDocument Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition Dim oDs As New List(Of Double) For Each oBody As SurfaceBody In oPDef.SurfaceBodies For Each oFace As Face In oBody.Faces If oFace.SurfaceType = SurfaceTypeEnum.kCylinderSurface Then Dim oCyl As Cylinder = oFace.Geometry oDs.Add((oCyl.Radius * 2)/2.54) End If Next Next Dim oSmallestID As Double = oDs.Min Dim oLargestOD As Double = oDs.Max MsgBox("The smallest ID of all Cylindrical surfaces found [in]= " & oSmallestID.ToString & vbCrLf & _ "The largest OD of all Cylindrical surfaces found [in]= " & oLargestOD)
Can't find what you're looking for? Ask the community or share your knowledge.