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

2024-04-29 16:40:15 发布

您现在位置:Python中文网/ 问答频道 /正文

现在我知道如何隐藏活动视口上的所有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)

Tags: 项目importtruefor菜单事情曲线栅格
1条回答
网友
1楼 · 发布于 2024-04-29 16:40:15

下面是一种隐藏一切的方法:

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)

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

^{pr2}$

但如果我是你,我会把它封装成一个定义:

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)

相关问题 更多 >