Message 1 of 14

Not applicable
01-05-2018
08:34 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Please see the code that I have been working through below.
The goal is to sum up the total of a custom iProperty called MSRP.
I seem to have everything working well however the moment I suppress something I get an Unspecified Error.
Any help would be greatly appreciated,
Riese
SyntaxEditor Code Snippet
'- - - - - - - - - - - find or create custom iProperty - - - - - - - - - - 'Define the open document & make Library Files Editable (IV 2018) ThisApplication.[_LibraryDocumentModifiable] = True Dim openDoc As Document openDoc = ThisDoc.Document 'Look at all of the files referenced in the open document Dim docFile As Document For Each docFile In openDoc.AllReferencedDocuments Dim propertyName1 As String = "MSRP" 'define custom property collection oCustomPropertySet = docFile.PropertySets.Item("Inventor User Defined Properties") Try 'look for property oProp = oCustomPropertySet.Item(propertyName1) Catch ' Assume error means not found so create it oCustomPropertySet.Add(0, propertyName1) End Try Next '- - - - - - - - - - - sum the custom iProperty - - - - - - - - - - 'clear the custom property in the assembly iProperties.Value("Custom", "MSRP") = 0 'set a reference to the assembly component definintion. 'This assumes an assembly document is open. Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition 'Iterate through all of the occurrences Dim oOccurrence As ComponentOccurrence For Each oOccurrence In oAsmCompDef.Occurrences 'check for and skip virtual components '(in case a virtual component trips things up) If Not TypeOf oOccurrence.Definition Is VirtualComponentDefinition Then 'Property In the Assembly xNumber = iProperties.Value("Custom", "MSRP") 'property in the parts yNumber = iProperties.Value(oOccurrence.Name, "Custom", "MSRP") sumNumber = xNumber + yNumber 'set property values iProperties.Value("Custom", "MSRP") = Round (sumNumber,2) MSRP = sumNumber Else End If Next
Solved! Go to Solution.