Hi all,
I need to add to all the components (parts and subassies) of an assembly an iproperty that is an extract of the filename
I tried the code below but is working just for the parts not the subassies.
Sub Main
On Error Resume Next
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oAsmDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
Dim oLeafOccs As ComponentOccurrencesEnumerator = oAsmDef.Occurrences.AllLeafOccurrences
'when you turn this on, you should also turn it back off when done
ThisApplication.SilentOperation = True
Dim oOcc As ComponentOccurrence
For Each oOcc In oLeafOccs
iProperties.Value(oOcc.Name, "Custom", "PN5") =(Mid(oOcc.Name, 11, 3))
Next
End Sub
Solved! Go to Solution.
Solved by FINET_Laurent. Go to Solution.
Hello @aurel_e,
The issue you are facing is that the AllLeafOccurrences collection contains each single part of the assembly.
To perform the desired task, you will need a recursive function that will go through each occurrences, & sub-occurences if present, thus englobing also the assemblies. Here a code with no error handling :
Sub Main
On Error Resume Next
Dim doc As AssemblyDocument = ThisApplication.ActiveDocument
Dim acd As AssemblyComponentDefinition = doc.ComponentDefinition
addProperty(acd.Occurrences)
End Sub
Sub addProperty(occs As Inventor.ComponentOccurrences) 'recursive
For Each occ As Inventor.ComponentOccurrence In occs
iProperties.Value(occ.Name, "Custom", "PN5") = (Mid(occ.Name, 11, 3))
If occ.SubOccurrences.Count > 0 Then addProperty(occ.SubOccurrences)
Next
End Sub
Kind regards,
FINET L.
If this post solved your question, please kindly mark it as "Solution"
If this post helped out in any way to solve your question, please drop a "Like"Perfect. I had to add that
On Error Resume Next
on the 2nd part of the code to make it work.
Many thanks.
Can't find what you're looking for? Ask the community or share your knowledge.