如何导入PyMEL核心?

时间:2015-10-27 10:19:22

标签: python maya pymel

我正在导入maya.standalone,初始化它,然后将pymel.core as pmc导入我的Maya Python解释器,该解释器在powershell中运行。在这一点上,我得到了很多警告。在我致电:xform, shape = pmc.polysphere()后,我收到警告:name 'xform' is not defined

这是pymel import的输出

> Warning: file: C:/Program
> Files/Autodesk/Maya2016/scripts/startup/initialStartup.mel line 195:
> Y-axis is already the Up-axis Initialized VP2.0 renderer {   Version :
> 6.3.16.0. Feature Level 5.   Adapter : Intel(R) HD Graphics 4600   Vendor ID: 32902. Device ID : 1046   Driver :
> nvwgf2umx.dll:9.18.13.5306.   API : DirectX V.11.   Max texture size :
> 16384 * 16384.   Max tex coords : 32   Shader versions supported
> (Vertex: 5, Geometry: 5, Pixel 5).   Active stereo support available :
> 0   GPU Memory Limit : 2080 MB.   CPU Memory Limit: 15472.7 MB. }
> OpenCL evaluator is attempting to initialize OpenCL. Detected 2 OpenCL
> Platforms:  0: Intel(R) Corporation. Intel(R) OpenCL. OpenCL 1.2 . 
> Supported extensions: cl_intel_dx9_media_sharing
> cl_khr_byte_addressable_store cl_khr_d3d11_sharing
> cl_khr_dx9_media_sharing cl_khr_gl_sharing
> cl_khr_global_int32_base_atomics cl_khr_global
> _int32_extended_atomics cl_khr_icd cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics  1: NVIDIA Corporation. NVIDIA
> CUDA. OpenCL 1.2 CUDA 7.5.8.  Supported extensions:
> cl_khr_byte_addressable_store cl_khr_icd cl_khr_gl_sharing
> cl_nv_compiler_options cl_nv_device_attribute_query
> cl_nv_pragma_unroll cl_nv_d3d9_sharing cl_nv_d3d10_shari ng
> cl_khr_d3d10_sharing cl_nv_d3d11_sharing cl_nv_copy_opts OpenCL
> evaluator choosing OpenCL platform Intel(R) Corporation. Choosing
> OpenCL Device Intel(R) HD Graphics 4600.  Device Type: GPU  Device is
> available. OpenCL device does not support out of order execution
> 
> Error: file: C:/Program
> Files/Autodesk/Maya2016/plug-ins/xgen/scripts/igInitialize.mel line
> 63: ImportError: file <maya console> line 1: No module named xgenm
> Error: Unable to execute igInitialize.mel. Unable to execute
> igInitialize.mel.Error: line 0: ImportError: file <maya console> line
> 1: No module named xgenm Error: Unable to execute xgen.mel. Unable to
> execute xgen.mel.xgmNurbsPatch [u'containerBase', u'entity',
> u'dagNode', u'shape', u'geometryShape', u'deformableShape',
> u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmP atch',
> u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape',
> u'deformableShape', u'controlPoint', u'surfaceShape',
> u'THsurfaceShape', u'xgmNurbsPatch'] pymel.internal.apicache : WARNING
> : lineage for node xgmNurbsPatch is cyclical: [u'containerBase',
> u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape',
> u'controlPoint', u's urfaceShape', u'THsurfaceShape', u'xgmPatch',
> u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape',
> u'deformableShape', u'controlPoint', u'surfaceShape',
> u'THsurfaceShape', u' xgmNurbsPatch'] xgmSubdPatch [u'containerBase',
> u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape',
> u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmPatch',
> u'containerBase', u'e ntity', u'dagNode', u'shape', u'geometryShape',
> u'deformableShape', u'controlPoint', u'surfaceShape',
> u'THsurfaceShape', u'xgmSubdPatch'] pymel.internal.apicache : WARNING
> : lineage for node xgmSubdPatch is cyclical: [u'containerBase',
> u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape',
> u'controlPoint', u'su rfaceShape', u'THsurfaceShape', u'xgmPatch',
> u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape',
> u'deformableShape', u'controlPoint', u'surfaceShape',
> u'THsurfaceShape', u'x gmSubdPatch'] xgmArchiveGuide
> [u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape',
> u'deformableShape', u'controlPoint', u'surfaceShape',
> u'THsurfaceShape', u'xgmGuide', u'containerBase', u'entity',
> u'dagNode', u'shape', u'geometryShape', u'deformableShape',
> u'controlPoint', u'surfaceShape', u'THsurfaceShape',
> u'xgmArchiveGuide'] pymel.internal.apicache : WARNING : lineage for
> node xgmArchiveGuide is cyclical: [u'containerBase', u'entity',
> u'dagNode', u'shape', u'geometryShape', u'deformableShape',
> u'controlPoint', u 'surfaceShape', u'THsurfaceShape', u'xgmGuide',
> u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape',
> u'deformableShape', u'controlPoint', u'surfaceShape',
> u'THsurfaceShape', u'xgmArchiveGuide'] xgmCardGuide [u'containerBase',
> u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape',
> u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmGuide',
> u'containerBase', u'e ntity', u'dagNode', u'shape', u'geometryShape',
> u'deformableShape', u'controlPoint', u'surfaceShape',
> u'THsurfaceShape', u'xgmCardGuide'] pymel.internal.apicache : WARNING
> : lineage for node xgmCardGuide is cyclical: [u'containerBase',
> u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape',
> u'controlPoint', u'su rfaceShape', u'THsurfaceShape', u'xgmGuide',
> u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape',
> u'deformableShape', u'controlPoint', u'surfaceShape',
> u'THsurfaceShape', u'x gmCardGuide'] xgmSphereGuide [u'containerBase',
> u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape',
> u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmGuide',
> u'containerBase', u 'entity', u'dagNode', u'shape', u'geometryShape',
> u'deformableShape', u'controlPoint', u'surfaceShape',
> u'THsurfaceShape', u'xgmSphereGuide'] pymel.internal.apicache :
> WARNING : lineage for node xgmSphereGuide is cyclical:
> [u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape',
> u'deformableShape', u'controlPoint', u' surfaceShape',
> u'THsurfaceShape', u'xgmGuide', u'containerBase', u'entity',
> u'dagNode', u'shape', u'geometryShape', u'deformableShape',
> u'controlPoint', u'surfaceShape', u'THsurfaceShape', u
> 'xgmSphereGuide'] xgmSplineGuide [u'containerBase', u'entity',
> u'dagNode', u'shape', u'geometryShape', u'deformableShape',
> u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmGuide',
> u'containerBase', u 'entity', u'dagNode', u'shape', u'geometryShape',
> u'deformableShape', u'controlPoint', u'surfaceShape',
> u'THsurfaceShape', u'xgmSplineGuide'] pymel.internal.apicache :
> WARNING : lineage for node xgmSplineGuide is cyclical:
> [u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape',
> u'deformableShape', u'controlPoint', u' surfaceShape',
> u'THsurfaceShape', u'xgmGuide', u'containerBase', u'entity',
> u'dagNode', u'shape', u'geometryShape', u'deformableShape',
> u'controlPoint', u'surfaceShape', u'THsurfaceShape', u
> 'xgmSplineGuide'] AbcExport v1.0 using Alembic 1.5.4 (built May  8
> 2014 13:47:10) Error: file: C:/Program
> Files/Autodesk/Maya2016/scripts/startup/autoLoadPlugin.mel line 46:
> ImportError: file <maya console> line 1: No module named
> mtoa.lightFilters
> 
> API error detected in plugins\mtoa\extension\PxMayaNode.cpp at line
> 222 : (kFailure): Unexpected Internal Failure Error: file: C:/Program
> Files/Autodesk/Maya2016/scripts/startup/autoLoadPlugin.mel line 46:
> ImportError: file <maya console> line 1: No module named
> mtoa.lightFilters
> 
> API error detected in plugins\mtoa\extension\PxMayaNode.cpp at line
> 222 : (kFailure): Unexpected Internal Failure Error: file: C:/Program
> Files/Autodesk/Maya2016/scripts/startup/autoLoadPlugin.mel line 46:
> ImportError: file <maya console> line 1: No module named
> mtoa.lightFilters
> 
> API error detected in plugins\mtoa\extension\PxMayaNode.cpp at line
> 222 : (kFailure): Unexpected Internal Failure Error: file: C:/Program
> Files/Autodesk/Maya2016/scripts/startup/autoLoadPlugin.mel line 46:
> ImportError: file <maya console> line 1: No module named
> mtoa.lightFilters
> 
> API error detected in plugins\mtoa\extension\PxMayaNode.cpp at line
> 222 : (kFailure): Unexpected Internal Failure 00:00:00   359MB ERROR  
> | [mtoa] [xgenTranslator] Could not find xgen_procedural in search
> path $ARNOLD_PLUGIN_PATH Error: file: C:/Program
> Files/Autodesk/Maya2016/scripts/startup/autoLoadPlugin.mel line 46:
> ImportError: file <maya console> line 1: No module named
> mtoa.api.extensions
> 
> API error detected in plugins\mtoa\extension\ExtensionsManager.cpp at
> line 571 : (kFailure): Unexpected Internal Failure Error: file:
> C:/Program Files/Autodesk/Maya2016/scripts/startup/autoLoadPlugin.mel
> line 46: ImportError: file <maya console> line 1: No module named
> mtoa.api.extensions
> 
> API error detected in plugins\mtoa\extension\ExtensionsManager.cpp at
> line 571 : (kFailure): Unexpected Internal Failure Error: file:
> C:/Program Files/Autodesk/Maya2016/scripts/startup/autoLoadPlugin.mel
> line 46: ImportError: file <maya console> line 1: No module named
> mtoa.api.extensions
> 
> API error detected in plugins\mtoa\extension\ExtensionsManager.cpp at
> line 571 : (kFailure): Unexpected Internal Failure Error: file:
> C:/Program Files/Autodesk/Maya2016/scripts/startup/autoLoadPlugin.mel
> line 46: ImportError: file <maya console> line 1: No module named
> arnold
> 
> API error detected in plugins\mtoa\Main.cpp at line 770 : (kFailure):
> Unexpected Internal Failure 00:00:00   362MB ERROR   | Failed to
> import python module 'arnold' Error: Failed to import python module
> 'arnold' aiSkyDomeLight [u'containerBase', u'entity', u'dagNode',
> u'shape', u'geometryShape', u'locator', u'THlocatorShape',
> u'SphereLocator', u'containerBase', u'entity', u'dagNode', u'shape',
> u'geo metryShape', u'locator', u'THlocatorShape', u'aiSkyDomeLight']
> pymel.internal.apicache : WARNING : lineage for node aiSkyDomeLight is
> cyclical: [u'containerBase', u'entity', u'dagNode', u'shape',
> u'geometryShape', u'locator', u'THlocatorShape', u'Sphere Locator',
> u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape',
> u'locator', u'THlocatorShape', u'aiSkyDomeLight'] aiSky
> [u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape',
> u'locator', u'THlocatorShape', u'SphereLocator', u'containerBase',
> u'entity', u'dagNode', u'shape', u'geometryShap e', u'locator',
> u'THlocatorShape', u'aiSky'] pymel.internal.apicache : WARNING :
> lineage for node aiSky is cyclical: [u'containerBase', u'entity',
> u'dagNode', u'shape', u'geometryShape', u'locator', u'THlocatorShape',
> u'SphereLocator',  u'containerBase', u'entity', u'dagNode', u'shape',
> u'geometryShape', u'locator', u'THlocatorShape', u'aiSky'] Error:
> file: C:/Program
> Files/Autodesk/Maya2016/scripts/startup/autoLoadPlugin.mel line 46:
> initializePlugin function failed (mtoa) AbcImport v1.0 using Alembic
> 1.5.4 (built May  8 2014 13:47:10) BifrostMain plug-in loaded (built Feb 26 2015 18:01:51) Error: file: C:/Program
> Files/Autodesk/Maya2016/scripts/startup/autoLoadPlugin.mel line 46:
> ImportError: file C:/Program
> Files/Autodesk/Maya2016/plug-ins/xgen/plug-ins/xgenMR.py line 9: No m
> odule named xgenm Warning: file: C:/Program
> Files/Autodesk/Maya2016/scripts/startup/autoLoadPlugin.mel line 46:
> Failed to run file: C:/Program
> Files/Autodesk/Maya2016/plug-ins/xgen/plug-ins/xgenMR.py pymel : ERROR
> : Failed to get controlCommand list from xgenMR pymel : ERROR : Failed
> to get modelEditorCommand list from xgenMR pymel : ERROR : Failed to
> get command list from xgenMR pymel : ERROR : Failed to get
> constraintCommand list from xgenMR pymel.core : ERROR : Failed to get
> depend nodes list from xgenMR Error: file: C:/Program
> Files/Autodesk/Maya2016/scripts/startup/autoLoadPlugin.mel line 46: 
> (xgenMR)
> >>>

我正在阅读实用玛雅编程一书,这是本书中的文字:

  

现在我们将开始挖掘Maya和PyMEL。让我们来吧   在mayapy解释器中初始化Maya,以便我们可以使用超过   只是标准的Python功能。我们通过电话来做到这一点   maya.standalone.initialize,如下面的代码所示:

>>> import maya.standalone
>>> maya.standalone.initialize()
>>> import pymel.core as pmc
>>> xform, shape = pmc.polySphere()
  

pymel.core的导入会自动隐式调用maya.standalone.initialize,但是我这样做了   明确地在这里,所以它清楚发生了什么。在将来,你可以   通常会跳过对maya.standalone.initialize的调用,然后导入   pymel.core。

     

我们可以发现很多关于这些PyMEL对象的信息,   代表Maya节点,使用基本的Python。例如,要看   我们的任何一个对象的类型,我们都可以使用内置类型   函数(我们将在本章后面深入研究类型)。

任何人都可以解释我在翻译中遇到的错误并提供解决方案吗?

2 个答案:

答案 0 :(得分:4)

(这不是一个完整的答案,但我是一个菜鸟,所以我不能发表评论。)

一堆警告,看起来像

xgmNurbsPatch [u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape', u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmPatch', u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape', u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmNurbsPatch']
# Warning: pymel.internal.apicache : lineage for node xgmNurbsPatch is cyclical: [u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape', u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmPatch', u'containerBase', u'entity', u'dagNode', u'shape', u'geometryShape', u'deformableShape', u'controlPoint', u'surfaceShape', u'THsurfaceShape', u'xgmNurbsPatch'] # 

是(我认为)Maya 2016的一个问题,可能不是你需要担心的任何事情。

我在脚本编辑器中工作,而不是使用maya.standalone。当我将Pymel导入Maya 2016时,我会收到6个针对各种&#39; xgm&#39;的警告。课程,和你一样。在之前版本的Maya中并没有发生。

至于错误,mtoa / Arnold和xgen都是插件(所有错误似乎都与插件加载有关)。也许你可以禁用它们?对不起,我还没有使用Maya主应用程序之外的Maya Python解释器。

编辑:我在XGen,Arnold和Maya 2016上看到其他人(或者你呢?)有类似的错误: http://forums.cgsociety.org/archive/index.php?t-1287693.html

答案 1 :(得分:2)

当您在Windows上时,请确保您没有使用Powershell ISE。只需使用标准的Powershell。

正如@Boon所说,大多数错误都是来自Maya的插件和位,可以写得更好。

当你专注于学习编程时,你不需要那些插件。您可以从交互式Maya会话中禁用它们:

  1. 打开Maya。
  2. 选择Windows-&gt;设置/偏好设置 - &gt;插件管理器
  3. 关闭所有未插入的插件的“已加载”和“自动加载” 顶部:即Xgen,Bifrost,Substance,mtoa等。
  4. 关闭Maya。
  5. 现在再试一次你的shell:

    mayapy
    import maya.standalone
    maya.standalone.initialize()
    import pymel.core as pm
    

    此时,我看到有关Y-Up和一些Alembic版本信息的警告,没有别的。没有什么可担心的。

    提示符为>>>,这是一件好事。您现在应该能够输入pymel命令: 输入(一次查看一次输出):

    pm.about(version=True)
    pm.polySphere() 
    pm.ls(type="mesh")
    

    修改

    如果您使用PowerShell并设置了个人资料,则可以通过在个人资料中添加以下行来节省一些时间.p1:

    function ms { mayapy -i  -c "import maya.standalone;maya.standalone.initialize();import pymel.core as pm;print('maya standalone initialized and pymel.core imported as pm')" }
    

    现在您可以打开一个PowerShell,输入ms并开始编码。