Hello All,
I want to clean up some custom properties with a externe ilogic rule. I want run it in a iam and than delete some custom properties in the parts. So if they are there in the part, than delete them. But I don't get the code right working. I want delete the custom property "R8_item_nummer"
Here I have some code:
' set a reference to the assembly component definintion.
' This assumes an assembly document is open.
Dim oCompDef As AssemblyComponentDefinition
oCompDef = ThisApplication.ActiveDocument.ComponentDefinition
oCompDef.RepresentationsManager.LevelOfDetailRepresentations("Master").Activate
InventorVb.DocumentUpdate(True)
Try
'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oCompDef.Occurrences
' Set Reference to Part Document
Dim invPart As Document
invPart = oOccurrence.Definition.Document
' Set Reference to Part's iProperies
Dim oPropertySets As PropertySets
oPropertySets = invPart.PropertySets
Dim oValue1 As String
Dim oValue2 As String
Try
oValue1 = iProperties.Value(oOccurrence.Name, "Custom", "R8_omschrijving")
iProperties.Value(oOccurrence.Name, "Project", "Description")=oValue1
Catch
End Try
Try
oValue2 = iProperties.Value(oOccurrence.Name, "Custom", "R8_item_nummer")
iProperties.Value(oOccurrence.Name, "Custom", "R8_GRND_ITEM_NUMMER")=oValue2
If oOccurrence.Name = "R8_item_nummer" Then
'delete the custom iProperty
Else
End If
Catch
End Try
Next
Catch
End Try
Regards,
Jorn
Solved! Go to Solution.
Solved by Jon.Dean. Go to Solution.
Hello,
The code works, but:
If oOccurrence.Name = "R8_item_nummer" Then
'delete the custom iProperty
Here I mis something. text here must be that the iProperty must be removed in the part.
Else
End If
Here is one idea:
'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
Check also the following thread.
Jon.
Thank you for your answer.
This is a code when you want to run it in a part.
But I want to run it in a assembly, and then it delete the properties in the parts.
If you do it from the Assembly, then you would need to know the name of every part in the assembly or generate code to make a set.
Then you could work through each part in turn, deleting the property.
It is starting to sound more like VB task.
Jon.
Hello Jorn,
Put the following code into an external rule and it should do the job for you:
Option Explicit ' Rule to delete custom properties from all parts present in the Assembly Dim oAssyDoc As Document = TryCast(ThisApplication.ActiveDocument, AssemblyDocument) Dim oCompDef As ComponentDefinition Dim oOccurDoc As Document Try If (oAssyDoc IsNot Nothing) Then ' Set the component definition oCompDef = oAssyDoc.ComponentDefinition ' Loop thru all the occurences For Each oOccurrence As ComponentOccurrence In oCompDef.Occurrences oOccurDoc = oOccurrence.Definition.Document If (oOccurDoc IsNot Nothing) Then For Each oProp As Object In _
oOccurDoc.PropertySets.Item("Inventor User Defined Properties") ' Check for the right name to delete If (oProp.Name = "Your Custom Property Name") Then oProp.Delete End If Next oProp End If Next oOccurrence Else MsgBox("This rule only works from an Assembly Document", _
vbOKOnly, "DeleteCustomProperties") End If Catch ex As Exception Dim sMsg As String = "Error info: " Dim Style As Integer = vbOKOnly Dim sTitle As String = "Error: DeleteCustomProperties" MsgBox(sMsg & vbNewLine & ex.Message, Style, sTitle) End Try
If you have more than one Property to delete use the following code:
Option Explicit ' Rule to delete custom properties from all parts present in the Assembly Dim oAssyDoc As Document = TryCast(ThisApplication.ActiveDocument, AssemblyDocument) Dim oCompDef As ComponentDefinition Dim oOccurDoc As Document Try If (oAssyDoc IsNot Nothing) Then ' Set the component definition oCompDef = oAssyDoc.ComponentDefinition ' Loop thru all the occurences For Each oOccurrence As ComponentOccurrence In oCompDef.Occurrences oOccurDoc = oOccurrence.Definition.Document If (oOccurDoc IsNot Nothing) Then For Each oProp As Object In _
oOccurDoc.PropertySets.Item("Inventor User Defined Properties") ' Check for the right name to delete Select Case oProp.Name Case "Your first Custom Property Name", _
"Your second Custom Property Name" oProp.Delete End Select Next oProp End If Next oOccurrence Else MsgBox("This rule only works from an Assembly Document", _
vbOKOnly, "DeleteCustomProperties") End If Catch ex As Exception Dim sMsg As String = "Error info: " Dim Style As Integer = vbOKOnly Dim sTitle As String = "Error: DeleteCustomProperties" MsgBox(sMsg & vbNewLine & ex.Message, Style, sTitle) End Try
Regards,
Eelco
Hi,
I need to delete all iProperties starting with the name "Color". I don't know what I'm doing wrong.
rule Delete_Select_iProperty
'define custom property collection oCustomPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties") 'look at each property in the collection Dim suffix As String = oCustProp i= "Color" 'where i is the first letter to start with' For Each oCustProp In oCustomPropertySet 'check for a property name that you don't want to delete If oCustProp.name = i & suffix Then 'delete the custom iProperty i = Chr(Asc(i)+1) oCustProp.Delete Else End If Next