Isotropix Forums

User Variables through Python

Clarisse Scripting related topics

User Variables through Python

Unread postby janoshunyadi » Fri May 26, 2017 11:25 am

Is there a way to add user variables through Python (Other than System env variables)?

Greets,
janoshunyadi
 
Posts: 99
Joined: Tue Dec 01, 2015 2:51 pm

Re: User Variables through Python

Unread postby fjutel » Fri May 26, 2017 11:55 am

Hi,

Do you mean a custom variable created in Clarisse? If yes, you can use this code :

python code

ix.application.add_custom_variable("NAME_OF_YOUR_VARIABLE", "VALUE")

Regards,
Florent Jutel
Isotropix
Clarisse QA
User avatar
fjutel
 
Posts: 264
Joined: Tue Jan 13, 2015 1:21 pm

Re: User Variables through Python

Unread postby janoshunyadi » Fri May 26, 2017 11:57 am

Excellent thank you!
janoshunyadi
 
Posts: 99
Joined: Tue Dec 01, 2015 2:51 pm

Re: User Variables through Python

Unread postby janoshunyadi » Fri May 26, 2017 12:04 pm

On the other hand is there a way to pass arguments trough command line for a python script to run at startup?
(Right now I'm trying to pass arguments trough system env variables and its not the most elegant way.)

example:
clarisse.exe -script c:\somescript.py "some_string"
janoshunyadi
 
Posts: 99
Joined: Tue Dec 01, 2015 2:51 pm

Re: User Variables through Python

Unread postby bvaldes » Mon May 29, 2017 9:17 am

Hello,

You can achieve this by using the function "argv" (from the "sys" module). The content of "sys.arv" is a list of all arguments given after Clarisse. In you case theses arguments will be:

python code

import sys
print sys.argv
>>> ['-script', 'c:\somescript.py', '"some_string"']

Then you have to find a way to parse these arguments to find the one you care. In this example this is the last one so:

python code

import sys
print sys.argv[-1]
>>> "some_string"

Regards
Benoit VALDES
Isotropix
Clarisse QA
User avatar
bvaldes
 
Posts: 141
Joined: Mon Sep 26, 2016 11:44 am


Return to Scripting