Sum of Custom iProperties as string

Sum of Custom iProperties as string

EbbeFN
Advocate Advocate
597 Views
2 Replies
Message 1 of 3

Sum of Custom iProperties as string

EbbeFN
Advocate
Advocate

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

0 Likes
598 Views
2 Replies
Replies (2)
Message 2 of 3

J-Camper
Advisor
Advisor

Hello @EbbeFN ,

 

Your request was pretty simple, you can use the ".ToString" method on your rounded Double to convert it into text.   I am attaching this simple fix as a .txt file [slightly_modded].

 

I also condensed the code into something that is easier to read and modify later, this is also attached as a .txt file [significantly_modded].

 

Let me know if you have any questions.

0 Likes
Message 3 of 3

EbbeFN
Advocate
Advocate

This is perfect - both solutions runs as I had wished (and the shortened version makes sense). Thanks a lot - have a nice day.

0 Likes