I'm trying to write a rule to retrieve a Custom iProperty value (text) from two parts in an assembly ("side.ipt" and "back.ipt") and store that information into that assembly's User Parameters (Material_Side and Material_Back). This is the code that I have so far.
oOccurrences = ThisDoc.Document.ComponentDefinition.Occurrences 'Get the set of occurrences in this assembly document
For Each oComp As ComponentOccurrence In oOccurrences 'Cycle through each component in the set
oCompName = oComp.Name 'Get the browser name of the component
Try
oCompMaterial = oComp.OccurrencePropertySets.Item("Inventor User Defined Properties").Item("Mat_Name").Value 'Get iProperty value from custom field named "Mat_Name"
Catch
oCompMaterial = "Error"
End Try
If InStr(oCompName, "side") > 0 Then 'Check if the desired bit of text is in the component's name
Material_Side = FormatAsFraction(NomThick_Side) & " " & oCompMaterial 'side material
Else If InStr(oCompName, "back") > 0 Then 'Check if the desired bit of text is in the component's name
Material_Back = FormatAsFraction(NomThick_Back) & " " & oCompMaterial 'back material
End If
Next
As best I can tell the issue is on line 7 as the oCompMaterial value that is returned to me is the catch value "Error" and not the iProperty value of the part. Any suggestions would be appreciated.
Thanks.
Solved! Go to Solution.
Solved by lantzwoodworking. Go to Solution.
I figured it out. Code posted below in case it helps anyone else later. Thanks.
oOccurrences = ThisDoc.Document.ComponentDefinition.Occurrences 'Get the set of occurrences in this assembly document
For Each oComp As ComponentOccurrence In oOccurrences 'Cycle through each component in the set
oCompName = oComp.Name 'Get the browser name of the component
oCompMaterial = iProperties.Value(oCompName, "Custom", "Mat_Name")
If InStr(oCompName, "side") > 0 Then 'Check if the desired bit of text is in the component's name
Material_Side = FormatAsFraction(NomThick_Side) & " " & oCompMaterial 'side material
Else If InStr(oCompName, "back") > 0 Then 'Check if the desired bit of text is in the component's name
Material_Back = FormatAsFraction(NomThick_Back) & " " & oCompMaterial 'back material
End If
Next
Can't find what you're looking for? Ask the community or share your knowledge.