Here is another way measure the distance from a selected part face to the 'next' part face 'behind' the selected one.
It is a bit longer code, because there are a lot of things to consider and check for, but I think you will like it. It doesn't just measure to all other parallel faces on the part, it only measures from the selected face to any faces that are 'behind' that face (on the same solid body), then if there was more than one measurement, it returns the measurement to the closest one (smallest non-zero measurement).
It is set up to be used within a Part document, and to measure between planar (flat) part faces only right now, but it could be further customized to include other types of entities and possibly work in other environments (assembly).
It uses the 'FindUsingVector' function, which is defined within the part's component definition.
Here's the iLogic code:
Sub Main()
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kPartDocumentObject Then
MsgBox("A Part Document must be active for this rule to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
Exit Sub
End If
Dim oPDef As PartComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition
Dim oStartFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select a part face.")
Dim oStartPt As Point = oStartFace.PointOnFace
'get the face 'normal' ('upwards direction' UnitVector of this face)
Dim oParams() As Double = {0,0} 'must either specify initial array size, or set values
Dim oNormals() As Double = {0,0,0} 'must either specify initial array size, or set values
oStartFace.Evaluator.GetNormal(oParams, oNormals) 'oNormals defines its UnitVector data
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
'create a UnitVector with reverse direction
'if you are facing a flat part face squarely, it's 'normal' will be pointing back at you
'we want to search in the opposite direction from that face
For i As Integer = 0 To 2
If Not oNormals(i) = 0 Then
oNormals(i) = oNormals(i) * (-1)
End If
Next
Dim oDir As UnitVector = oTG.CreateUnitVector(oNormals(0), oNormals(1), oNormals(2))
Dim oFilter() As SelectionFilterEnum = {SelectionFilterEnum.kPartFacePlanarFilter} 'SelectionFilterEnum.kAllPlanarEntities
Dim oObsEnum As ObjectsEnumerator = oPDef.FindUsingVector(oStartPt, oDir, oFilter)
If oObsEnum.Count <= 1 Then 'because it finds the starting face
MsgBox("No planar entities found. Exiting.", , "")
Exit Sub
End If
Dim oStartPlane As Plane = oStartFace.Geometry
Dim oDistances As New List(Of Double)
Dim oDbl As Double
For Each oFace As Face In oObsEnum
If oFace Is oStartFace Then Continue For
Dim oOtherPlane As Plane = oFace.Geometry
If oOtherPlane.IsParallelTo(oStartPlane) Then
oDbl = GetDistance(oStartPlane, oOtherPlane)
If oDbl > 0 Then
oDistances.Add(oDbl)
End If
End If
Next
Dim oDistance As Double
If oDistances.Count = 0 Then
MsgBox("No distances in list. Exiting.", , "")
Exit Sub
ElseIf oDistances.Count = 1 Then
oDistance = oDistances.First
MsgBox("oDistance = " & oDistance,,"")
Else
oDistance = MinOfMany(oDistances.ToArray)
MsgBox("oDistance = " & oDistance,,"")
' For Each oDst As Double In oDistances
' MsgBox("oDst = " & oDst, , "")
' Next
End If
End Sub
Public Function GetDistance(ByVal oStart As Plane, ByVal oEnd As Plane) As Double
Dim oMeasure As MeasureTools = ThisApplication.MeasureTools
Dim oDist As Double = oMeasure.GetMinimumDistance(oStart, oEnd)
oDist = ThisApplication.UnitsOfMeasure.ConvertUnits(oDist, UnitsTypeEnum.kDatabaseLengthUnits, UnitsTypeEnum.kInchLengthUnits)
GetDistance = oDist
End Function
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
If you have time, please... Vote For My IDEAS 💡or you can Explore My CONTRIBUTIONS
Wesley Crihfield

(Not an Autodesk Employee)