为Blender Add-Ons设置PyDev和Eclipse

时间:2013-05-29 19:01:53

标签: eclipse pydev blender

我按照此ebook Programming Add-Ons for Blender 2.5中的说明设置了开发环境。

目前我尝试调试已安装的add-on called Bloop虽然它似乎有用,但eclipse仍会显示许多错误消息,如:

class Mapping(object):

    def __init__(self, joint=None, id=None, bone=None, other=None):
        ...
        self.bone_matrix = bpy.bloop.armature.matrix_world.inverted() * self.bone.bone.matrix_local.inverted()
                               ^^^^
                               ErrorMsg: Undefined variable from import: bloop

外部库配置如下:

enter image description here

Blenders版本是2.67,附加组件是为2.59开发的。我在混合器中完全没有使用Python的经验。

另一类错误是:

Unresolved import: MappingSet   bloop.py

from .mapping_set import MappingSet

其中MappingSet与尝试导入的bloop.py位于同一文件夹中。

项目结构如下(我没有源文件夹,因为我想编辑到位)

enter image description here

我做错了什么?

至少抑制错误消息的解决方法是在这些行的末尾使用#@ UnresolvedImport和#@ UndefinedVariable。

1 个答案:

答案 0 :(得分:1)

我以不同方式设置调试,但仍然基于lux-render教程。

首先,创建一个.py文件,让我们调用它debug.py,它将包含一个函数,稍后我们将调用它来设置调试。将此文件放在与模块的主__init__.py相同的文件夹中。根据lux-renderer教程,添加以下代码,更新PYDEV_SOURCE_DIR。

import sys

def startdebug():
    try:
        # set the PYDEV_SOURCE_DIR correctly before using the debugger
        PYDEV_SOURCE_DIR = 'C:\Program Files\eclipse\plugins\org.python.pydev.debug_2.5.0.2012040618\pysrc'

        # test if PYDEV_SOURCE_DIR already in sys.path, otherwise append it
        if sys.path.count(PYDEV_SOURCE_DIR) < 1:
            sys.path.append(PYDEV_SOURCE_DIR)

        # import pydevd module
        import pydevd

        # set debugging enabled
        pydevd.settrace(None, True, True, 5678, False, False)
    except:
        pass

设置PYDEV_SOURCE_DIR时,请确保将其指向org.python.pydev.debug_xxxxx。还有另一个与此类似的文件夹。为确保您拥有正确的文件夹,它将包含/ pysrc文件夹。

现在在您的主__init__.py中,这必须先于任何其他导入语句才能正常工作。直接在bl_info部分下添加以下内容,奇怪的是blender会解析它本身。

DEBUGGING = True
if(DEBUGGING):
    import debug
    debug.startdebug()

在此处使用它将避免添加每个文件跟踪,如lux-render教程。

  1. 将一些断点添加到附加组件文件夹中的版本
  2. 切换到调试透视图,
  3. 启动Eclipses调试服务器,
  4. 启动搅拌机
  5. 运行脚本,它将点击断点。
  6. 我遇到的常见问题:

    • 将路径指向错误的pydev调试文件夹,确保有/ pysrc文件夹
    • 当Pydev更新时,更新PYDEV_SOURCE_DIR,因为debug_xxxxx将有更改
    • 没有运行eclipse服务器,
    • 在文件的本地副本上设置断点,而不是在blender附加目录中设置断点
    • 保存脚本并不意味着blender会重新加载它,使用imp,禁用/重新设置加载项或重新启动Blender。

    有很好的说明可以设置blender和eclipse进行调试。 http://wiki.blender.org/index.php/User:Z0r/PyDevAndProfiling

    虽然这适用于搅拌机游戏引擎,但其中大部分适用于常规搅拌机。希望这有帮助!

    编辑:我删除了它,因为我觉得这没有回答你的问题。但是这是因为你坚持。