Hi again @Anonymous ,
I took the time to write an iLogic rule for you. Hopefully it's what you're looking for 🙂
Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oFace1 As FaceProxy = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select start face")
Dim oFace2 As FaceProxy = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select end face")
Dim oHole As FaceProxy = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceCylindricalFilter, "Select Circular reference")
Dim FactoryFile As String = "C:\VaultWorkingFolder\Designs\Temp\Jhoel\BoltingAssy\M12 Bolt Nut Washer.ipt" 'Full file path to iPart factory
Dim MemberFile As String = "C:\VaultWorkingFolder\Designs\Temp\Jhoel\BoltingAssy\TestMember1" & ".ipt" 'Full file path to iPart member
Dim oGripLength As Double = Math.Round(ThisApplication.MeasureTools.GetMinimumDistance(oFace1, oFace2), 5) *10
Dim oCustomArr(0) As String
oCustomArr(0) = oGripLength & " mm"
Dim oMember As ComponentOccurrence = oAsm.ComponentDefinition.Occurrences.AddCustomiPartMember(FactoryFile, _
ThisApplication.TransientGeometry.CreateMatrix(), MemberFile, ,oCustomArr)
Dim oZaxis As WorkAxisProxy
Call oMember.CreateGeometryProxy(oMember.Definition.WorkAxes.Item("Z Axis"), oZaxis)
Dim oInsPlane As WorkPlaneProxy
Call oMember.CreateGeometryProxy(oMember.Definition.WorkPlanes.Item("XY Plane"), oInsPlane)
oAsm.ComponentDefinition.Constraints.AddMateConstraint(oZaxis, oHole, 0, ,InferredTypeEnum.kInferredLine)
oAsm.ComponentDefinition.Constraints.AddMateConstraint(oFace1, oInsPlane, "2.5 mm")
If you run this rule from the main assembly you've attached previously you'll be asked to select start face, end face and hole.
The code will then place your bolt with desired grip length and constrain it in position 🙂