This came up recently with a customer where they’d like to see all of the different volumes at one time for an iPart’s members. This could be used for mass or other property. The only limitation is your creativity with it.
The scope is: we want to get the volumes for all the elaborated members of an iPart factory at one time and this rule does that when we add a custom “Volume” parameter to the iPart table, trigger the rule to fire on any parameter change and edit the table via a spreadsheet. Problem: Cubic inches (or any other distance type) doesn’t have a predefined enum. So we need to use a workaround and build up a string that defines the desired units. There is the issue of the unit type changing from document to document so we won’t want to hard-code the unit value but instead be able to set it dynamically. We also want to make sure that, if the parameter exists, we’re not duplicating it and it’s correct for the current member. Here’s how the code looks:
'Dimension a variable for user paramaters
oMyParameter= _
ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters
'test to see if the parameter is already there and, if so, that it matches the correct
'volume of the member using the embedded if/then/end if block
Dim param As Parameter
On Error Resume Next
param = oMyParameter.Item("Volume")
If Parameter("Volume") <> iProperties.Volume Then
Parameter("Volume") = iProperties.Volume
End If
On Error Goto 0
'If it doesn't exist, create it so that we can add it to the table. We have to concatenate
'Units of measure as a string b/c there is no enum for ^3 inches but no problem, it still
'can be had and dynamic the way we'll set it up
If param Is Nothing Then
'Get the document's units of meausure, comcatenate that with a volumetric string of ^3
'in order to show the units as volume units
Dim uom As UnitsOfMeasure = ThisApplication.ActiveDocument.UnitsOfMeasure
Dim volUnits As String = uom.GetStringFromType(uom.LengthUnits) & "^3"
'Set a parameter equal to the current properties volume adding the units of
'measure in volume units from above
Dim Vol = iProperties.Volume
oParameter=oMyParameter.AddByExpression("Volume", Vol, volUnits)
End If
iLogicVb.UpdateWhenDone = True
‘Then, once this rule is run, it’s just a matter of adding the new “Volume” user
‘parameter column (from other) we’ve created to our iPart table – just once.
I’m sure there are probably other ways to do it but it really works out pretty well with very little actual code. As a note, when you change members, you’ll get a dialog that you should answer yes to, that states the values in the active row do not match. It is asking you if you'd like to update the table with the new value before continuing. Answering yes will reflect the volume for the new member's cell value in the table in both the iPart table in Inventor as well as in the Excel spreadsheet.
Once they've all been activated and the dialogs have been answered "Yes", your values will be reflected in the table/spreadsheet.
-Daren
(1st line of code edited with underscore to fit in the provided space)