Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Ilogic Code to get ID of a revolved shape

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
danny.lewisA9QBW
555 Views, 4 Replies

Ilogic Code to get ID of a revolved shape

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

Labels (2)
4 REPLIES 4
Message 2 of 5
Daan_M
in reply to: danny.lewisA9QBW

'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
in reply to: Daan_M

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

 

Message 4 of 5

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

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.

Post to forums  

Autodesk Design & Make Report