Hi @Sonny4. It looks like the code you posted is mainly just a repeat of what Alan Acheson posted in Message 4 in 2023, but with the one line of code accessing the ComponentOccurrence.OccurrencePropertySetsEnabled property uncommented, as he suggested in that message. If all that is required is ensuring that property's value is False for all components in the assembly, then we could use a much shorter code like the following iLogic rule example.
Similar to the original example, it expects the active document to be an assembly, and if it is not, it will exit the rule without doing anything. It then calls a custom, recursive Sub routine to process all components in the assembly to ensure that property is set the way we want it. It even avoids a few common potential errors, such as when a component does not have any sub components (like a part), and when the component is suppressed. When a component is suppressed, almost everything we try to do with it by code will throw an error, because it has been unloaded from Inventor's memory.
Sub Main
Dim oADoc As Inventor.AssemblyDocument = TryCast(ThisApplication.ActiveDocument, Inventor.AssemblyDocument)
If oADoc Is Nothing Then Return
DisableInstanceProperties(oADoc.ComponentDefinition.Occurrences)
End Sub
Sub DisableInstanceProperties(occs As Inventor.ComponentOccurrences)
If (occs Is Nothing) OrElse (occs.Count = 0) Then Return
For Each occ As Inventor.ComponentOccurrence In occs
If occ.Suppressed Then Continue For 'avoids potential error
If occ.OccurrencePropertySetsEnabled Then occ.OccurrencePropertySetsEnabled = False
DisableInstanceProperties(occ.SubOccurrences)
Next 'occ
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield

(Not an Autodesk Employee)