【问题标题】:How to show/hide items(?) in active view on maya with python?如何使用python在maya的活动视图中显示/隐藏项目(?)?
【发布时间】:2023-04-01 10:22:01
【问题描述】:

现在我知道如何隐藏活动视口上的所有 nurbs 曲线了。但是,我怎样才能同时对视口上显示菜单上的所有项目(如相机、操纵器、网格......等)做同样的事情?

我认为我需要为此使用 for 循环,但我需要一些指导。谢谢。

import maya.cmds as cmds

actView = cmds.getPanel(wf=True)

if cmds.modelEditor(actView, q=True, nurbsCurves=True) == 1:
    cmds.modelEditor(actView, e=True, nurbsCurves=False)

【问题讨论】:

    标签: python hide show maya


    【解决方案1】:

    这是一种隐藏一切的方法:

    actView = cmds.getPanel(wf=True) # actView='modelPanel4'
    # list the flag we use to hide, not that alo hide nearly everything
    hide_attrs = ['alo', 'manipulators', 'grid', 'hud', 'hos', 'sel']
    # value is used to make visible or to hide (0 is for hiding)
    value = 0
    # flags is used to create a dictionary that will be used in the command to do : manipulators = 0
    flags = { i : value for i in hide_attrs }
    # the double star unpack a python dictionnary the key = value, i.e in this case : alo = 0, hud = 0....
    cmds.modelEditor(actView, e=1, **flags)
    

    如果你想更具体,你可以为可见属性构建另一个字典

    # merge dictionnaries
    def merge_two_dicts(x, y):
        # In Python 3.5 or greater, : z = {**x, **y}
        # or w = {'foo': 'bar', 'baz': 'qux', **y}
    
        z = x.copy()  # start with x's keys and values
        z.update(y)  # modifies z with y's keys and values & returns None
        return z
    
    actView = cmds.getPanel(wf=True) # actView='modelPanel4'
    hide_attrs = ['alo', 'manipulators', 'grid', 'hud', 'hos']
    vis_attrs = ['sel']
    hide_flags = { i : 0 for i in hide_attrs }
    vis_flags = { i : 1 for i in vis_attrs }
    flags = merge_two_dicts(hide_flags, vis_flags)
    cmds.modelEditor(actView, e=1, **flags)
    

    但如果我是你,我会把它封装到一个 def 中:

    def set_actviewVis(value, attrs=list):
        actView = cmds.getPanel(wf=True) # actView='modelPanel4'    
        flags = { i : value for i in attrs }
        cmds.modelEditor(actView, e=1, **flags)
    
    hide_attrs = ['alo', 'manipulators', 'grid', 'hud', 'hos']
    set_actviewVis(0, hide_attrs)
    vis_attrs = ['sel']
    set_actviewVis(1, vis_attrs)
    

    【讨论】:

      猜你喜欢
      • 2011-06-01
      • 2011-01-11
      • 2015-12-24
      • 1970-01-01
      • 2015-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多