Is It Possible to Get Distances programatically?

Valued Contributor
Valued Contributor

Hi, everyone!

 

Does anybody know if it's possible to get the distance between to faces or edges of diferent parts in a assembly document programatically as show in the pic below?

 

PainelBandeira.png

 

Thanks!

3 REPLIES

Re: Is It Possible to Get Distances programatically?

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

You can either use the MinimumDistance() or NormalDistance() methods on the AssemblyDocument object. The following code computes the minimum distance between the first faces of the first two occurrences in the active assembly document.

Additionally to the distance value, you can indicate the two points between which the minimum distance was measured (not done in my code).

'----------------------------------------------------------------------
' ASM: Compute the minimum distance between two entities in ASM
'----------------------------------------------------------------------
Dim objAsm As SolidEdgeAssembly.AssemblyDocument = objApp.ActiveDocument
Dim objOccs As SolidEdgeAssembly.Occurrences = objAsm.Occurrences
' Get the first face from the first occurrence (assuming it is a part occurrence)
Dim objOcc1 As SolidEdgeAssembly.Occurrence = objOccs.Item(1)
Dim objDoc1 As SolidEdgePart.PartDocument = objOcc1.OccurrenceDocument
Dim objBody1 As SolidEdgeGeometry.Body = objDoc1.Models.Item(1).Body
Dim objFaces1 As SolidEdgeGeometry.Faces = objBody1.Faces(FeatureTopologyQueryTypeConstants.igQueryAll)
Dim objFace1 As SolidEdgeGeometry.Face = objFaces1.Item(1)
' Get the first face from the second occurrence (assuming it is a part occurrence)
Dim objOcc2 As SolidEdgeAssembly.Occurrence = objOccs.Item(2)
Dim objDoc2 As SolidEdgePart.PartDocument = objOcc2.OccurrenceDocument
Dim objBody2 As SolidEdgeGeometry.Body = objDoc2.Models.Item(1).Body
Dim objFaces2 As SolidEdgeGeometry.Faces = objBody2.Faces(FeatureTopologyQueryTypeConstants.igQueryAll)
Dim objFace2 As SolidEdgeGeometry.Face = objFaces2.Item(1)
' Create references to the faces
Dim objRef1 As SolidEdgeFramework.Reference = objAsm.CreateReference(objOcc1, objFace1)
Dim objRef2 As SolidEdgeFramework.Reference = objAsm.CreateReference(objOcc2, objFace2)
' Compute the minimum distance between both faces
Dim dist As Double = 0
Dim pnt1(2) As Double
Dim pnt2(2) As Double
objAsm.MinimumDistance(objRef1, objRef2, dist, pnt1, pnt2)
' Highlight the two faces and show the distance value
Dim objHLSet As SolidEdgeFramework.HighlightSet = objAsm.HighlightSets.Add()
objHLSet.AddItem(objRef1)
objHLSet.AddItem(objRef2)
objHLSet.Draw()
MsgBox("Minimum Distance:  " & (dist * 1000).ToString("F2") & " mm")
objHLSet.Delete()

 

Re: Is It Possible to Get Distances programatically?

Valued Contributor
Valued Contributor

Hi, Martin!

 

I'll implement this code as soon as possible and give you a feedback!

 

Thank you!

Re: Is It Possible to Get Distances programatically?

Valued Contributor
Valued Contributor
Thanks Martin!

It works perfectly !!!