Message 1 of 8
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello I have had some code developed over two years ago now, for Inventor 2020, now I have Inventor 2022, it doesnt seem to be working perfectly.
The code attached is supposed to run on an Assembly, create a bounding box in each part file, create three custom iProperties called, With, Length, Thickness (Or BoxThickness), grab the dimensions from the bounding box, put the smallest value as the thickness. It does work, but when I save the assembly to changes the values back to default, and also the thickness property isn't showing correctly. Any suggestions?
Imports system.Collections
Public Sub Main()
' Get the active assembly.
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
' Get the assembly component definition.
Dim oAsmDef As AssemblyComponentDefinition
oAsmDef = oAsmDoc.ComponentDefinition
' Get all of the leaf occurrences of the assembly.
Dim oLeafOccs As ComponentOccurrencesEnumerator
oLeafOccs = oAsmDef.Occurrences.AllLeafOccurrences
' Iterate through all part occurrences in assembly.
Dim oOcc As ComponentOccurrence
For Each oOcc In oLeafOccs
L = Math.Abs(oOcc.RangeBox.MaxPoint.X - oOcc.RangeBox.MinPoint.X) * 10
W = Math.Abs(oOcc.RangeBox.MaxPoint.Y - oOcc.RangeBox.MinPoint.Y) * 10
H = Math.Abs(oOcc.RangeBox.MaxPoint.Z - oOcc.RangeBox.MinPoint.Z) * 10
Dim oList As New ArrayList
oList.Add(L)
oList.Add(W)
oList.Add(H)
Call oList.Sort()
iProperties.Value(oOcc.Name,"Custom", "Length") = Round(oList.Item(2),0)& " mm"
iProperties.Value(oOcc.Name,"Custom", "Width") = Round(oList.Item(1),0)& " mm"
iProperties.Value(oOcc.Name, "Custom", "BoxThickness") = Round(oList.Item(0),1) & " mm"
Next
End Sub
Solved! Go to Solution.