To create a custom iProperty that contains the total length of some components in an assembly, you can use iLogic in Autodesk Inventor. Here's how you can create a rule that will set the value of a custom iProperty called "Total Length" based on the length of a beam component, the thickness of a bottom plate, and the thickness of a top plate:
- Open the assembly that you want to add the custom iProperty to.
- Open the iLogic Editor by going to the Manage tab and clicking on "iLogic Editor" in the iLogic panel.
- Create a new rule by clicking on the "New Rule" button in the iLogic Editor.
- Name the rule "Set Total Length" and add the following code:
' Get the length of the beam component
Dim beamLength As Double = Parameter("Beam Component Name", "Length")
' Get the thickness of the bottom plate
Dim bottomPlateThk As Double = Parameter("Bottom Plate Name", "Thk")
' Get the thickness of the top plate
Dim topPlateThk As Double = Parameter("Top Plate Name", "Thk")
' Calculate the total length
Dim totalLength As Double = beamLength + bottomPlateThk + topPlateThk
' Set the value of the custom iProperty
iProperties.Value("Custom", "Total Length") = totalLength
Replace "Beam Component Name", "Bottom Plate Name", and "Top Plate Name" with the names of the components in your assembly that contain the length and thickness parameters.
5.Save the rule and close the iLogic Editor.
Now, every time you run the "Set Total Length" rule, it will calculate the total length of the components and set the value of the custom iProperty "Total Length" to the calculated value.
To format the custom iProperty to display the length in feet and inches (fraction to 1/16), you can modify the rule as follows:
' Get the length of the beam component in inches
Dim beamLengthIn As Double = Parameter("Beam Component Name", "Length")
' Get the thickness of the bottom plate in inches
Dim bottomPlateThkIn As Double = Parameter("Bottom Plate Name", "Thk")
' Get the thickness of the top plate in inches
Dim topPlateThkIn As Double = Parameter("Top Plate Name", "Thk")
' Calculate the total length in inches
Dim totalLengthIn As Double = beamLengthIn + bottomPlateThkIn + topPlateThkIn
' Convert total length from inches to feet and inches
Dim totalFeet As Integer = Math.Floor(totalLengthIn / 12)
Dim totalInches As Double = totalLengthIn - (totalFeet * 12)
Dim totalInchesRound As Double = Math.Round(totalInches * 16) / 16
' Set the value of the custom iProperty
iProperties.Value("Custom", "Total Length") = totalFeet.ToString() & "'-" & totalInchesRound.ToString("0.0''")
This code first calculates the total length in inches and then converts it to feet and inches. The total inches are rounded to the nearest 1/16th and displayed with a precision of one decimal place. The resulting value is formatted as feet-inches, and the dual display of the total length is shown.