University of Southern CaliforniaUSC
USC ICT TwitterUSC ICT FacebookUSC ICT YouTube

Passing arguments to python script | General SmartBody Discussion | Forum

Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
Passing arguments to python script
August 19, 2014
8:17 pm
Avatar
New Member
Members
Forum Posts: 2
Member Since:
August 19, 2014
sp_UserOfflineSmall Offline

I currently have a batch file that makes a call of the form:

sbgui.exe -scriptpath ../data/scripts -script my_script.py

 

In my_script.py, I have a hard-coded path for the output of sbgui. However, it would be much nicer if I could pass an argument (the output path) to my_script.py. Does anyone have a way to do this? I poked around in the source, but did not see anything obvious:

http://sourceforge.net/p/smart.....main.cpp 

August 19, 2014
8:28 pm
Avatar
Admin
Forum Posts: 983
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

You can set the mediapath:

 

-mediapath=

 

and access it from Python:

 

p = scene.getMediaPath()

 

then create a directory relative to that path. If you are looking for an argument that can be passed into the command line that can then be used in a script, that doesn't yet exist, although it would be easy to parse a name=value parameter in the command line and set them as attributes on the Scene object for access internally.

 

Ari

August 20, 2014
2:55 pm
Avatar
New Member
Members
Forum Posts: 2
Member Since:
August 19, 2014
sp_UserOfflineSmall Offline

Thanks for the reply. I couldn't find a way to set this from the sbgui.exe command line call, so I just had my windows batch file build the python script by putting this line at the beginning:

model_export_path="My Path"

Resolved!

August 21, 2014
7:48 pm
Avatar
Admin
Forum Posts: 983
Member Since:
December 1, 2011
sp_UserOfflineSmall Offline

Ah, yes, I suppose you can set environment variables then access them via Python:

 

<span class="pln">myvar = os</span><span class="pun">.</span><span class="pln">environ</span><span class="pun">.</span><span class="pln">get</span><span class="pun">(</span><span class="str">'SOME_VARIABLE'</span><span class="pun">)<br /><br />Ari<br /><br /></span>
Forum Timezone: America/Los_Angeles

Top Posters:

jwwalker: 80

jyambao: 52

rbaral: 47

adiaz: 30

WargnierP: 29

lucky7456969: 28

mbarros: 28

avida.matt: 26

JonathanW: 24

laguerre: 23

Member Stats:

Guest Posters: 69

Members: 122211

Moderators: 3

Admins: 4

Forum Stats:

Groups: 1

Forums: 5

Topics: 531

Posts: 2495