Thank you so much, this works perfectly.
I have one final hurdle to overcome.
In my "local rule" version, i have separated the definitions as follows:
For Assembly documents i have:
Dim oCompDef As AssemblyComponentDefinition = ThisDoc.Document.ComponentDefinition
' Change BOM Structure based on multi value parameter
' Set BOM Structure iProperty for use with Vault
Select Case oCompDef.BOMStructure
Case "51970"
BOM_MStr = "Normal"
iProperties.Value("Custom", "BOM Structure") = "Normal"
Case "51971"
BOM_MStr = "Phantom"
iProperties.Value("Custom", "BOM Structure") = "Phantom"
Case "51972"
BOM_MStr = "Reference"
iProperties.Value("Custom", "BOM Structure") = "Reference"
Case "51973"
BOM_MStr = "Purchased"
iProperties.Value("Custom", "BOM Structure") = "Purchased"
Case "51974"
BOM_MStr = "Inseparable"
iProperties.Value("Custom", "BOM Structure") = "Inseparable"
End Select
and for part documents i have:
Dim oCompDef As PartComponentDefinition = ThisDoc.Document.ComponentDefinition
' Change BOM Structure based on multi value parameter
' Set BOM Structure iProperty for use with Vault
Select Case oCompDef.BOMStructure
Case "51970"
BOM_MStr = "Normal"
iProperties.Value("Custom", "BOM Structure") = "Normal"
Case "51971"
BOM_MStr = "Phantom"
iProperties.Value("Custom", "BOM Structure") = "Phantom"
Case "51972"
BOM_MStr = "Reference"
iProperties.Value("Custom", "BOM Structure") = "Reference"
Case "51973"
BOM_MStr = "Purchased"
iProperties.Value("Custom", "BOM Structure") = "Purchased"
Case "51974"
BOM_MStr = "Inseparable"
iProperties.Value("Custom", "BOM Structure") = "Inseparable"
End Select
If i am going to combine these two in an external rule, I think i need to check if the open document is a part or assembly, and then set oCompDef accordingly.
i tried a few things like:
Dim oDoc As Document = ThisApplication.ActiveDocument
'... Misc code here
If oDoc.DocumentType = kPartDocumentObject Then
Dim oCompDef As PartComponentDefinition
oCompDef = ThisDoc.Document.ComponentDefinition
Else If oDoc.DocumentType = kAssemblyDocumentObject Then
Dim oCompDef As AssemblyComponentDefinition
oCompDef = ThisDoc.Document.ComponentDefinition
however i get errors that oCompDef is not defined. So i suppose you cannot define a variable within an "if - then" block?
full ***Non-Working*** code here:
'Rule will set the Default BOM structure of the document to match the user parameter BOM_MStr
'If the parameter does not exist, it will be created.
Dim oDoc As Document = ThisApplication.ActiveDocument
Parameter.UpdateAfterChange = True
iLogicVb.UpdateWhenDone = True
ups = ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters
oParamName = "BOM_MStr"
If oDoc.DocumentType = kPartDocumentObject Then
Dim oCompDef As PartComponentDefinition
oCompDef = ThisDoc.Document.ComponentDefinition
Else If oDoc.DocumentType = kAssemblyDocumentObject Then
Dim oCompDef As AssemblyComponentDefinition
oCompDef = ThisDoc.Document.ComponentDefinition
End If
Try
'Checking to see if this Parameter already exists
t = Parameter.Param(oParamName)
Catch
'If this Parameter doesn't exist, create it
oParameter = ups.AddByValue(oParamName, "Normal", UnitsTypeEnum.kTextUnits)
MultiValue.SetList("BOM_MStr", "Normal", "Phantom", "Purchased", "Reference", "Inseperable")
End Try
' Change BOM Structure based on multi value parameter
Select Case BOM_MStr
Case "Normal"
oCompDef.BOMStructure = "51970"
Case "Phantom"
oCompDef.BOMStructure = "51971"
Case "Reference"
oCompDef.BOMStructure = "51972"
Case "Purchased"
oCompDef.BOMStructure = "51973"
Case "Inseparable"
oCompDef.BOMStructure = "51974"
End Select
'Output Parameters values from this rule to the Model. (Use this before Document Update)
RuleParametersOutput()
'Immediately update the current document.
InventorVb.DocumentUpdate()
the end goal is to get a form that collects all the iProperties we have to change constantly in to one place.
The button "Apply BOM Changes" will run a rule based on the code I referenced in the "accepted solution".
