Hi
I am migrating our old Inventor data to our new system. I will do an ilogic script for that.
I know how to add custom iProperties with iLogic but how can I remove them? Is it possible with iLogic? I would like to clean out all old iProperties that we don't need anymore.
Solved! Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Hi TimoVahteri8922,
You can run this snippet from the part file to remove ALL custom iProperties
'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
You can use this snippet if you have a custom property you do not want to delete you can check for it by name, and delete the rest:
'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 for a property name that you don't want to delete If Not oCustProp.name = "HelloWorld" Then 'delete the custom iProperty oCustProp.Delete Else End If Next
You can use this snippet to define a list of properties to keep, and then delete any not in that list:
'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
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Seems like I am looking for a forth kind of snippet
I need an iLogic-rule that deletes a list of custom properties. I want only the custom properties in my list to be deleted, all other properties I want to keep...
Is there a snippet for this?
I would be very greatful if someone could come up with this...
Hi tegstette,
This rule will delete all of the properties that you add to the list.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
'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
Perfect! Just what I needed!
Thank you for your quick and kind reply!
Hi, and thanks so much again for the code you provided me, Curtis
Worked just perfect in Inventor file by file!
But then I wanted to use this in a batch-job-program (code injector) and I get syntax error, and a message thet says 'oCustProp' is not delared... Now I am a little desperate because I cannot find a solution for it and I have stated a mayjor batch-cleaning-job...
Here is the code (that works perfectly in Invenor - but not in the batch-program)
'define list of custom properties to delete Dim MyArrayList As New ArrayList MyArrayList.add("TitleFormula") MyArrayList.add("Tolerance") MyArrayList.add("bh") '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
I attach the errors and warning.
Really hope someone can help me with a quick tip, so I hopefully can proceed our panned job...
Hi tegstette,
I think you just need to add this line:
Dim oCustProp As Inventor.Property
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
'define list of custom properties to delete Dim MyArrayList As New ArrayList MyArrayList.add("TitleFormula") MyArrayList.add("Tolerance") MyArrayList.add("bh") Dim oCustProp As Inventor.Property '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
'Rule 1: 'Delete user Parameter "Each" if exists Dim oDoc As PartDocument=ThisDoc.Document Dim param As Parameter Try param = oDoc.ComponentDefinition.Parameters.Item("Each") param.Delete Catch End Try '------------------------------------------- 'Rule 2: 'If file has AreaFP = SLETT , then delete property AreaFP Try If iProperties.Value("Custom", "AreaFP").ToUpper = "SLETT" Then 'define list of custom properties to delete Dim MyArrayList2 As New ArrayList MyArrayList2.add("AreaFP") '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 MyArrayList2.Contains(oCustProp.Name)Then 'delete the custom iProperty oCustProp.Delete End If Next End If Catch ex As Exception 'Here I can add a messagebox 'MsgBox(ex.ToString) End Try
Hi, and thank you for your answer
I finally found the problem... we have a lot of files with a user parameter (fx-paremeters) that is no longer in use, and this is called "Each" - and it is exported to create a custom property that is called "Each". Problem is that "Each" is also used in the code...:
For Each oCustProp In oCustomPropertySet
So I tried to make a rule to delete this user parameter and this works good if this is the only code in the rule, but when the rule continues to the delete customproperties, it seems like it still remembers Each as parameter. So my challenge now is how to "break" this memory... Here is the code.
Can you help me with at tip?
Hi Curtis
Is it possible to get your code to work at the assembly level? In other words delete custom iprops from the top level assembly, all subassemblies, and all parts.
I know about the traverse assembly method but can't figure out how to get things working.
Thanks,
Bryan
Hi @mcloughlin_b,
Here is a quick iLogic rule that deletes every custom iProperty in every occurrence ( parts and subassemblies) in the assembly. I only did minimal testing, so post back if it does not work.
Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition 'Iterate through all of the occurrences Dim oOccurrence As ComponentOccurrence For Each oOccurrence In oAsmCompDef.Occurrences.AllReferencedOccurrences(oAsmCompDef) 'define custom property collection oCustomPropertySet = oOccurrence.Definition.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 Next
HI Curtis
That works great but can it be tweaked to only delete custom props from an arraylist?
Thanks for your time.
Bryan
@mcloughlin_b wrote:
That works great but can it be tweaked to only delete custom props from an arraylist?
Hi mcloughlin_b,
Sure, see the first example below, note I've added the converse of this as well, just in case it's helpful to someone in the future.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Delete only custom iProps that ARE in the list:
'define list of custom properties Dim MyArrayList As New ArrayList MyArrayList.add("Hello World 001") MyArrayList.add("Hello World 002") MyArrayList.add("Hello World 003") Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition 'Iterate through all of the occurrences Dim oOccurrence As ComponentOccurrence For Each oOccurrence In oAsmCompDef.Occurrences.AllReferencedOccurrences(oAsmCompDef) 'define custom property collection oCustomPropertySet = oOccurrence.Definition.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 If MyArrayList.Contains(oCustProp.Name)Then 'delete the custom iProperty oCustProp.Delete End If Next Next
Delete only custom iProps that are NOT in the list:
'define list of custom properties Dim MyArrayList As New ArrayList MyArrayList.add("Hello World 001") MyArrayList.add("Hello World 002") MyArrayList.add("Hello World 003") Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition 'Iterate through all of the occurrences Dim oOccurrence As ComponentOccurrence For Each oOccurrence In oAsmCompDef.Occurrences.AllReferencedOccurrences(oAsmCompDef) 'define custom property collection oCustomPropertySet = oOccurrence.Definition.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 If MyArrayList.Contains(oCustProp.Name)Then 'skip it Else 'delete the custom iProperty oCustProp.Delete End If Next Next
@Curtis_Waguespack Hi Curtis, thanks for the last bit of code. I have tried to tweak it a bit to create two different array lists so that I can perform different actions on each list.
'define list of custom properties Dim MyArrayList As New ArrayList MyArrayList.add("STEEL) MyArrayList.add("STEEL") Dim MyArrayList1 As New ArrayList MyArrayList1.add("PAINT") MyArrayList1.add("PAINT") Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition 'Iterate through all of the occurrences Dim oOccurrence As ComponentOccurrence For Each oOccurrence In oAsmCompDef.Occurrences.AllReferencedOccurrences(oAsmCompDef) 'define custom property collection oCustomPropertySet = oOccurrence.Definition.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 If MyArrayList.Contains(oCustProp.Name) Then MessageBox.Show(oOccurrence.ReferencedFileDescriptor.FullFileName & " contains STEEL operations, which will be deleted.", "STEEL Operations") 'delete the custom iProperty oCustProp.Delete
MsgBox(oCustProp.Name & " was deleted") 'Going to add a line here to add a replacement iProp End If 'check property name against the list If MyArrayList1.Contains(oCustProp.Name) Then MessageBox.Show(oOccurrence.ReferencedFileDescriptor.FullFileName & " contains PAINT operations, which will be deleted.", "PAINT Operations") 'delete the custom iProperty oCustProp.Delete
MsgBox(oCustProp.Name & " was deleted") 'Going to add a line here to add a replacement iProp End If Next Next
I ran the code in a simple assembly where the sub part had both iProps present, it notifies me with the first msg box and deletes the iProps but I get this error before the second msg box:
Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
Any ideas how I can fix?
Hi c.rp.Henderson,
As written, I don't see a need for the 2 lists, so I think you can use one list and an 'Else If' to resolve this as in this 1st version:
'define list of custom properties Dim MyArrayList As New ArrayList MyArrayList.add("STEEL") MyArrayList.add("PAINT") Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition 'Iterate through all of the occurrences Dim oOccurrence As ComponentOccurrence For Each oOccurrence In oAsmCompDef.Occurrences.AllReferencedOccurrences(oAsmCompDef) 'define custom property collection oCustomPropertySet = oOccurrence.Definition.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 If MyArrayList.Contains(oCustProp.Name) Then MessageBox.Show(oOccurrence.ReferencedFileDescriptor.FullFileName & " contains STEEL operations, which will be deleted.", "STEEL Operations") 'delete the custom iProperty oCustProp.Delete MsgBox(oCustProp.Name & " was deleted") 'Going to add a line here to add a replacement iProp 'check property name against the list Else If MyArrayList.Contains(oCustProp.Name) Then MessageBox.Show(oOccurrence.ReferencedFileDescriptor.FullFileName & " contains PAINT operations, which will be deleted.", "PAINT Operations") 'delete the custom iProperty oCustProp.Delete MsgBox(oCustProp.Name & " was deleted") 'Going to add a line here to add a replacement iProp End If Next Next
If the 2 lists are required, then you can add a 'Continue For' line to move on once the first If/Then has executed. I think the error you're getting is because the property is deleted, and then 2nd If/Then condition is looking at that property still. The 'Continue For' should resolve this.
'define list of custom properties Dim MyArrayList As New ArrayList MyArrayList.add("STEEL") 'define list of custom properties Dim MyArrayList1 As New ArrayList MyArrayList1.add("PAINT") Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition 'Iterate through all of the occurrences Dim oOccurrence As ComponentOccurrence For Each oOccurrence In oAsmCompDef.Occurrences.AllReferencedOccurrences(oAsmCompDef) 'define custom property collection oCustomPropertySet = oOccurrence.Definition.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 If MyArrayList.Contains(oCustProp.Name) Then MessageBox.Show(oOccurrence.ReferencedFileDescriptor.FullFileName & " contains STEEL operations, which will be deleted.", "STEEL Operations") 'delete the custom iProperty oCustProp.Delete MsgBox(oCustProp.Name & " was deleted") 'Going to add a line here to add a replacement iProp Continue For End If 'check property name against the list If MyArrayList1.Contains(oCustProp.Name) Then MessageBox.Show(oOccurrence.ReferencedFileDescriptor.FullFileName & " contains PAINT operations, which will be deleted.", "PAINT Operations") 'delete the custom iProperty oCustProp.Delete MsgBox(oCustProp.Name & " was deleted") 'Going to add a line here to add a replacement iProp End If Next Next
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Hi there,
Wonder if you could help me on a similar matter. I've used a custom task in task scheduler to create a custom property across our library in the vault. But now I want to delete a certain property (category) from the custom properties, again using an external rule via the custom task in task scheduler.
Any chance you know how to create a ilogic rule to do this?
Thanks
Martin
Hello Curtis,
I tried the version with keeping the iProps in the list.
Unfortunately I get the following error.
(Ausnahme von HRESULT: 0x80004005 (E_FAIL))
Do you have any idea what this could be?
Best regards
i Forget
Dim MyArrayList As New ArrayList MyArrayList.Add("AENDERUNGS_DATUM") MyArrayList.Add("AENDERUNG_NAME") MyArrayList.Add("B") MyArrayList.Add("D") MyArrayList.Add("L") MyArrayList.Add("G_L") MyArrayList.Add("H1") MyArrayList.Add("H2") MyArrayList.Add("DATUM_GEZ") MyArrayList.Add("PTC_WM_ITERATION") MyArrayList.Add("PTC_WM_LIFECYCLE") MyArrayList.Add("PTC_WM_LIFECYCLE_STATE") MyArrayList.Add("PTC_WM_NAME") MyArrayList.Add("PTC_WM_NUMBER") MyArrayList.Add("PTC_WM_ORGANIZATION_ID") MyArrayList.Add("PTC_WM_REVISION") MyArrayList.Add("TK_AENDERUNGSNUMMER") MyArrayList.Add("TK_ARTIKELNUMMER") MyArrayList.Add("TK_DIN_NR") MyArrayList.Add("TK_ERSATZ_FÜR") MyArrayList.Add("TK_GEPRUEFT_AM") MyArrayList.Add("TK_GEPRUEFT_DURCH") MyArrayList.Add("TK_TITEL") MyArrayList.Add("TK_TITEL_EN") MyArrayList.Add("ZEICHNUNGSNR") Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition Dim oOccurrence As ComponentOccurrence For Each oOccurrence In oAsmCompDef.Occurrences.AllReferencedOccurrences(oAsmCompDef) oCustomPropertySet = oOccurrence.Definition.Document.PropertySets.Item("Inventor User Defined Properties") For Each oCustProp In oCustomPropertySet If MyArrayList.Contains(oCustProp.name) Then 'skip it Else oCustProp.Delete End If Next Next
Can't find what you're looking for? Ask the community or share your knowledge.