Where does PPG come from?


In property page callbacks like OnClicked and OnChanged, you can use the PPG object to access the parameters on the property page. For example:

def TestProp_text_OnChanged():
Application.LogMessage(PPG.text.Value)

The docs say that PPG is a global variable, but if you try to use PPG outside of a callback, you’ll get a “name is not defined” error.
Or, if you try to put all your callbacks into a separate module, you’ll get that “name is not defined” error again. Several XSI users have hit this problem:

Subject : Re: PPG in self-installable plugins
Interpreter global?
If you just start the script editor and type:

Application.LogMessage(str(PPG))

You’ll get:

#NameError: name 'PPG' is not defined

But in the aforementioned callback if you do:
def TestProp_text_OnChanged( ):
if 'PPG' in globals():
log('Yehaw!')

It’ll find PPG in the globals. When did it get there and how? And more importantly who’s globals?

globals() is module specific (Dive into Python, 8.5 – locals and globals) so if I define a decorator in a separate module it can’t access the global PPG that lives in the global namespace of my plugin.

Arrggsjabcsjdbhcsd!!! My brain is turning to mush!

So what’s up with this PPG object? Where does it come from, and why can’t you access it when you put the callback function into a module?

The answer is that the callback is executed in its own instance of the scripting engine, with its own namespace.
To execute the callback, XSI creates a script engine for the logic (aka the ppg callbacks), and inserts the PPG object into the scripting engine namespace.

When I answered this question back in 2005 on the XSI list, I was officially named one of the ten coolest people in the Universe :-).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s