Give the custom property a variable and then use a try/except
This might be a dirty way of doing it and I'm sure someone far more qualified
will tell you why this is a bad idea. But it works :)
from win32com.client import constants as c
root = Application.ActiveSceneRoot
#------function ---------------------------------
def main():
global cpSet
root = Application.ActiveSceneRoot
Application.DeselectAll()
Application.SelectObj("Scene_Root", "", "")
#give your custom property a variable e.g cpSet
cpSet = root.AddProperty("Custom_parameter_list",False, "CustomPSet")
Application.SelectObj("CustomPSet", "", "")
Application.SIAddCustomParameter("CustomPSet", "Param", "siDouble", 0, "",
"", "", 2053, "", 1, "", "")
Application.InspectObj(cpSet,"","CustomPSet", c.siModal)
box = XSIUIToolkit.MsgBox('I did what you asked me to do', 1, 'FINISHED!' )
print box
if box == 1:
print "OK"
Application.DeleteObj (cpSet)
if box == 2:
print "Cancel"
Application.DeleteObj (cpSet)
#-------------------------------------------------------------------------
#script starts here -----------------
try:
main()
except:
Application.DeleteObj (cpSet)
print "cancelled"
Date: Mon, 17 Nov 2014 14:37:14 +0000
Subject: Re: Python help
From: [email protected]
To: [email protected]
Cheers, Simon. - Thanks for the links and info.
I think part 2 is a little above where I am with scripting! I might look into
storing a version number in an attribute property to reference as a variable
rather than having build a list, look-up the latest version in a folder etc.
With regard to number 1 I am inspecting the property of a temporary custom
parameter set (These inputs are to be used as variables in various portions of
the script. If 'ok' is selected then the script continues to run as I want but
what I want cancel to do is remove the temporary cp set. I can use your
message box at the end of the script which does the job (like below) but I'd be
interested in knowing how to do this on the custom parameter set inspect
property window because if cancel is selected at this stage then the cp set
remains.
from win32com.client import constants as
cApplication.DeselectAll()Application.SelectObj("Scene_Root", "",
"")Application.AddProp("Custom_parameter_list", "", "", "CustomPSet",
"")Application.SelectObj("CustomPSet", "",
"")Application.SIAddCustomParameter("CustomPSet", "Param", "siDouble", 0, "",
"", "", 2053, "", 1, "", "")
Application.InspectObj("CustomPSet","","CustomPSet", c.siModal)
box = XSIUIToolkit.MsgBox('I did what you asked me to do', 1, 'FINISHED!'
)print box
if box == 1: Application.DeleteObj("CustomPSet")
if box == 2: Application.DeleteObj("CustomPSet")
On 17 November 2014 13:36, Simon Reeves <[email protected]> wrote:
You need a msgbox
http://download.autodesk.com/global/docs/softimage2014/en_us/sdkguide/si_om/XSIUIToolkit.MsgBox.html
1 is the ok/cancel style box, if you then print the variable you will see the
result of what they picked, as you can see it returns 1 if the user clicked ok,
or 2 if the cancelled (or pressed x)
EG:
box = XSIUIToolkit.MsgBox('hello', 1, 'lalal' )print box
if box == 1:
print 'ok' if box == 2: print 'cancelled'
for 2) if you are doing stuff with v### and file paths I recommend you use
regular expression though daunting, sites like this are extremely useful
http://regexr.com/
Simon ReevesLondon, UK
[email protected]
www.simonreeves.comwww.analogstudio.co.uk
On 17 November 2014 13:16, Jonny Grew <[email protected]> wrote:
Hi list.
A real novice at this but I'm butchering various scripts at the moment and
wondered if anyone can shed any light on these two bits of code. I can find
examples of number 1 in VB but I'm working in Python. everything I've
discovered at the moment doesn't work
1 - I want to run 2 portions of scripts depending on whether the inspected
property of a custom parameter set has the button push 'ok' or 'cancel' - I
can't find the code for this portion of the 'if' statement
2 (a lot more complex, i suspect) I want to look up and get the latest version
number of a saved out model/scene/action (all of these have the format "v##').
These will live in a folder structure determined by a number of variables in
the script that I have already. My script will then add 1 to this number in
order to ensure the next export doesn't override an existing asset. As a
bonus... if the user changes this number meaning an export would save over an
existing asset then it would be great to flag a warning with an 'THIS VERSION
ALREADY EXISTS ARE YOU SURE" message.
Any tips or links to scripts that I can hack would be much appreciated!
CheersJonny