Forum Discussion

ianlop's avatar
ianlop
Occasional Contributor
2 years ago

Changing the value of a project variable through scripting

Hello

 

I'd like to change the value of a project variable through a script that has already been set as some value at some time at the beginning of execution.

So at the beginning of my python script i do something like this:

 

Project.Variable.Obj1 = Some Object

...

But then later on down the execution of my keyword test I want to reassign that project variable object to a new one through a method like so, where "projVarObj" would be the "reference" to the project variable "Obj1":
def foo(projVarObj, propNames=[], propValues=[])):

       ...
       projVarObj = MainWindow.Find(propNames, propValues, 1000, True)

I have tried this but when I debug I see that the projVarObj is None.

 

6 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    You have assigned the following project variable,

     

    Project.Variable.Obj1 = Some Object

     

    Then somewhere below, you want to assign Project.Variable.Obj1 to something else, using

     

    def foo(projVarObj, propNames=[], propValues=[])):
      projVarObj = MainWindow.Find(propNames, propValues, 1000, True)

     

     

    projVarObj is different to Project.Variable.Obj1. If projVarObj is None, then it means the Find method was not able to find the object based on the criteria given for propNames and propValues.

    • ianlop's avatar
      ianlop
      Occasional Contributor

      I meant that projVarObj as a parameter is None. Even though I have already assigned it some value earlier in the execution. The .Find method was just something ill be doing with the project variable.

      So what I have:

      Project.Variable.Obj1 = Some object

      but later on down the road when I don't want to type out Project.Variable.SomeObject in its entirety i want to make a method that generalizes the changing of one of my project variables through the method foo I wrote up there, I could have Proj.Variable.Obj1 through Obj5 and i want to change them this way for simplification purposes.

      foo(Project.Variable.Obj1, PropNames[1,2,3], PropValues[1,2,3])

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Sorry, I still don't quite understand.

     

    Are you able to upload your complete code? 

    • ianlop's avatar
      ianlop
      Occasional Contributor

      Another way of asking my question is if it is possible to change a project variable's contents that does not require me to explicitly write out


      "Project.Variable.Obj1 = some object"

       

      over and over again.

      Instead can I send Project.Variable.Obj1 as an argument to a method I made to change it that way?
      If so, when I tried to do this, the project variable i passed did not get changed in its calling method. Why's that?