Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
WCrihfield
in reply to: Anonymous

You may need to convert the value to your local document units.  By default, any Double type values that are returned from iLogic's built-in measurement functions, are always given in the "Database Units" for that type of measurement. The "Database Units" used for Length measurements is always Centimeters, instead of the units specified within the Document Settings.  That's just how iLogic is set up, and that can't be changed.  However, you can convert the returned values by which ever means you prefer.  You can simply include some extra math in your code to compensate for the unit differences, or you can use Inventor's built-in unit converter.

 

Here is an updated version of that code, in which I am converting the units to Inches, instead of leaving them in default Centimeters.  I've also included the Perimeter measurement, to show the difference (when applicable).

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 oPDoc As PartDocument = ThisApplication.ActiveDocument
Dim oCustPropSet As PropertySet = oPDoc.PropertySets.Item("Inventor User Defined Properties")
Dim oFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select a Part Face.")
Dim oMeasure As MeasureTools = ThisApplication.MeasureTools
Dim oPerimeter, oOther, oTLL As Double

For Each oEL As EdgeLoop In oFace.EdgeLoops
	If oEL.IsOuterEdgeLoop Then
		'<<< This doesn't accound for interior holes or cutouts >>> 
		oPerimeter = oMeasure.GetLoopLength(oEL)
	Else
		oOther = oOther + oMeasure.GetLoopLength(oEL)
	End If
Next
oTLL = (oPerimeter + oOther)

'Convert the Database Units (Centimeters) to Inches
'oPerimeter = (oPerimeter / 2.54)
'oOther = (oOther / 2.54)
'or
oPerimeter = ThisApplication.UnitsOfMeasure.ConvertUnits(oPerimeter, UnitsTypeEnum.kDatabaseLengthUnits, UnitsTypeEnum.kInchLengthUnits)
oOther = ThisApplication.UnitsOfMeasure.ConvertUnits(oOther, UnitsTypeEnum.kDatabaseLengthUnits, UnitsTypeEnum.kInchLengthUnits)

'the measured units have already been converted now, so the math with be in Inches
oTLL = (oPerimeter + oOther)

oAns = MsgBox("Perimiter = " & oPerimeter & vbCrLf & _
"Other Interior Loop Lengths = " & oOther & vbCrLf & _
"Total Loop Length = " & oTLL & vbCrLf & _
"Do you want to write the Total Loop Length value to iProperties? ", vbYesNo + vbQuestion + vbDefaultButton2, " TOTAL LOOP LENGTH ")
If oAns = vbNo Then
	Exit Sub
ElseIf oAns = vbYes Then
	'checking if that iProperty already exists or if it needs to be created
	Dim oExists As Boolean 'False by default
	For Each oProp As Inventor.Property In oCustPropSet
		If oProp.Name = "Total Loop Length" Then
			oProp.Value = oTLL
			oExists = True
		End If
	Next
	If oExists = False Then
		oCustPropSet.Add(oTLL, "Total Loop Length")
	End If
End If

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' :thumbs_up:.

If you have time, please... Vote For My IDEAS :light_bulb:and Explore My CONTRIBUTIONS

Inventor 2021 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)