Maya(含2018)如何用Python切换‘ignore hidden in outliner’标志?
Got it, let's break this down—this is a common gotcha when scripting Maya's outliner, especially since the property names aren't always intuitive. I’ve run into this exact issue before, so here’s how to fix it:
The Core Problem
You’re trying to control the outliner’s "Ignore Hidden in Outliner" toggle, which overrides the hiddenInOutliner property on individual nodes (like your hid node). The confusion usually comes from mixing up panel-level settings with node-level settings, or using the wrong command/property name.
Step 1: Target the Correct Outliner Panel
First, you need to make sure you’re referencing the right outliner panel. If you’re working with the active outliner, you can grab it dynamically; if you know the panel name (like outlinerPanel1), you can hardcode it:
import maya.cmds as cmds # Get the currently focused outliner panel (falls back to default if none is focused) active_outliner = cmds.getPanel(withFocus=True) if not active_outliner.startswith("outliner"): active_outliner = "outlinerPanel1" # Default outliner panel name
Step 2: Toggle the "Ignore Hidden" Setting
The outliner’s "Ignore Hidden in Outliner" option maps directly to the showHidden property in the outlinerEdit command. Here’s how to toggle it, or set it explicitly:
Toggle the setting on/off
# Check current state of the "Ignore Hidden" option current_state = cmds.outlinerEdit(active_outliner, query=True, showHidden=True) # Flip the state cmds.outlinerEdit(active_outliner, edit=True, showHidden=not current_state)
Force enable/disable the setting
# Enable "Ignore Hidden in Outliner" (shows nodes marked as hidden) cmds.outlinerEdit(active_outliner, edit=True, showHidden=True) # Disable "Ignore Hidden in Outliner" (hides nodes marked as hidden) cmds.outlinerEdit(active_outliner, edit=True, showHidden=False)
Why You Might Have Been Stuck
- Wrong command: Using
outlinerPanelinstead ofoutlinerEdit—the former is for creating/managing panels, while the latter edits their display settings. - Misnamed property: The toggle isn’t called something obvious like
ignoreHidden—it’sshowHidden, whereTruemeans "show hidden nodes" (i.e., ignore theirhiddenInOutlinerflag), andFalsemeans "respect the node’s hidden flag".
Testing with Your Example
For your hid node:
- If
cmds.getAttr("hid.hiddenInOutliner")returnsTrue, but the outliner hasshowHidden=True, the node will stay visible. - Running
cmds.outlinerEdit(active_outliner, edit=True, showHidden=False)will immediately hide thehidnode, since the outliner now respects its hidden flag.
内容的提问来源于stack exchange,提问作者winteralfs

