PDA

View Full Version : XSI - PYTHON - PPG Object Logic question


Pascaru
07-20-2007, 02:22 AM
Hi,

I created PPG Objects in Jscript for XSI, I am now trying to make the same PPG Object with Python for XSI.

This is the code I have for my PPG Logic and Language:

jscript:
oPPGLayout.Logic = CreateHandControls_OnClicked.toString()
oPPGLayout.Language = "JScript" ;

what is the equivalent for Python?? this is what I have:

oPPGLayout.Logic = str("CreateHandControls_OnClicked")
oPPGLayout.Language = "Python" ;

The UI still pops up but i get the error below, saying my function is not defined.


# ERROR : Traceback (most recent call last):
# File "<script Block >", line 1, in <module>
# CreateHandControls_OnClicked
# NameError: name 'CreateHandControls_OnClicked' is not defined
# - [line 1]
# ERROR : Property Page Script Logic Error (Python ActiveX Scripting Engine)
# ERROR : >[1] CreateHandControls_OnClicked
# ERROR : Traceback (most recent call last):
# File "<script Block >", line 1, in <module>
# CreateHandControls_OnClicked
# NameError: name 'CreateHandControls_OnClicked' is not defined

Any suggestions will be greatly appreciated.
Thank you

dlanier
07-21-2007, 06:01 AM
Hi Pascaru,

Actualy the toString Javascript function doesn't print only the name but the whole function code in a string format.

So in Python, it's a burden to do and you have to define all your function code inside the string, like this :

layout.AddRow()
layout.AddButton("Convert","Convert your scene")
layout.AddButton("Help","Help")
layout.EndRow()
layout.Language = "Python"
s ="def Convert_OnClicked():Application.logMessage (PPG.Inspected(0).Pipeline.value)\n"
s+="def Help_OnClicked():Application.logMessage (\"HELP\")"
layout.Logic =s


If you want your functions to call another function, it should be defined in the string as well...

I've also found that there is a Python module called "inspect" that has a "getsource" function (not sure about the name) which is exactly the same as JScript's toString()
Unfortunately, it doesn't work when using ActiveX Python (or at least I didn't succeeded in making it work... But some other people on Python forums have the same problem)


And finally, I was told to rather develop a plugin through Python as there is no need of a logic block in that case, the functions are defined directly in the script and don't need to be in a string format in the logic block. It's only a few extra functions to define when developing a XSI plugin in Python. It's worth trying :-)
Best regards,

Pascaru
07-21-2007, 06:50 AM
Hello David,

What I don't understand is why the content of my function is not executed when i click the button.

Let's say the code you wrote is the one used to create my layout and set the layout.logic..

Do I syill define the function later on in the code:
def Convert_OnClicked()
LogMessage("test")


When running the script, i get the UI, i get my button, i click and get the .value , but i do NOT get the log "test".. How come it doesnt call that function?


"it's a burden to do and you have to define all your function code inside the string,"
by this, do you mean i have to write ALL the function code inside the layout.logic ?? (not only the function name then?) ...


I can send you my code if you could you help me figure this out it would be great, seems like you're the one with the answer on all those forums :)

thank you.

dlanier
07-21-2007, 05:36 PM
Pascaru,

Yes, exactly, you have to write ALL the code in the string passed to the logic code, not only the function names.

No problem, feel free to send me your code if needed at contact@dl3d.com, I'll try to fix it.
Regards,

Pascaru
07-21-2007, 06:59 PM
"you have to write ALL the code in the string passed to the logic code, not only the function names."
hmm. wow, that's not every readable at the end then huh? ..

I am sending you my code to your email, thanks ! :)

CGTalk Moderation
07-21-2007, 06:59 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.