Good afternoon!
I want to create a rule for creating and deleting a parameter.
Example:
If Type = 1, then
create parameter
If Type = 2, then
delete the parameter
after deleting a parameter, logic automatically assigns a value to the deleted parameter. see the following picture
How can I restore the assembly parameter so that after deleting the part parameter it is again equal to the assembly parameter???
Solved! Go to Solution.
Solved by WCrihfield. Go to Solution.
Solved by WCrihfield. Go to Solution.
Hi @k_ponomarenko. If that parameter you are deleting and recreating does not need to be a 'blue', unquoted parameter name, then change Line 17 (where it is being used the first time) so that it uses the 'Parameter(ParamName)' functionality, instead of the blue, unquoted parameter name functionality. That will eliminate that odd line of code being automatically added to the start of your code for that parameter with an odd value. Also, on Line 21, you have the wrong variable spelling ("ParaName" vs "ParamName"). I would have attempted to edit your code, but it is just an image, not selectable code, and some of the text in it appears to be in a language I am not familiar with.
Wesley Crihfield
(Not an Autodesk Employee)
Hello WCrihfield.
I fixed the code and it really helped, there is no error.
But after executing the parameter creation code, the parameter is created not as a multi-valued parameter, but as a single value that is specified in the List.Item(3) (see the code).
Simply put, a multi-valued parameter is not created.
I understand that the logic of the ArrayList code is broken.
I would appreciate it if you could help solve this problem.
Thank you for your help.
'MultiValue.SetList("Type_container", "Сontainer CIP solution", "Pressure damping capacity") 'Type_container = "Сontainer CIP solution" Dim oParams As Parameters Dim oAssemblyDoc As AssemblyDocument = ThisDoc.Document Dim oAssemblyCompDef As AssemblyComponentDefinition = oAssemblyDoc.ComponentDefinition Dim oComp As AssemblyComponentDefinition = oAssemblyDoc.ComponentDefinition oParams = oAssemblyCompDef.Parameters Dim oUPs As UserParameters = oComp.Parameters.UserParameters Dim oUP As UserParameter Dim ParamName As String = "Diameter_of_the_intake_pipe" Dim List As New ArrayList List.Add("80") List.Add("100") List.Add("125") List.Add("150") If Type_container = "Сontainer CIP solution" Then Try Test = oUPs.Item(ParamName).Value Catch oUP = oUPs.AddByExpression(ParamName, List.Item(3), UnitsTypeEnum.kMillimeterLengthUnits) Parameter("Сontainer CIP:1", "Диаметр_патрубка_забора") = Parameter(ParamName) End Try ElseIf Type_container = "Pressure damping capacity" Then Try oUP = oUPs.Item(ParamName) oUP.Delete Catch End Try Parameter("Сontainer CIP:1", "Diameter_of_the_intake_pipe") = False End If
Hi @k_ponomarenko. There are at least 3 different ways to assign multiple values to a Parameter (or UserParameter) type object that already exists, but it must already exist first. You can not created it with multiple values directly, in the same line of code that creates it. The 'MultiValue' object provides one of these ways to set multiple values to a parameter. There is also the 'iLogicVb.Automation.ParamMultiValues()' method. Then there is also the UserParameter.ExpressionList.SetExpressionList() method (not shown in example below). The second two offer more control, but possibly also more complexity. For example, the iLogicVb.Automation.ParamMultiValues method allows you to specify which 'Document' you want it to work within, while the 'MultiValue' object just attempts to figure out which document you want it to be working within.
I also noticed something else that does not seem right to me. You are wanting to set multiple, quoted, numerical values as the multiple values of the UserParameter named "Diameter_of_the_intake_pipe", but then it looks like you have a UserParameter by the same name within an assembly component that you are setting the value of when you delete this assembly level one. But you are setting the value of that one in the component to False (unquoted, so understood as a Boolean). If that parameter within the component has numerical, or text type units, then setting a Boolean as its value may not work. But if it has Boolean type units, that would be OK.
Parameter.UpdateAfterChange = True
MultiValue.UpdateAfterChange = True
'MultiValue.SetList("Type_container", "Сontainer CIP solution", "Pressure damping capacity")
'Type_container = "Сontainer CIP solution"
Dim oAssemblyDoc As AssemblyDocument = ThisDoc.Document
Dim oAssemblyCompDef As AssemblyComponentDefinition = oAssemblyDoc.ComponentDefinition
Dim oParams As Parameters = oAssemblyCompDef.Parameters
Dim oUPs As UserParameters = oParams.UserParameters
Dim oUP As UserParameter
Dim ParamName As String = "Diameter_of_the_intake_pipe"
Dim List As New ArrayList
List.Add("80")
List.Add("100")
List.Add("125")
List.Add("150")
If Type_container = "Сontainer CIP solution" Then
Try
oUP = oUPs.Item(ParamName)
Catch
oUP = oUPs.AddByExpression(ParamName, List.Item(3), UnitsTypeEnum.kMillimeterLengthUnits)
MultiValue.SetList(ParamName, List)
'can use previous line, or next line to set multiple values to existing parameter
'iLogicVb.Automation.ParamMultiValues(ThisDoc.Document, ParamName) = List
'oUP.ExpressionList.SetExpressionList(List) 'just another example
Parameter("Сontainer CIP:1", "Диаметр_патрубка_забора") = Parameter(ParamName)
'can use previous line, or next line to set value of existing parameter within component.
'iLogicVb.Automation.ParamValueInComponent(oAssemblyDoc, "Сontainer CIP:1", "Диаметр_патрубка_забора") = Parameter(ParamName)
End Try
ElseIf Type_container = "Pressure damping capacity" Then
Try
oUP = oUPs.Item(ParamName)
oUP.Delete
Catch
End Try
'<<< above, we are setting multiple String values to this parameter, but below, you are trying to set a Boolean to it >>>
'<<< this does not seem right. Maybe you meant to include quotation marks around False, to make it a String also? >>>
'<<< you can not change the 'Units' of a parameter by simply assigning a different type of value >>>
Parameter("Сontainer CIP:1", "Diameter_of_the_intake_pipe") = False
'or use next line instead - it allows you to specify a Document (the assembly document)
'iLogicVb.Automation.ParamValueInComponent(oAssemblyDoc, "Сontainer CIP:1", "Diameter_of_the_intake_pipe") = False
End If
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield
(Not an Autodesk Employee)
Hello, Crifield! Thank you very much for the recommendations. Thanks to your code, I managed to achieve the desired result. However, I had to break my head until I thought to add this rule to the initiator of events and everything worked as intended.
Can't find what you're looking for? Ask the community or share your knowledge.