Maya Python:由于Reload()而导致的未绑定方法 [英] Maya Python: Unbound Method due to Reload()

查看:402
本文介绍了Maya Python:由于Reload()而导致的未绑定方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个文件从第三个文件导入相同的对象跟踪方法。它的工作原理是这样的

I have two files that import the same object tracking method from a third file. It works something like this

file TrackingMethod

    class Tracker(object):
        def __init__(self,nodeName=None,dag=None,obj=None):
            #Does some open maya stuff to get the dag path
        def fullpath(self):
            return dag.fullpath()

file Shapes #classes that create objects with shape nodes
    import TrackingMethod as trm
    reload(trm)

    class circle(trm.Tracker):
        def __init__(self,nodeName=None,dag=None,obj-None):
            #does some shape related stuff then inits tracker
            trm.Tracker.__init__(self,nodeName=nodeName,dag=dag,obj=obj)

file ShaderNodes #Classes that create shading nodes
    import TrackingMethod as trm
    reload(trm)

    class shaderThingy(trm.Tracker):
        def __init__(self,nodeName=None,dag=None,obj-None):
            #does some shader related stuff then inits tracker
            trm.Tracker.__init__(self,nodeName=nodeName,dag=dag,obj=obj)

这是问题所在。错误发生在trm.Tracker。 init 。如果我使用这两个文件并且我碰巧重新加载()ShaderNode或Shapes,则另一个的方法将不再识别它们是原始TrackingMethod类的子类。通过重新加载其他类失去了它的引用,我得到:

Here's the problem. The error occurs at the trm.Tracker.init. If I use both files and I happen to reload() either ShaderNode or Shapes, the methods of the other will no longer recognize they're subclasses of the original TrackingMethod class. By reloading the other class loses it's reference back and I get either:

>>unbound method __init__() must be called with Tracker instance as first argument (got circle instance instead) 

>>unbound method __init__() must be called with Tracker instance as first argument (got ShaderThingy instance instead) 

..取决于重新加载的内容。无论哪个是重新加载的工作,以前重新加载都是未绑定的。

..depending on which gets reloaded. Whichever is the last to get reloaded works, and the previously reloaded gets unbound.

请注意,我需要重新加载这些脚本来测试我的更改。我知道一旦重新加载就不存在了,他们将不再受到限制,但我需要在工作时看到我的更改。

Mind you, I need to reload these scripts to test my changes. I know once the reloads are out of there they'll no longer be unbound, but I need to see my changes as I work.

我该怎么办?

推荐答案

您可能希望从子模块中删除重新加载,并按照文件中依赖项隐含的逻辑顺序重新加载它们: p>

You probably want to remove the reloads from your submodules and reload them in the logical order implied by the dependencies in the files:

reload(TrackingMethod)
reload(Shapes)
reload(ShaderNodes)

对于像这样的小案例它可行,但如果事情变得更复杂,那将很难管理。

For a small case like this it works, but if things get more complex it's going to be hard to manage.

这篇关于Maya Python:由于Reload()而导致的未绑定方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆