Tuesday, March 11, 2014

iLogic - Delete Custom iProperties

Issue:
You have some custom iProperties in your file that you want to remove. Because you have a lot of files that contain these custom iProperties, you find yourself doing this quite often. You'd like an iLogic rule that will help with this when you encounter these custom iProperties.


Solution:
Here are three rule variations to help with this.

Variation 1
Delete only the custom iProperties found in the list.



'------- start of ilogic ------

'define list of custom properties to delete
Dim MyArrayList As New ArrayList
MyArrayList.add("Hello World 001")
MyArrayList.add("Hello World 002")
MyArrayList.add("Hello World 003")

'define custom property collection
oCustomPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")
'look at each property in the collection
For Each oCustProp in oCustomPropertySet
'check property name against the list you want to delete
If MyArrayList.Contains(oCustProp.name)Then
'delete the custom iProperty
oCustProp.Delete
Else
'skip it
End If
Next

'------- end of ilogic ------


Variation 2
Delete only the custom iProperties NOT found in the list.


'------- start of ilogic ------

'define list of custom properties to keep
Dim MyArrayList As New ArrayList
MyArrayList.add("Hello World 001")
MyArrayList.add("Hello World 002")
MyArrayList.add("Hello World 003")

'define custom property collection
oCustomPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")
'look at each property in the collection
For Each oCustProp in oCustomPropertySet
'check property name against the list you don't want to delete
If MyArrayList.Contains(oCustProp.name)Then
'skip it
Else
'delete the custom iProperty
oCustProp.Delete
End If
Next

'------- end of ilogic ------


Variation 3
Delete All custom iProperties found in the part.


'------- start of ilogic ------

'define custom property collection
oCustomPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")
'look at each property in the collection
For Each oCustProp in oCustomPropertySet
'delete the custom iProperty
oCustProp.Delete
Next

'------- end of ilogic ------