How to minimum measure i-logic

How to minimum measure i-logic

khnam
Contributor Contributor
232 Views
1 Reply
Message 1 of 2

How to minimum measure i-logic

khnam
Contributor
Contributor

Hi

When measured using i-logic below, there is an error from reality.
It is not the distance between the centers of the sides.
Can you tell me how i-logic works to find the minimum distance?

 

SubMain()
' Select two faces
Dim face1 As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select the first face.")
Dim face2 As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select the second face.")

' Measure distance only when two faces are selected
If face1 IsNot Nothing AndAlso face2 IsNot Nothing Then
' Center point of two sides
Dim centroid1 As Point = face1.PointOnFace
Dim centroid2 As Point = face2.PointOnFace

' Use the center points of the two sides to calculate the distance.
Dim distanceInCM As Double = centroid1.DistanceTo(centroid2) * 10 ' Convert to centimeters (cm).

'Display the distance as a message.
MessageBox.Show("The minimum distance between two selected faces is " & Math.Round(distanceInCM, 1).ToString() & " mm.")

'Assign a value to Measure1 of User parameters.
iProperties.Value("Custom", "measure1Value") = Math.Round(distanceInCM, 1).ToString()
Else
' If either of the two sides is not selected, an error message is displayed.
MessageBox.Show("Please select two faces.")
End If
End Sub

0 Likes
Accepted solutions (1)
233 Views
1 Reply
Reply (1)
Message 2 of 2

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @khnam . This is because the PointOnFace method gets a point somewhere on the interior of the Face, but definitely not in the center. Therefore, you can get a result that will be greater than the distance between the two faces. Here is a sample iLogic code that gets the minimum distance between two faces.

Sub Main()
	Dim oInvApp As Inventor.Application = ThisApplication
	Dim oCM As CommandManager = oInvApp.CommandManager
	' Select two faces
	Dim face1 As Face = oCM.Pick(SelectionFilterEnum.kPartFaceFilter, "Select the first face.")
	Dim face2 As Face = oCM.Pick(SelectionFilterEnum.kPartFaceFilter, "Select the second face.")
	
	' Measure distance only when two faces are selected
	If face1 IsNot Nothing AndAlso face2 IsNot Nothing Then		
		' Use the center points of the two sides to calculate the distance.
		Dim distanceInCM As Double = oInvApp.MeasureTools.GetMinimumDistance(face1, face2) * 10 ' Convert to centimeters (cm).
		
		'Display the distance as a message.
		MessageBox.Show("The minimum distance between two selected faces is " & Math.Round(distanceInCM, 3).ToString() & " mm.")
		
		'Assign a value to Measure1 of User parameters.
		iProperties.Value("Custom", "measure1Value") = Math.Round(distanceInCM, 1).ToString()
	Else
		' If either of the two sides is not selected, an error message is displayed.
		MessageBox.Show("Please select two faces.")
	End If
End Sub

 

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