代码之家  ›  专栏  ›  技术社区  ›  user8972552

如何使用python在maya的活动视图中显示/隐藏项目(?)?

  •  0
  • user8972552  · 技术社区  · 7 年前

    现在我知道了如何隐藏活动视口中的所有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)
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   DrWeeny    7 年前

    以下是隐藏所有内容的方法:

    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 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)