Remove all instance properties

Remove all instance properties

johan.degreef
Advisor Advisor
1,037 Views
7 Replies
Message 1 of 8

Remove all instance properties

johan.degreef
Advisor
Advisor

Is there a way to remove all (given in the past) instance properties from an assembly, its subassemblies and parts?

Inventor 2025, Vault Professional 2025, Autocad Plant 3D 2025
0 Likes
Accepted solutions (2)
1,038 Views
7 Replies
Replies (7)
Message 2 of 8

EdvinTailwind
Collaborator
Collaborator

In Vault multi-Property editing can be done like this to the files you select:

EdvinTailwind_0-1687254863462.png

 

Then you'll get a spreadsheet looking window where everything can be edited in bulk. The trick is to clear one cell at the top, and then drag it over the rest (both rows and columns), much like Excel. The only limitation is that you can't drag text into numeric etc. In this example the Cost column can't be included as it's a numeric one:

EdvinTailwind_1-1687255156619.png

 

Coming up next: someone posting an iLogic script that does this in a second. 😉

 

Message 3 of 8

johan.degreef
Advisor
Advisor

@EdvinTailwind Thx, I know this workflow, but an instance property is tied to an assembly. I think this will not work this way

Inventor 2025, Vault Professional 2025, Autocad Plant 3D 2025
0 Likes
Message 4 of 8

A.Acheson
Mentor
Mentor
Accepted solution

Hi @johan.degreef 

It took a bit of digging as instance properties are hidden within occurrence>occurrencepropertysets.

This forum search here helped me narrow down where to look. There was a handy sample in there written in VBA and here it is converted to VB.NET for ilogic environment. 

 

There is two lines in there commented off for now but you can switch them on depending on what you want to do and once you make sure it is catching all the properties you want to change which can be checked by viewing the logger window.

One is to enable/disable Instance properties and the other will set the property expression to a blank string. This code isn't tested so as always test in a non production environment  first to ensure it works as expected. 

 

'oProp.Expression = ""
'oOccu.OccurrencePropertySetsEnabled = False

 

 

Sub Main()
    If ThisApplication.ActiveDocument Is Nothing Then
        MsgBox ("Please open an assembly document!")
    ElseIf (ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject) Then
        MsgBox ("Please open an assembly document!")
    Else
    
        Dim oDoc As AssemblyDocument
        oDoc = ThisApplication.ActiveDocument
    
        GetInstancePropInfo oDoc.ComponentDefinition.Occurrences

    End If
End Sub

Sub GetInstancePropInfo(oOccus As ComponentOccurrences)

    Dim oOccu As ComponentOccurrence
    Dim oTempOccu As ComponentOccurrence
    
    ' The Instance Properties is accessiable via ComponentOccurrence only
    ' so below will get the ComponentOccurrence from ComponentOccurrenceProxy.
    For Each oTempOccu In oOccus
        If oTempOccu.Type = kComponentOccurrenceProxyObject Then
           oOccu = oTempOccu.NativeObject
             
        Else
            oOccu = oTempOccu
        End If
        
        Info.Logger(oOccu.Name)
        '  Instance Properties
        If oOccu.OccurrencePropertySetsEnabled Then
            Dim oProp As Inventor.Property
            For Each oProp In oOccu.OccurrencePropertySets(1)
            
                ' Print property info
                Info.Logger( "    " & oProp.DisplayName & ":" & oProp.Expression)
                'oProp.Expression = ""
                'oOccu.OccurrencePropertySetsEnabled = False
            Next
        End If
        
        GetInstancePropInfo oTempOccu.SubOccurrences
    Next
End Sub

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 5 of 8

johan.degreef
Advisor
Advisor

@A.Acheson Thanks! If it is simpler for the code, all instances can be deleted instead of blanked.

Inventor 2025, Vault Professional 2025, Autocad Plant 3D 2025
0 Likes
Message 6 of 8

A.Acheson
Mentor
Mentor
Accepted solution

Hi @johan.degreef 

 

I'm that case you should need just this line

oProp.Delete

 Place into this for loop here

For Each oProp In oOccu.OccurrencePropertySets(1)
            
     ' Print property info
     Info.Logger( "    " & oProp.DisplayName & ":" & oProp.Expression)
      oProp.Delete
 Next
If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 7 of 8

Sonny4
Participant
Participant

I try Google Gemini to make an ilogic code.

 

Sub Main()
' Check document type
If ThisApplication.ActiveDocument Is Nothing Or _
(ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject) Then
MsgBox ("Please open an assembly document!")
Exit Sub
End If

Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument

' Start recursive cleanup
GetInstancePropInfo(oDoc.ComponentDefinition.Occurrences)

Logger.Info("Done! Instance Properties have been cleared from all sub-components.")

' Optional: Save the document after the changes
' oDoc.Save()
End Sub

Sub GetInstancePropInfo(oOccus As ComponentOccurrences)

Dim oOccu As ComponentOccurrence
Dim oTempOccu As ComponentOccurrence

For Each oTempOccu In oOccus

' Handle Proxy objects
If oTempOccu.Type = kComponentOccurrenceProxyObject Then
oOccu = oTempOccu.NativeObject
Else
oOccu = oTempOccu
End If

' Check if instance properties are enabled
If oOccu.OccurrencePropertySetsEnabled Then

' NEW LINE: Sets OccurrencePropertySetsEnabled to False
' This deletes all existing instance properties.
oOccu.OccurrencePropertySetsEnabled = False

Logger.Info("Instance Properties deleted from: " & oOccu.Name)
End If

' Go into the next level (recursion)
GetInstancePropInfo(oTempOccu.SubOccurrences)
Next
End Sub

0 Likes
Message 8 of 8

WCrihfield
Mentor
Mentor

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

EESignature

(Not an Autodesk Employee)

0 Likes