Ilogic Code to get ID of a revolved shape

Ilogic Code to get ID of a revolved shape

danny.lewisA9QBW
Advocate Advocate
1,096 Views
4 Replies
Message 1 of 5

Ilogic Code to get ID of a revolved shape

danny.lewisA9QBW
Advocate
Advocate

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

0 Likes
Accepted solutions (2)
1,097 Views
4 Replies
Replies (4)
Message 2 of 5

Daan_M
Collaborator
Collaborator

'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?

Message 3 of 5

danny.lewisA9QBW
Advocate
Advocate

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

 

revolved shape.JPG

 

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

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

EESignature

(Not an Autodesk Employee)

Message 5 of 5

danny.lewisA9QBW
Advocate
Advocate
Accepted solution

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)