2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

オブジェクトが非表示なのかどうか確認したい

2
Last updated at Posted at 2025-11-30

mayaにおいてオブジェクトの可視性を制御する方法はいくつかあると思いますがー

  • visibility / LOD visibility
  • 親ノードの visibility / LOD visibility
  • displayLayer

複雑なシーンで、上記どれかの方法で非表示になってるオブジェクトがあるとうっかり色々取りこぼしてしまいそうで

オブジェクトが表示状態なのか否かを調べてみようかと思います。

総当たり

オブジェクトの可視性制御は上記の3パターンだとして、総当たりで調べればまぁ解りますかね。

オブジェクトの

  • visibility を確認する
  • LOD visibility を確認する

displayLayerによる可視性の制御は オブジェクトのoverrideVisibilityをdisplayLayerで制御しているので

  • overrideVisibility を確認する

この3つを確認し、親ノードへ移動。
同じく3つを確認し また親ノードへ移動。

最上位にたどり着くまでに非表示状態のものがあったら、非表示!

import maya.cmds as cmds
import maya.api.OpenMaya as om2

def checkHierarchyVis(target):
	dagPath = om2.MGlobal.getSelectionListByName(target).getDagPath(0)
	fullpathName = om2.MFnDagNode(dagPath.node()).fullPathName()

	hierarchyParts = fullpathName.split("|")
	hierarchyParts.reverse()
	
	show = True
	
	for node in hierarchyParts:		
		checkAttr = [
			"visibility",
			"lodVisibility",
			"overrideVisibility"
		]
		
		for attr in checkAttr:
			if cmds.getAttr(node + "." + attr) == False:
				return False

	return True
	
checkHierarchyVis("pSphere1")

こんな感じのサンプルデータを作ってみました。

image.png

displayLayerで消してみました。
image.png

checkHierarchyVis("pSphere1")
# Result: False

親ノードをhideしてみました。
image.png

checkHierarchyVis("pSphere1")
# Result: False

機能してそうですねー。

別の方法

なんかないかなー とAPIをぬぼーっと流し見してみたら

なんかありました。

def OpenMaya.MDagPath.isVisible ()
Returns true if the DAG Node at the end of the path is visible.

こんな感じですかねー

import maya.cmds as cmds
import maya.api.OpenMaya as om2

def isShow(target):    
    mesh_dagPath = om2.MGlobal.getSelectionListByName(target).getDagPath(0)
    return mesh_dagPath.isVisible()

image.png

isShow("pSphere1")
# Result: False

image.png

isShow("pSphere1")
# Result: False

あーこっちでも行けそうですねー

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?