Message 1 of 3
Sum of Custom iProperties as string
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi out there
Im trying to be able to attach different materials to parts in the same assembly - and the get the mass for each mix of materials.
Im new to iLogic - and have as a start tried to pick up some pieces published by others.
Now its actually working - but I want the sum of the iProperties to be as text (String) - and the way it works now I get the result in numbers (next step is adding the mass properties to an iAssembly factory - and I assume its like the iPart factory - best as String)
This is what I have done until now - I bet it can be done in fewer lines - but I try to understand what I'm doing..
'Find or create custom iProperty 'Define the open document 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 = "MassA" Dim propertyName2 As String = "MassB" Dim propertyName3 As String = "MassC" Dim propertyName4 As String = "MassD" Dim propertyName5 As String = "MassE" '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 Try 'look for property oProp = oCustomPropertySet.Item(propertyName2) Catch ' Assume error means not found so create it oCustomPropertySet.Add(0, propertyName2) End Try Try 'look for property oProp = oCustomPropertySet.Item(propertyName3) Catch ' Assume error means not found so create it oCustomPropertySet.Add(0, propertyName3) End Try Try 'look for property oProp = oCustomPropertySet.Item(propertyName4) Catch ' Assume error means not found so create it oCustomPropertySet.Add(0, propertyName4) End Try Try 'look for property oProp = oCustomPropertySet.Item(propertyName5) Catch ' Assume error means not found so create it oCustomPropertySet.Add(0, propertyName5) End Try Next 'Sum the custom iProperty '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 'clear the custom property in the assembly iProperties.Value("Custom", "MassA") = 0 For Each oOccurrence In oAsmCompDef.Occurrences xNumber = iProperties.Value("Custom", "MassA") 'custom property in the parts yNumber = iProperties.Value(oOccurrence.Name, "Custom", "MassA") sumNumber = xNumber + yNumber 'set custom property values iProperties.Value("Custom", "MassA") = Round (sumNumber,3) Next iProperties.Value("Custom", "MassB") = 0 For Each oOccurrence In oAsmCompDef.Occurrences xNumber = iProperties.Value("Custom", "MassB") 'custom property in the parts yNumber = iProperties.Value(oOccurrence.Name, "Custom", "MassB") sumNumber = xNumber + yNumber 'set custom property values iProperties.Value("Custom", "MassB") = Round (sumNumber,3) Next iProperties.Value("Custom", "MassC") = 0 For Each oOccurrence In oAsmCompDef.Occurrences xNumber = iProperties.Value("Custom", "MassC") 'custom property in the parts yNumber = iProperties.Value(oOccurrence.Name, "Custom", "MassC") sumNumber = xNumber + yNumber 'set custom property values iProperties.Value("Custom", "MassC") = Round (sumNumber,3) Next iProperties.Value("Custom", "MassD") = 0 For Each oOccurrence In oAsmCompDef.Occurrences xNumber = iProperties.Value("Custom", "MassD") 'custom property in the parts yNumber = iProperties.Value(oOccurrence.Name, "Custom", "MassD") sumNumber = xNumber + yNumber 'set custom property values iProperties.Value("Custom", "MassD") = Round (sumNumber,3) Next iProperties.Value("Custom", "MassE") = 0 For Each oOccurrence In oAsmCompDef.Occurrences xNumber = iProperties.Value("Custom", "MassE") 'custom property in the parts yNumber = iProperties.Value(oOccurrence.Name, "Custom", "MassE") sumNumber = xNumber + yNumber 'set custom property values iProperties.Value("Custom", "MassE") = Round (sumNumber,3) Next
Can anyone tell me how to change the results to Strings
Mvh Ebbe FN