统计
  • 建站日期:2021-03-10
  • 文章总数:32 篇
  • 评论总数:5 条
  • 分类总数:9 个
  • 最后更新:7月9日
文章 Houdini

houdini 快速找到选择物体材质球(ar mr rs )

Luo7758
首页 Houdini 正文

一.跳转到材质

#Import Modules
import toolutils
import hou

#Set Variables
selected_node = ""

#Define type arrays
MAT_Detect = ["redshift::Material","redshift_vopnet","principledshader::2.0","materialbuilder","arnold::standard_surface", "arnold_materialbuilder"]
Sel_Detect = ["geo","instance"]

#Get the Selected Nodes
selected = hou.selectedNodes()

#Check if there is something selected 
if selected:
    #Compare first selected objects type with the valid object types
    if selected[0].type().name() in Sel_Detect:
        #Set the selected node. Just the fist is valid
        selected_node = selected[0]
    #Force the user to select an object, if the current doesn't match the selection type
    else:
        #Clear the selection
        hou.clearAllSelected() 
        #Promt the user to select an new object
        prompt = toolutils.selectionPrompt(hou.objNodeTypeCategory())
        scene_viewer = toolutils.sceneViewer() 
        selected_objects = scene_viewer.selectObjects(prompt)
        #Check if an object is selected
        if selected_objects:
            #Set the first selected node to variable
            selected_node = selected_objects[0]
        else:
            #Output an Error
            hou.ui.displayMessage("Nothing Selected")    
#Force the user to select an object, because nothing is selected
else:
    #Promt the user to select an new object
    prompt = toolutils.selectionPrompt(hou.objNodeTypeCategory())
    scene_viewer = toolutils.sceneViewer() 
    selected_objects = scene_viewer.selectObjects(prompt)
    #Check if an object is selected
    if selected_objects:
        #Set the first selected node to variable
        selected_node = selected_objects[0]
    else:
        #Output an Error
        hou.ui.displayMessage("Nothing Selected")

#Check if the selected_node variable is not empty
if selected_node:
    #Compare selected_node's type with the valid object types
    if selected_node.type().name() not in MAT_Detect :
        #Convert Releative Pathes to Absolute Pathes
        matPath = selected_node.parm("shop_materialpath").eval()
        #Set the targetpath to the node variable
        node = selected_node.node(matPath)
        #Check if node is valid
        if node:
            #Look for child Objects
            if node.children():
                #If there are children, replace node with the fist child
                node = node.children()[0]
        else:
            #Output an Error
            hou.ui.displayMessage("Empty material path")

    else:
        node = selected_node
        #Look for child Objects
        if node.children():
            node = node.children()[0]

    #Check if the material node exists
    if node:        
        #Set some Variables
        pane = ""
        index = 0
        #Loop over the active panes
        while pane is not None:
            #Search for the first network editor
            pane = hou.ui.paneTabOfType(hou.paneTabType.NetworkEditor, index) 
            #Loop over the panes
            if pane is not None:
                #Get the current state
                ID = pane.linkGroup()
                #Looking for Linkgroup1
                if str(ID) == "paneLinkType.Group1":
                    targetPane = pane
                    switchorselect = 1
                #Looking for FollowSelection
                if str(ID) == "paneLinkType.FollowSelection":
                    targetPane = pane
                    switchorselect = 0
                #Looking for Pinned
                if str(ID) == "paneLinkType.Pinned":
                    targetPane = pane
                    switchorselect = 2
            index += 1

        #If there is a PaneType Group1 
        if switchorselect == 1:
            #Set the current Node
            targetPane.setCurrentNode(node)
        #If the PaneTypeState is set to Follow selection
        if switchorselect == 0:
            #Selet the material
            node.setSelected(True, clear_all_selected=True)
        #If the PaneTypeState is set to Pinned
        if switchorselect == 2:
            #Retun an errror
            hou.ui.displayMessage("The PaneType is set to Pinned")

二. 选择当前节点跳转到引用此节点参数的节点

sel = hou.selectedNodes()[0]
sel.setSelected(False)
ref = sel.parmsReferencingThis()
if len(ref) == 1:
    target = ref[0].node()
elif len(ref) >1:
    list = []
    for i in ref:
        list.append(i.node().path())
    path = hou.ui.selectFromList(list, message='to Jamp referencing Node')
    print (path)
    target = ref[path[0]].node()
else:
    target = sel
target.setSelected(True)
p = hou.ui.paneTabOfType(hou.paneTabType.NetworkEditor)
p.setCurrentNode(target)
p.homeToSelection()

版权说明
文章采用: 《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权。
版权声明:未标注转载均为本站原创,转载时请以链接形式注明文章出处。如有侵权、不妥之处,请联系站长删除。敬请谅解!

-- 展开阅读全文 --
这篇文章最后更新于2022-8-10,已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!
如何利用vscode 写 Markdown笔记
« 上一篇
carbon学习之路(一)
下一篇 »

发表评论

已有 1 条评论

  1. silence V管理员

    说道:顶呱呱

HI ! 请登录
注册会员,享受下载全站资源特权。
暂不提供社交账号登录

今日事今日毕

标签

热门文章

3
Houdini vellum 学习 - 01
4
carbon学习之路(一)
5
Houdini vellum 学习 - 02