def getNodeType(self): ''' get the selected node type ''' # Note a special treatment of backticks (bash specifics) # cmd = ''' %s "optype -t opfind -N \"/\"\`opselectrecurse(\\"/\\",0)\`" ''' % self.hcommand # This is just a regular hscript command you would launch from hscript shell in houdini hscriptCmd = r'''optype -t opfind -N /`opselectrecurse("/",0)''' # hscriptCmd = r'''optype -t opfind -N "/"opselectrecurse("/",0)''' # change on WIN if os.name=='posix': hscriptCmd = subPorts.escape(hscriptCmd, 1) else: hscriptCmd = subPorts.escape(hscriptCmd, 2) # dont escape backticks in a shell # the command gets wrapped with double-quates - required by bash # and prepanded with full path hcommand cmd = r'''%s "%s"''' % (self.hcommand,hscriptCmd) print ("CMD getNodeType:", cmd) p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) cmd_stdout, cmd_stderr = p.communicate() selection = None selection = cmd_stdout.decode('ascii').strip() if selection == '': print ("=== nothing selected ===") print ("Node type: " ,selection) return selection
def getCodeAsText(self): ''' Introduce escape characters to avoid misinterpretation by the shell ''' view = self.window.active_view() codeText = view.substr(sublime.Region(0, view.size())) # Treat \n in the strings differently then new lines at the end of the line temp = [] textSplited = re.split('((?s)".*?")', codeText) for x in textSplited: if os.name=='posix': x = subPorts.escape(x) else: x = subPorts.escape(x,3) # WIN - code as text temp.append(x) codeText = r''.join(temp) ''' this command works from the bash hcommand 2223 "opparm /obj/geo1/python1 python \"print \\"______cccB\\" \" " ^ ^ ^ ^ queue single escape quote | | double escape ''' return codeText
def hdaRun(self,choice,hdaOptions,tunnel,tableAndOpName): # Currently there is no support for the vex context in vex HDA SOP if choice!=-1: # -1 is set when pressed ESC hscriptCmd = r'''otcontentadd %s %s %s''' % (tableAndOpName, hdaOptions[choice], tunnel.filePath) # Hscript command hscriptCmd = subPorts.escape(hscriptCmd, 1) cmd = r'''%s "%s"''' % (tunnel.hcommand,hscriptCmd) print ("CMD - HDA update",cmd) p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
def getNodePath(self): ''' get the node path ''' # cmd = ''' %s "opfind -N \"/\"\`opselectrecurse(\\"/\\",0)\`" ''' % self.hcommand # no space between \"/\"\`o # cmd = r''' %s "opfind -N "/"\`opselectrecurse(\"/\",0)\`" ''' % self.hcommand # raw works too hscriptCmd = r'''opfind -N "/"`opselectrecurse("/",0)''' # Hscript command if os.name=='posix': hscriptCmd = subPorts.escape(hscriptCmd, 1) else: hscriptCmd = subPorts.escape(hscriptCmd, 2) cmd = r'''%s "%s"''' % (self.hcommand,hscriptCmd) print ("CMD getNodePath:", cmd) p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) cmd_stdout, cmd_stderr = p.communicate() nodePath = cmd_stdout.decode('ascii').strip() print ("Node path: " ,nodePath) return nodePath