Message 1 of 5
Rule to generate 'Custom Property' from Parameter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi a couple of weeks back I got a bit of help with some code because I'm rubbish at it mainly.
Basically I was going to generate a custom parameter called 'bought out type'.
I now want to add something that will take that result in this case 'Automation Tools' and create a custom property of the same name.
This was it:
Dim oUParams As UserParameters = ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters Dim oUParam As UserParameter Dim sName As String = "Bought_Out_Type" Dim oValues As New List(Of String) oValues.Add("Motion & Drives") oValues.Add("Pneumatics & Hydraulics") oValues.Add("Automation Tools") oValues.Add("Electrical Control & Motion") oValues.Add("Electrical Components") oValues.Add("Fixings") oValues.Add("Pipe & Fittings") oValues.Add("Mechanical Components") oValues.Add("Raw Material") Try oUParam = oUParams.Item(sName) MultiValue.SetList(sName, oValues.ToArray) Catch oUParam = oUParams.AddByValue(sName, "", UnitsTypeEnum.kTextUnits) MultiValue.SetList(sName, oValues.ToArray) End Try
The only other thing I'm struggling with, I wanted to generate a secondary 'Bought Out Code' which is a shorthand version of the first things we created. The only issue is I cannot get it to populate the parameter properly, it seems to get them mixed up!!
'Access User parameters of the active document Dim oMyParameters As UserParameters = ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters 'Create list of Parameter names of type: number Dim textParams As New List(Of String) textParams.AddRange({"Bought_Out_Code"}) 'Testing and Creation of User Parameters of type: text For Each item In textParams Try 'Check if User Parameter exists Param = oMyParameters.Item(item) Catch 'Parameter doesn't exist as a User Parameter Try 'attempt to create new parameter oMyParameters.AddByValue(item, "filler", UnitsTypeEnum.kTextUnits) '(Name, Value, Unit Type) Catch 'Parameter exists but not as a User Parameter MessageBox.Show("The Parameter: " & item & " exists as a parameter, but is not a user parameter.", "Creation Failure") End Try End Try Next If Parameter("Bought_Out_Type") = "Motion & drives" Then Parameter("Bought_Out_Code") = "MOTO" If Parameter("Bought_Out_Type") = "Pneumatics & Hydraulics" Then Parameter("Bought_Out_Code") = "PNHY" If Parameter("Bought_Out_Type") = "Automation Tools" Then Parameter("Bought_Out_Code") = "AUTO" If Parameter("Bought_Out_Type") = "Electrical Control & Motion" Then Parameter("Bought_Out_Code") = "ECON" If Parameter("Bought_Out_Type") = "Electrical Components" Then Parameter("Bought_Out_Code") = "EGEN" If Parameter("Bought_Out_Type") = "Fixings" Then Parameter("Bought_Out_Code") = "FIXS" If Parameter("Bought_Out_Type") = "Pipe & Fittings" Then Parameter("Bought_Out_Code") = "PIPE" If Parameter("Bought_Out_Type") = "Mechanical Components" Then Parameter("Bought_Out_Code") = "COMP" If Parameter("Bought_Out_Type") = "Raw Material" Then Parameter("Bought_Out_Code") = "MATE" iLogicForm.ShowGlobal("Bought Out Types")