paste script.

   2212   4   1
User Avatar
Member
193 posts
Joined: 12月 2016
Offline
Hello, I've been working on a paste script that's a bit more advanced than the one circulating on the internet right now.


It that checks the context you are pasting in and the type of node you are trying to paste in some cases.

For example, it will paste copied nodes in geo level as sop imports when pasting in lops and it wil paste cop networks as an image node when working in a materialXSubnet.

I bind it to ctrl + shift + v


Below is the code. It's not optimized, but it works.




#should refactor with only the node being created in the a forloop



import hou

network = hou.ui.curDesktop().paneTabUnderCursor()
networkpath = network.pwd().path()
pos = network.cursorPosition()

clipboard = hou.ui.getTextFromClipboard()

context = hou.node(networkpath)

n = 0

shader = 0

# shader types
#     0 = null error
#     1 = mtlx



print("context       : " +context.type().name())
print("contextparent : " +context.parent().type().name())

if clipboard:
    list = clipboard.split()
    print("____")
    for item in list:
        n += 1
        print(n)
    n=0
    #for using cops in shaders
    entry = hou.node(list[0])
    print(hou.node(list[0]).type().name())
    print(entry.parent().type().name())
    
    #check if cop node
    if entry.parent().type().name() == 'cop2net' or entry.parent().type().name() == 'img' and hou.node(list[0]) != None:
        
    #check if in shading context
        if context.parent().type().name() == 'materiallibrary' or context.parent().type().name() == 'mat':
            for item in list:
                if hou.node(item) != None:
                    
                    #check chader type
                    
                    for child in context.children():
                        #print (child)
                        name = str(child)
                        #print (name)
                        if hou.patternMatch("*tlx*", name):
                            shader = 1
                    
                    
                    #create node
                    
                    if shader == 1:
                        if hou.node(item) != None:
                                node = hou.node(networkpath).createNode('mtlximage','merge_'+item.split('/')[-1])
                                node.parm('file').set('op:'+str(item))
                                node.setPosition(pos)
                                node.move([n*1,-0.9*n])
                                if n == 0:
                                    node.setSelected(True,True)
                                else:
                                    node.setSelected(True,False)
                                n = n + 1

                            
                            
                            
                            
                            
    #for geo context
    elif context.type().name() == 'geo' or context.type().name() == 'sopnet' or context.type().name() == 'sopsolver::2.0':
        for item in list:
            if hou.node(item) != None:
                merge = hou.node(networkpath).createNode('object_merge','merge_'+item.split('/')[-1])
                merge.parm('objpath1').set(str(item))
                merge.setPosition(pos)
                merge.move([n*1,-0.9*n])
                if n == 0:
                    merge.setSelected(True,True)
                else:
                    merge.setSelected(True,False)
                n = n + 1


    #for lop context
    elif context.type().name() == 'stage':
        print('in stage')
        for item in list:
            if hou.node(item) != None:
                sopimport = hou.node(networkpath).createNode('sopimport','merge_'+item.split('/')[-1])
                sopimport.parm('soppath').set(str(item))
                sopimport.setPosition(pos)
                sopimport.move([n*1,-0.9*n])
                if n == 0:
                    sopimport.setSelected(True,True)
                else:
                    sopimport.setSelected(True,False)
                n = n + 1
    else:
        print('no logic setup')
n = 0


print("__________________________________________________")
Edited by NicTanghe - 2022年12月16日 16:50:22
User Avatar
Member
679 posts
Joined: 2月 2017
Offline
Hey NicTanghe,

Thank you for sharing. Could you explain where and when to use it?
Excuse my ignorance!

Cheers
CYTE
User Avatar
Member
193 posts
Joined: 12月 2016
Offline
Updated the discription
User Avatar
Member
44 posts
Joined: 3月 2023
Offline
here is paste script
User Avatar
Member
44 posts
Joined: 3月 2023
Offline
Updated the script so it actualy works in subnets now.
Stil needs updating for pasting lop nodes in sop context.
as wel as cleaning up the naming

#should refactor with only the node being created in the a forloop



import hou

pane = hou.ui.curDesktop().paneTabUnderCursor()
network = pane.pwd()
networkpath = network.path()
pos = pane.cursorPosition()

clipboard = hou.ui.getTextFromClipboard()

context = hou.node(networkpath)
type = network.type()

stype = 0

print("type : " + str(type.name()))
if network:
    if str(type.name())=="subnet":
        for child_node in network.children():
            if isinstance(child_node, hou.SopNode):
                print("This is a SOP subnet.")
                stype = 1
                break
            elif isinstance(child_node, hou.LopNode):
                stype = 2
                print("This is a LOP subnet.")
                break
            elif isinstance(child_node, hou.Cop2Node):
                print("This is a COP subnet.")
                stype = 3
                break
        else:
            print("This subnet does not contain a SOP, LOP, or COP network.")
    else:         
        print("This is not a subnet.")
else:
    print("Node not found.")


n = 0
shader = 0

if clipboard:
    list = clipboard.split()
    print("____")
    for item in list:
        n += 1
        print(n)
    n=0
    if hou.node(list[0]) is not None:
        #for using cops in shaders
        entry = hou.node(list[0])
        
        #check if cop node
        if entry.parent().type().name() == 'cop2net' or entry.parent().type().name() == 'img' and hou.node(list[0]) != None:
            
        #check if in shading context
            if context.parent().type().name() == 'materiallibrary' or context.parent().type().name() == 'mat' or stype == 3:
                for item in list:
                    if hou.node(item) != None:
                        
                        #check chader type
                        
                        for child in context.children():
                            #print (child)
                            name = str(child)
                            #print (name)
                            if hou.patternMatch("*tlx*", name):
                                shader = 1
                        
                        
                        #create node
                        
                        if shader == 1:
                            if hou.node(item) != None:
                                    node = hou.node(networkpath).createNode('mtlximage','merge_'+item.split('/')[-1])
                                    node.parm('file').set('op:'+str(item))
                                    node.setPosition(pos)
                                    node.move([n*1,-0.9*n])
                                    if n == 0:
                                        node.setSelected(True,True)
                                    else:
                                        node.setSelected(True,False)
                                    n = n + 1
    
                                
                                
                                
                                
                                
        #for sop context
        elif context.type().name() == 'geo' or context.type().name() == 'sopnet' or context.type().name() == 'sopsolver::2.0' or stype == 1:
            for item in list:
                if hou.node(item) != None:
                    merge = hou.node(networkpath).createNode('object_merge','merge_'+item.split('/')[-1])
                    merge.parm('objpath1').set(str(item))
                    merge.setPosition(pos)
                    merge.move([n*1,-0.9*n])
                    if n == 0:
                        merge.setSelected(True,True)
                    else:
                        merge.setSelected(True,False)
                    n = n + 1
    
    
        #for lop context
        elif context.type().name() == 'stage' or stype == 2:
            print('in stage')
            for item in list:
                if hou.node(item) != None:
                    sopimport = hou.node(networkpath).createNode('sopimport','merge_'+item.split('/')[-1])
                    sopimport.parm('soppath').set(str(item))
                    sopimport.setPosition(pos)
                    sopimport.move([n*1,-0.9*n])
                    if n == 0:
                        sopimport.setSelected(True,True)
                    else:
                        sopimport.setSelected(True,False)
                    n = n + 1
        else:
            print('no logic setup')
    n = 0
    
    
    print("__________________________________________________")
Edited by nicolaas.tanghe - 2023年4月6日 15:33:02
  • Quick Links