put the custom class in a separate file worked!!

and using the maya.mel.eval() call makes the ctrl+z undo the whole
thing! sweeeet~


thanks a lot guys!

-ling

On Feb 8, 12:38 am, Ofer Koren <[email protected]> wrote:
> When you call the 'python' mel-command, you're essentially running that
> python code in the "__main__" module (the script editor window). This means
> that only variables/functions defined in that __main__ module will be
> available to the python call, and definitions made in the module where the
> python call is made will not.
> So you'll have to refer to your module where your definitions exist in order
> to use them. You can do this generically like so:
>
> cmd = "import %s; mayaString=%s.customClass(); mayaString.doit()" %
> (__name__, __name__)
> mm.eval('python("%s")' % cmd)
>
> (beware of sys.path.append(...) as it will keep adding to your python path
> in each cmd call and slow down your python import mechanism; use it only if
> needed - i assume that since the module is actually running it is already
> imported and so it probably already exists in the python path)
>
> - Oferwww.mrbroken.com
>
> On Tue, Feb 8, 2011 at 7:43 AM, Ling <[email protected]> wrote:
> > Thanks for the replay guys:
>
> > @Adam, I am not sure, will give it a try..
>
> > @Chad, the reason I am doing this is hoping if I can have some better
> > call back if hit "ctrl-Z" in maya.
> > I could just run the python command directly, but the ctrl+z would
> > only undo the last step defined in the customClass().doIt()
>
> > @C. B. Esquire: currently the customClass is in the same file as the
> > caller functions,
> > but I will try to make it a separate file and see how it works, thanks
> > for the suggestion!
>
> > thanks again! will report after try it in the morning!
>
> > -ling
>
> > On Feb 7, 8:27 pm, "C. B. Esquire" <[email protected]> wrote:
> > > if youre in a python module, which is overriding mel procs, this is a
> > > perfectly good reason to use python calls in the proc override
> > > if this is the case, you you can import the module in the same call, to
> > > throw to maya.mel to eval ~
>
> > > cmd = 'python("import
> > > sys;sys.path.append(\'/the/path/to/your/script\');import yourModule;
> > > mayaString=customClass();mayaString.doit()");'
> > > mm.eval(cmd)
>
> > > On Tue, Feb 8, 2011 at 4:59 PM, Chad Dombrova <[email protected]> wrote:
>
> > > > > cmd   = 'python(\"mayaString = customClass()\");'
> > > > > cmd += 'python(\"mayaString.doit()\");'
>
> > > > > maya.mel.eval(cmd)
>
> > > > wait, i don't get it. why are you using maya.mel.eval to run python
> > code?
>
> > > > -chad
>
> > > > --
> > > >http://groups.google.com/group/python_inside_maya
>
> > --
> >http://groups.google.com/group/python_inside_maya
>
>

-- 
http://groups.google.com/group/python_inside_maya

Reply via email to