Is there a method to get and return the longest edge of a part/body?

Is there a method to get and return the longest edge of a part/body?

melsabbahy
Explorer Explorer
528 Views
4 Replies
Message 1 of 5

Is there a method to get and return the longest edge of a part/body?

melsabbahy
Explorer
Explorer

I am trying to identify the longest edge inside a part (or body) measure its length and identify the start/end point and the angles with respect to the origin axis. 

 

Can anyone support in any of these steps?

Thanks!

0 Likes
529 Views
4 Replies
Replies (4)
Message 2 of 5

Andrii_Humeniuk
Advisor
Advisor

Hello @melsabbahy . This is an example of how to get the longest edge:

Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim oDocDef As PartComponentDefinition = oDoc.ComponentDefinition
Dim oEdge As Edge
Dim oEdgeLengths As New List(Of Double)
Dim oMin, oMax, oLength As Double
Dim oBody As SurfaceBody = oDocDef.SurfaceBodies.Item(1)
For Each oEdge In oBody.Edges
	oEdge.Evaluator.GetParamExtents(oMin, oMax)
	oEdge.Evaluator.GetLengthAtParam(oMin, oMax, oLength)
	oEdgeLengths.Add(Round(oLength, 6))
Next
For Each oEdge In oBody.Edges
	oEdge.Evaluator.GetParamExtents(oMin, oMax)
	oEdge.Evaluator.GetLengthAtParam(oMin, oMax, oLength)
	If Round(oLength, 6) = oEdgeLengths.Max Then
		MessageBox.Show(oLength, oBody.Name)
	End If
Next

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 3 of 5

dimamazutaMMJ32
Advocate
Advocate
Hello!
I added to the sample of the code above the angle measurements to the original axes, eges naming and identify the start/end point.

 

 

Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim oDocDef As PartComponentDefinition = oDoc.ComponentDefinition
Dim oEdge As Edge
Dim oEdgeLengths As New List(Of Double)
Dim oMin, oMax, oLength As Double
Dim oBody As SurfaceBody = oDocDef.SurfaceBodies.Item(1)

Dim i As Integer = 1

For Each oEdge In oBody.Edges
	oEdge.Evaluator.GetParamExtents(oMin, oMax)
	oEdge.Evaluator.GetLengthAtParam(oMin, oMax, oLength)
	oEdgeLengths.Add(Round(oLength, 6))
Next
For Each oEdge In oBody.Edges
	oEdge.Evaluator.GetParamExtents(oMin, oMax)
	oEdge.Evaluator.GetLengthAtParam(oMin, oMax, oLength)	
	If Round(oLength, 6) = oEdgeLengths.Max Then		
		MessageBox.Show("The longest edge =" & oLength & "cm", oBody.Name)		
		Try
		oNames = iLogicVb.Automation.GetNamedEntities(oDoc)
		oNames.SetName(oEdge, "LongestEdge" & i)
		oNames.SetName(oEdge.StartVertex, "StartPoint" & i)
		oNames.SetName(oEdge.StopVertex, "EndPoint" & i)
		
		i = i + 1
		
		angleX = Measure.Angle("LongestEdge" & i, "X Axis") 
		angleY = Measure.Angle("LongestEdge" & i, "Y Axis")
		angleZ = Measure.Angle("LongestEdge" & i, "Z Axis")
		
		Dim Text1 As String = "Angle bettwen Endge and X Axis =" & angleX & " deg;"
		Dim Text2 As String = "Angle bettwen Endge and Y Axis =" & angleY & " deg;"
		Dim Text3 As String = "Angle bettwen Endge and Z Axis =" & angleZ & " deg."
		MessageBox.Show(Text1 & vbLf & Text2 & vbLf & Text3, "Title")
		
		Catch
		End Try		
	End If	
Next

 

 

Message 4 of 5

melsabbahy
Explorer
Explorer

@Andrii_Humeniuk thank you so much. Your contribution added a lot.

0 Likes
Message 5 of 5

melsabbahy
Explorer
Explorer

thank you so much @dimamazutaMMJ32 . I liked the idea of adding entities!

0 Likes