Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Measure Minimum Distance on Faces at an angle

Curtis_Waguespack
Consultant

Measure Minimum Distance on Faces at an angle

Curtis_Waguespack
Consultant
Consultant

 

Problem:

I'm trying to get the minimum distance between 2 faces that are not aligned to the X,Y, or Z axes. Ultimately I'm trying to do this in an assembly, which means that the ilogic function for doing this does not work for my needs.  see below for using the iLogic function in the assembly for this

 

In attempting to use the API to do this I am getting these results, where things work for the round face, but not for the square face. I assume the round face is getting the center points of the circular edges, but the square face is getting some other points. 

 

How would I get the correct measurement for these sloped faces?

 

 

Dim Face1 As Face
Dim Face2 As Face

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

Face1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select Start Face:")
Face2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select End Face:")

Dim Distance As Double
Distance = ThisApplication.MeasureTools.GetMinimumDistance(Face1.PointOnFace, Face2.PointOnFace,,,ClosestPointTwo)

Distance = oDoc.UnitsOfMeasure.ConvertUnits(Distance, "cm", "in")
MsgBox(Distance & " in",,"iLogic")

 

 

I've provided a 2023 example that demonstrates the issue. This example is a part, but I get the same results with this part in an assembly.

 

To see the issue open the part and run the rule. Then select the top and bottom face of the disc, and you will get 4 in, which is correct.

 

Curtis_Waguespack_0-1673893574946.png

 

Curtis_Waguespack_0-1673892208592.png

 

Do the same for the square shape and you get this result:

Curtis_Waguespack_1-1673892228189.png

 

 

Reply
Accepted solutions (2)
403 Views
4 Replies
Replies (4)

Curtis_Waguespack
Consultant
Consultant

oops!

 

Think I was just having Monday troubles, and overlooked the iLogic function to do this in an assembly 🙃

 

Curtis_Waguespack_0-1673894520922.jpeg

 

Dim compOcc = Component.InventorComponent("Measure Faces On Angle 2023:1") 

'bookmark	
Dim oThickness As Double
oThickness = Round(Measure.MinimumDistance(compOcc.Name, "TopFace1", compOcc.Name, "BottomFace1"),3)
MsgBox(oThickness)

 

However, I'd still prefer to do this with the API because I can not guarantee named entities exist

 

 

 

0 Likes

WCrihfield
Mentor
Mentor
Accepted solution

Hi @Curtis_Waguespack.  I'm still using 2022, so couldn't open your sample, but attempted to recreate the sample by creating an angled WorkPlane, then sketching a rectangle on it, which is not square with any main axes, and extruded it for testing.  This may not be a universal solution, but if both faces are 'planar' and parallel to each other, then you could get the Plane object from Face.Geometry, then use Plane.DistanceTo method on at least one of the two faces, which should eliminate the skewed point-to-point measurement.  I'm not using the Face.GeometryType to check for 'planar', but am using the kPartFacePlanarFilter.

oObj1 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select a Flat Face.")
If oObj1 Is Nothing OrElse (TypeOf oObj1 Is Face = False) Then Return
Dim oFace1 As Face = oObj1

oObj2 = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select a Flat Face.")
If oObj2 Is Nothing OrElse (TypeOf oObj2 Is Face = False) Then Return
Dim oFace2 As Face = oObj2

Dim oDoc As Document = oFace1.Parent.ComponentDefinition.Document
Dim oDist As Double
Dim oPlane1 As Plane = oFace1.Geometry
Dim oPlane2 As Plane = oFace2.Geometry
oDist = oPlane1.DistanceTo(oFace2.PointOnFace)
'oDist = oPlane1.DistanceTo(oPlane2.RootPoint)
oDist = Abs(oDoc.UnitsOfMeasure.ConvertUnits(oDist, "cm", "in"))
MsgBox("Min Distance = " & oDist & Chr(34), vbInformation, "")

However, if the two faces may not always be planar, or not always parallel, then this process may not work correctly either.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

WCrihfield
Mentor
Mentor
Accepted solution

Another variation I got decent results with is:  capturing Face2.PointOnFace to a variable (oP2), then using that within oP1 = Face1.GetClosestPointTo(oP2), to get the other Point, then using oP1.DistanceTo(oP2), which returned an accurate value.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Curtis_Waguespack
Consultant
Consultant

@WCrihfield, both suggestions look good. I think the first one will work for my needs, as the faces will always be parallel. I'll mark these as solutions later once I get a chance to look at them in the solution.

 

Thanks for looking at this!

 

Curtis_Waguespack_4-1673899031225.png