  | | | <DEFANGED_script >Python and the PPG global variable? | <DEFANGED_script >Python and the PPG global variable? 2005-04-27 - By Aloys Baillet
Back Sorry Patrick, but I don't think it's possible... What you can also do is to put all the code of the scripted operator in a separate file, and call XSIFactory.CreateScriptedOpFromFile. But in this case you have to know where is installed the file (what I usually do is to take the current PluginItem and ask its FileName property to find out where I am in the filesystem, then point at the scripted op file. The advantage of this method is that you can add as many helper function in your code without having to add them in the operator code with the inspect.getsourcefunction... Cheers,
Aloys
On 4/28/05, Patrick Boucher <patrickb@(protected)> wrote: > > Jerry Gamache wrote: > > The nifty func.toString() from jscript does not translate directly into > str(func) in Python. You ended up calling OnInit as you were running the > setup script and it is normal that PPG is not defined there. > > > > You have some options: > > > > 1- Pass all the logic inlined in a string: > > > > # Put all the PPG logic inside a triple quoted string. > > # Can be difficult to debug since syntax errors will > > # not be found until the PPG is opened. > > oLayout.Logic = """ > > > > def OnInit(): > > Application.LogMessage(str(dir(PPG))) > > > > def Cons_OnChanged(): > > Application.LogMessage(str(dir(PPG))) > > > > """ > > > > 2- Grab the function text from an imported module: > > > > import inspect > > import myPPGHandlers > > > > # Grab the code directly from the imported module: > > # Easier to debug since syntax errors will get caught > > # when importing the module, and easier to manage since > > # everything is in a module. > > oLayout.Logic = inspect.getsource(myPPGHandlers.OnInit) + \ > > inspect.getsource(myPPGHandlers.cons_OnChanged) > > > > I currently don't think you can get the source code of a function > defined in the setup code since that code is very quickly compiled into > bytecode and the actual source text is discarded. This means that the code > text must reside in a file somewhere and the import/inspect combo is you > solution here. > > > > > > > > --- > > Unsubscribe? Mail Majordomo@(protected) with the following text in > body: > > unsubscribe xsi > > > > When creating a custom scripted operator, is there any way to use the > same kind of layout logic mechanism as a self-installable PPG? > > I'm usisng your #2 technique on a tip from one of my coworkers but I'd > rather everything be callback based. > > -- > Patrick Boucher > TD - Coder - Resident geek > Buzz Image Group > Tel 514.848.0579 > Fax 514.848.6371 > > www.buzzimage.com <http://www.buzzimage.com> > www.xsi-blog.com <http://www.xsi-blog.com> > --- > Unsubscribe? Mail Majordomo@(protected) with the following text in body: > unsubscribe xsi >
-- Aloys Baillet - Character TD @ Animal Logic
Sorry Patrick, but I don't think it's possible...<br> What you can also do is to put all the code of the scripted operator in a separate file, and call XSIFactory.CreateScriptedOpFromFile. But in this case you have to know where is installed the file (what I usually do is to take the current PluginItem and ask its FileName property to find out where I am in the filesystem, then point at the scripted op file. The advantage of this method is that you can add as many helper function in your code without having to add them in the operator code with the inspect.getsource function...<br> Cheers,<br> <br> Aloys<br><br><div><span class="gmail_quote">On 4/28/05, <b class="gmail _sendername">Patrick Boucher</b> <<a href="mailto:patrickb@(protected)" >patrickb@(protected)</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> Jerry Gamache wrote:<br>> The nifty func.toString() from jscript does not translate directly into str(func) in Python. You ended up calling OnInit as you were running the setup script and it is normal that PPG is not defined there.<br>><br>> ; You have some options:<br>><br>> 1- Pass all the logic inlined in a string:<br>><br>> # Put all the PPG logic inside a triple quoted string. <br>> # Can be difficult to debug since syntax errors will<br>> # not be found until the PPG is opened.<br>> oLayout.Logic = """<br> ><br>> def OnInit():<br>> Application.LogMessage(str(dir(PPG))) <br>><br>> def Cons_OnChanged():<br>> Application.LogMessage(str(dir(PPG)))<br>><br>> """ <br>><br>> 2- Grab the function text from an imported module:<br>><br> > import inspect <br>> import myPPGHandlers<br>><br>> # Grab the code directly from the imported module:<br>> # Easier to debug since syntax errors will get caught <br>> # when importing the module, and easier to manage since <br>> # everything is in a module.<br>> oLayout.Logic = inspect.getsource (myPPGHandlers.OnInit) + \<br>> inspect.getsource(myPPGHandlers.cons_OnChanged)<br>><br>> I currently don't think you can get the source code of a function defined in the setup code since that code is very quickly compiled into bytecode and the actual source text is discarded. This means that the code text must reside in a file somewhere and the import/inspect combo is you solution here.<br>><br>><br>><br>> ---<br>> Unsubscribe? Mail <a href="mailto:Majordomo@(protected)">Majordomo@(protected)</a> with the following text in body:<br>> unsubscribe xsi<br>><br> <br>When creating a custom scripted operator, is there any way to use the<br >same kind of layout logic mechanism as a self-installable PPG?<br><br>I'm usisng your #2 technique on a tip from one of my coworkers but I'd<br> rather everything be callback based.<br><br>--<br>Patrick Boucher<br>TD - Coder - Resident geek<br>Buzz Image Group<br>Tel 514.848.0579<br>Fax 514.848.6371<br> <br><a href="http://www.buzzimage.com">www.buzzimage.com</a><br> <a href="http://www.xsi-blog.com">www.xsi-blog.com</a><br>---<br>Unsubscribe? Mail <a href="mailto:Majordomo@(protected)">Majordomo@(protected)</a> with the following text in body:<br>unsubscribe xsi<br></blockquote></div> <br><br><br>-- <br>Aloys Baillet - Character TD @ Animal Logic
|
|
 |