Setting a Variable with multiple possible values

Setting a Variable with multiple possible values

JamesMeBoi
Enthusiast Enthusiast
646 Views
6 Replies
Message 1 of 7

Setting a Variable with multiple possible values

JamesMeBoi
Enthusiast
Enthusiast

I want to be able to set a value to a variable XXXX in 4 instances, activating which one in a Case Select statement. Essentially if 1 out of 4 of the cases is true it will assign that number as the variable to be used later in the code. The hope being that only one of the 4 cases would activate allowing my code to be much simpler. I Will post my example code below. I just need to know if it is possible to do this? Thank you.

 

Select Case True
   Case StackLightOptions = "NO STACK LIGHT" AndAlso HMIOptions = "BR HMI"
	   Components.Delete("A10000932:1")
	   Components.Delete("A10000117:1")
	   Components.Delete("A10000929:1")
	   XXXX = ("A10000817:1")

   Case StackLightOptions = "STACK LIGHT" AndAlso HMIOptions = "BR HMI"
	   Components.Delete("A10000817:1")
	   Components.Delete("A10000117:1")
	   Components.Delete("A10000929:1")
	   XXXX = ("A10000932:1")
	   
   Case StackLightOptions = "NO STACK LIGHT" AndAlso HMIOptions = "STANDARD AB HMI"
	   Components.Delete("A10000932:1")
	   Components.Delete("A10000817:1")
	   Components.Delete("A10000117:1")
	   XXXX = ("A10000929:1")
	   
   Case StackLightOptions = "STACK LIGHT" AndAlso HMIOptions = "STANDARD AB HMI"
	   Components.Delete("A10000932:1")
	   Components.Delete("A10000817:1")
	   Components.Delete("A10000929:1")
	   XXXX = ("A10000117:1")

End Select


If HMILocation = "CENTER" Then
	Components.Delete("A10001125:1")
	Components.Delete("A10001125:2")
	Constraints.AddMate("Mate1", "A10001124:1", "WorkAxis1", "XXXX", "WorkAxis1",
                    offset := 0.0, e1InferredType := InferredTypeEnum.kNoInference, e2InferredType := InferredTypeEnum.kNoInference,
                    solutionType := MateConstraintSolutionTypeEnum.kNoSolutionType,
                    biasPoint1 := Nothing, biasPoint2 := Nothing)
	Constraints.AddMate("Mate2", "A10001124:1", "WorkAxis2", "XXXX", "WorkAxis2",
                    offset := 0.0, e1InferredType := InferredTypeEnum.kNoInference, e2InferredType := InferredTypeEnum.kNoInference,
                    solutionType := MateConstraintSolutionTypeEnum.kNoSolutionType,
                    biasPoint1 := Nothing, biasPoint2 := Nothing)

End If


If HMILocation = "LEFT" Then
	Components.Delete("A10001124:1")
	Components.Delete("A10001125:2")
	Constraints.AddMate("Mate1", "A10001125:1", "WorkAxis1", "XXXX", "WorkAxis1",
                    offset := 0.0, e1InferredType := InferredTypeEnum.kNoInference, e2InferredType := InferredTypeEnum.kNoInference,
                    solutionType := MateConstraintSolutionTypeEnum.kNoSolutionType,
                    biasPoint1 := Nothing, biasPoint2 := Nothing)
	Constraints.AddMate("Mate2", "A10001125:1", "WorkAxis2", "XXXX", "WorkAxis2",
                    offset := 0.0, e1InferredType := InferredTypeEnum.kNoInference, e2InferredType := InferredTypeEnum.kNoInference,
                    solutionType := MateConstraintSolutionTypeEnum.kNoSolutionType,
                    biasPoint1 := Nothing, biasPoint2 := Nothing)

End If


If HMILocation = "RIGHT" Then
	Components.Delete("A10001124:1")
	Components.Delete("A10001125:1")
	Constraints.AddMate("Mate1", "A10001125:2", "WorkAxis1", "XXXX", "WorkAxis1",
                    offset := 0.0, e1InferredType := InferredTypeEnum.kNoInference, e2InferredType := InferredTypeEnum.kNoInference,
                    solutionType := MateConstraintSolutionTypeEnum.kNoSolutionType,
                    biasPoint1 := Nothing, biasPoint2 := Nothing)
	Constraints.AddMate("Mate2", "A10001125:2", "WorkAxis2", "XXXX", "WorkAxis2",
                    offset := 0.0, e1InferredType := InferredTypeEnum.kNoInference, e2InferredType := InferredTypeEnum.kNoInference,
                    solutionType := MateConstraintSolutionTypeEnum.kNoSolutionType,
                    biasPoint1 := Nothing, biasPoint2 := Nothing)

End If

 

0 Likes
Accepted solutions (2)
647 Views
6 Replies
Replies (6)
Message 2 of 7

theo.bot
Collaborator
Collaborator

This should work:

 

replace: XXXX = ("A10000817:1") for XXXX = "A10000817:1" in each case of your selection

 

then in your constrains codes don't use "XXXX", but remove the Quotes: XXXX. Like this:

Constraints.AddMate("Mate1", "A10001125:2", "WorkAxis1", XXXX, "WorkAxis1",
                    offset := 0.0, e1InferredType := InferredTypeEnum.kNoInference, e2InferredType := InferredTypeEnum.kNoInference,
                    solutionType := MateConstraintSolutionTypeEnum.kNoSolutionType,
                    biasPoint1 := Nothing, biasPoint2 := Nothing)

 

Message 3 of 7

JamesMeBoi
Enthusiast
Enthusiast

While this does improve the codes ability to run it still does not allow the variable inside the Constraint to work. This is the error that it kicks up. I believe what I am trying to do of making using a Case Select to assign a Assembly number to a variable as well as not assigning the other numbers that weren't selected in the Case Select statement. Then to use that variable in the Constraint function. Below is the pop up window I get after activating the form.

 

 

*******

Error in rule: NEW ATTEMPT, in document: Template Kanga Practice.iam

Unable to cast object of type 'System.String' to type 'Autodesk.iLogic.Types.ComponentArgument'

*******

Message 4 of 7

theo.bot
Collaborator
Collaborator
Accepted solution

You're right 🙂

 

we need to declare the variable as Component Argument, then it will work:

here is a sample that i used for testing.

Dim Part1 As ComponentArgument
Part1= "black:1"
Dim Part2 As ComponentArgument 
Part2 = "blue:1" 

Constraints.AddFlush("Flush1", Part1, "XY Plane", Part2, "XY Plane",
                     offset := 0.0, biasPoint1 := Nothing, biasPoint2 := Nothing)

 

Message 5 of 7

JamesMeBoi
Enthusiast
Enthusiast

I think we are getting closer, We have a new error with this presenting itself

 

*****

Rule Compile Errors in NEW ATTEMPT, in Template Kanga Practice.iam

Error on Line 108 : Variable 'Part2' hides a variable in an enclosing block.
Error on Line 115 : Variable 'Part2' hides a variable in an enclosing block.
Error on Line 122 : Variable 'Part2' hides a variable in an enclosing block.
Error on Line 129 : Variable 'Part2' hides a variable in an enclosing block

*****

 

The lines numbers may look a little off but each error but each is highlighted red. It appears that the variables are still confused since all 4 values are being assigned as one. Do you know of an option that only assigns the variable once the program has been run? It appears that the ILogic is determining what variable is what before even running the program.

 

 

Select Case True
   Case StackLightOptions = "NO STACK LIGHT" AndAlso HMIOptions = "BR HMI"
	   Components.Delete("A10000932:1")
	   Components.Delete("A10000117:1")
	   Components.Delete("A10000929:1")
	   Dim Part2 As ComponentArgument 
	   Part2 = "A10000817:1"

   Case StackLightOptions = "STACK LIGHT" AndAlso HMIOptions = "BR HMI"
	   Components.Delete("A10000817:1")
	   Components.Delete("A10000117:1")
	   Components.Delete("A10000929:1")
	   Dim Part2 As ComponentArgument 
	   Part2 = "A10000932:1"
	   
   Case StackLightOptions = "NO STACK LIGHT" AndAlso HMIOptions = "STANDARD AB HMI"
	   Components.Delete("A10000932:1")
	   Components.Delete("A10000817:1")
	   Components.Delete("A10000117:1")
	   Dim Part2 As ComponentArgument 
	   Part2 = "A10000929:1"
	   
   Case StackLightOptions = "STACK LIGHT" AndAlso HMIOptions = "STANDARD AB HMI"
	   Components.Delete("A10000932:1")
	   Components.Delete("A10000817:1")
	   Components.Delete("A10000929:1")
	   Dim Part2 As ComponentArgument 
	   Part2 = "A10000117:1"

End Select


If HMILocation = "CENTER" Then
	Components.Delete("A10001125:1")
	Components.Delete("A10001125:2")
	Constraints.AddMate("Mate1", "A10001124:1", "WorkAxis1", Part2, "WorkAxis1",
                    offset := 0.0, e1InferredType := InferredTypeEnum.kNoInference, e2InferredType := InferredTypeEnum.kNoInference,
                    solutionType := MateConstraintSolutionTypeEnum.kNoSolutionType,
                    biasPoint1 := Nothing, biasPoint2 := Nothing)
	Constraints.AddMate("Mate2", "A10001124:1", "WorkAxis2", Part2, "WorkAxis2",
                    offset := 0.0, e1InferredType := InferredTypeEnum.kNoInference, e2InferredType := InferredTypeEnum.kNoInference,
                    solutionType := MateConstraintSolutionTypeEnum.kNoSolutionType,
                    biasPoint1 := Nothing, biasPoint2 := Nothing)

End If


If HMILocation = "LEFT" Then
	Components.Delete("A10001124:1")
	Components.Delete("A10001125:2")
	Constraints.AddMate("Mate1", "A10001125:1", "WorkAxis1", Part2, "WorkAxis1",
                    offset := 0.0, e1InferredType := InferredTypeEnum.kNoInference, e2InferredType := InferredTypeEnum.kNoInference,
                    solutionType := MateConstraintSolutionTypeEnum.kNoSolutionType,
                    biasPoint1 := Nothing, biasPoint2 := Nothing)
	Constraints.AddMate("Mate2", "A10001125:1", "WorkAxis2", Part2, "WorkAxis2",
                    offset := 0.0, e1InferredType := InferredTypeEnum.kNoInference, e2InferredType := InferredTypeEnum.kNoInference,
                    solutionType := MateConstraintSolutionTypeEnum.kNoSolutionType,
                    biasPoint1 := Nothing, biasPoint2 := Nothing)

End If


If HMILocation = "RIGHT" Then
	Components.Delete("A10001124:1")
	Components.Delete("A10001125:1")
	Constraints.AddMate("Mate1", "A10001125:2", "WorkAxis1", Part2, "WorkAxis1",
                    offset := 0.0, e1InferredType := InferredTypeEnum.kNoInference, e2InferredType := InferredTypeEnum.kNoInference,
                    solutionType := MateConstraintSolutionTypeEnum.kNoSolutionType,
                    biasPoint1 := Nothing, biasPoint2 := Nothing)
	Constraints.AddMate("Mate2", "A10001125:2", "WorkAxis2", Part2, "WorkAxis2",
                    offset := 0.0, e1InferredType := InferredTypeEnum.kNoInference, e2InferredType := InferredTypeEnum.kNoInference,
                    solutionType := MateConstraintSolutionTypeEnum.kNoSolutionType,
                    biasPoint1 := Nothing, biasPoint2 := Nothing)

End If

 

Message 6 of 7

theo.bot
Collaborator
Collaborator
Accepted solution
You only need to declare it once out side you select case, not every time. so put the line "Dim Part2 As ComponentArgument " before your select case part.
Message 7 of 7

JamesMeBoi
Enthusiast
Enthusiast
Thank you my friend it worked!