def _save_scene_or_use_current():
    """Manual save-scene flow.

    When user chooses to save, they get a dialog to choose a
    name. When he chooses to use-current, just make sure the
    file exists.
    """
    fn = hou.hipFile.path()
    save_file_response = hou.ui.displayMessage(
        title='Unsaved changes',
        text="What would you like to do?",
        buttons=(
            "Save and submit",
            "Submit existing scene",
            "Cancel"),
        close_choice=2)
    if save_file_response == 2:
        return None
    if save_file_response == 0:
        fn = hou.ui.selectFile(
            start_directory=os.path.dirname(hou.hipFile.path()),
            title="Save",
            file_type=hou.fileType.Hip,
            pattern="*.hip,*.hiplc,*.hipnc,*.hip*",
            default_value=hou.hipFile.basename(),
            chooser_mode=hou.fileChooserMode.Write)
        if fn:
            hou.hipFile.save(file_name=fn)
    if save_file_response == 1:

        hou.findFile(fn)

    return fn
Beispiel #2
0
def _file_exists(filename):
    """Does it exist and is it a file?"""
    if not filename:
        return False
    try:
        hou.findFile(filename)
        return True
    except hou.OperationFailed:
        return False
def _file_exists(filename):
    """Does it exist and is it a file?"""
    if not filename:
        return False
    try:
        hou.findFile(filename)
        return True
    except hou.OperationFailed:
        return False
def get_config_file():

    try:
        return hou.findFile("ExternalEditor.cfg")
    except hou.OperationFailed:
        return os.path.join(hou.expandString("$HOUDINI_USER_PREF_DIR"),
                            "ExternalEditor.cfg")
Beispiel #5
0
  def get_dependencies(frame_begin, frame_end, step):
    """Finds all file dependencies in the project for specific range of frames.

    Args:
      frame_begin: First frame (inclusive) of range to render.
      frame_end: Last frame (inclusive) of range to render.
      step: Frame range step.

    Returns:
      set of str, List of detected dependencies.
    """
    refs = hou.fileReferences()
    frames = xrange(int(frame_begin), int(frame_end) + 1, int(step))

    result = set()

    wildcards = ['<udim>', '$SF']
    wildcard_regex = [re.compile(re.escape(wc), re.IGNORECASE)
                      for wc in wildcards]

    for frame in frames:
      for parm, _ in refs:
        if parm:
          file_path = parm.evalAtFrame(frame)
          if file_path in result:
            continue
          for wildcard in wildcard_regex:
            file_path = wildcard.sub('*', file_path)
          for file in glob.glob(file_path):
            try:
              if hou.findFile(file) and file not in result:
                result.add(file)
            except hou.OperationFailed:
              pass
    return result
  def get_dependencies(frame_begin, frame_end, step):
    """Finds all file dependencies in the project for specific range of frames.

    Args:
      frame_begin: First frame (inclusive) of range to render.
      frame_end: Last frame (inclusive) of range to render.
      step: Frame range step.

    Returns:
      set of str, List of detected dependencies.
    """
    refs = hou.fileReferences()
    frames = xrange(int(frame_begin), int(frame_end) + 1, int(step))

    result = set()
    for frame in frames:
      for parm, _ in refs:
        if parm:
          file_path = parm.evalAtFrame(frame)
          if file_path in result:
            continue
          try:
            if hou.findFile(file_path):
              result.add(file_path)
          except hou.OperationFailed:
            pass
    return result
    def _processValue(self):
        # Skip normal types.
        if isinstance(self.value, (bool, float, int)):
            return

        # Don't do anything if the property isn't enabled.
        if not self.enabled:
            return

        # If the object is a list of only one entry, extract it.
        if len(self.value) == 1:
            self.value = self.value[0]

        # If the value is actually a relative file, search for it in the
        # Houdini path.
        if self.findFile:
            self.value = hou.findFile(self.value)

        # Object is a list (possibly numbers or strings or both).
        if isinstance(self.value, list):
            # Does the list contain any strings.
            containsStrings = False

            for val in self.value:
                # If the value is a string, flag it.
                if isinstance(val, str):
                    containsStrings = True
                    break

            # If at least one value is a string then we need to convert them
            # all to strings.
            if containsStrings:
                self.value = [str(val) for val in self.value]
Beispiel #8
0
def build_pyfilter_command(pyfilter_args=None, pyfilter_path=None):
    """Build a PyFilter -P command.

    :param pyfilter_args: Optional list of args to pass to the command.
    :type pyfilter_args: list(str)
    :param pyfilter_path: Optional path to the filter script.
    :type pyfilter_path: str
    :return: The constructed PyFilter command.
    :rtype: str

    """
    import hou

    if pyfilter_args is None:
        pyfilter_args = []

    # If no path was passed, use the one located in the package.
    if pyfilter_path is None:
        try:
            pyfilter_path = hou.findFile("pyfilter/ht-pyfilter.py")

            # If we can't find the script them log an error and return nothing.
        except hou.OperationFailed:
            logger.error("Could not find pyfilter/ht-pyfilter.py")

            return ""

    # Ensure the script path exists.
    if not os.path.exists(pyfilter_path):
        raise OSError("No such file: {}".format(pyfilter_path))

    cmd = '-P "{} {}"'.format(pyfilter_path, " ".join(pyfilter_args))

    return cmd
Beispiel #9
0
def build_pyfilter_command(pyfilter_args=None, pyfilter_path=None):
    """Build a PyFilter -P command.

    :param pyfilter_args: Optional list of args to pass to the command.
    :type pyfilter_args: list(str)
    :param pyfilter_path: Optional path to the filter script.
    :type pyfilter_path: str
    :return: The constructed PyFilter command.
    :rtype: str

    """
    import hou

    if pyfilter_args is None:
        pyfilter_args = []

    # If no path was passed, use the one located in the package.
    if pyfilter_path is None:
        try:
            pyfilter_path = hou.findFile("pyfilter/ht-pyfilter.py")

            # If we can't find the script them log an error and return nothing.
        except hou.OperationFailed:
            _logger.error("Could not find pyfilter/ht-pyfilter.py")

            return ""

    # Ensure the script path exists.
    if not os.path.exists(pyfilter_path):
        raise OSError("No such file: {}".format(pyfilter_path))

    cmd = '-P "{} {}"'.format(pyfilter_path, " ".join(pyfilter_args))

    return cmd
Beispiel #10
0
    def _processValue(self):
        """Perform operations and cleanup of the value data."""
        # Skip normal types.
        if isinstance(self.value, (bool, float, int)):
            return

        # Don't do anything if the property isn't enabled.
        if not self.enabled:
            return

        # If the object is a list of only one entry, extract it.
        if len(self.value) == 1:
            self.value = self.value[0]

        # If the value is actually a relative file, search for it in the
        # Houdini path.
        if self.find_file:
            self.value = hou.findFile(self.value)

        # Object is a list (possibly numbers or strings or both).
        if isinstance(self.value, list):
            # Does the list contain any strings.
            contains_string = False

            for val in self.value:
                # If the value is a string, flag it.
                if isinstance(val, str):
                    contains_string = True
                    break

            # If at least one value is a string then we need to convert them
            # all to strings.
            if contains_string:
                self.value = [str(val) for val in self.value]
Beispiel #11
0
def _findFile():
    # Try to find the file.
    try:
        filePath = hou.findFile("config/gcs.json")

    # Catch the exception if the file couldn't be found and use None.
    except hou.OperationFailed:
        filePath = None

    return filePath
Beispiel #12
0
def _findFile():
    # Try to find the file.
    try:
        filePath = hou.findFile("config/gcs.json")

    # Catch the exception if the file couldn't be found and use None.
    except hou.OperationFailed:
        filePath = None

    return filePath
Beispiel #13
0
    def __init__(self, name, property_block):
        self._name = name

        # Store the raw value object.
        self._value = property_block["value"]

        self._find_file = property_block.get("findfile", False)
        self._rendertype = property_block.get("rendertype")

        if self.find_file:
            import hou
            self._value = hou.findFile(self.value)
Beispiel #14
0
def buildPyFilterCommand(node):
    """Construct the mantra command with PyFilter."""
    import hou

    try:
        script_path = hou.findFile("pyfilter/customPyFilter.py")

    # If we can't find the script them log an error and return nothing.
    except hou.OperationFailed:
        logger.error("Could not find pyfilter/customPyFilter.py")

        return ""

    # Build the wrapped -P command with out script and arg string.
    cmd = '-P "{} {}"'.format(script_path, buildArgStringFromNode(node))

    return cmd
def get_config_file():

    try:
        return hou.findFile("externaleditor.pref")
    except hou.OperationFailed:
        
        ver = hou.applicationVersion()
        if sys.platform in ["darwin", "os2", "os2emx"]:
            verStr = "{}.{}".format(ver[0], ver[1])
        else:
            verStr = "houdini{}.{}".format(ver[0], ver[1])

        cfg_root = hou.expandString("$HOME") + os.sep + verStr
        if not os.path.exists(cfg_root):
            os.makedirs(cfg_root)

        cfg = cfg_root + os.sep + "externaleditor.pref"

        return cfg
Beispiel #16
0
def get_houdini_app(dev=None, config_file=None, config_obj=None, **kwargs):
    # If dev is None, that means try to detect the environment
    if dev is None:
        dev = is_dev()

    # Choose a different config class based on dev
    if not config_obj:
        config_obj = HoudiniDevConfig if dev else HoudiniAppConfig

    # If the caller didn't specify an explict config file, and hou is availabe,
    # use findFile to find a config file in the Houdini path
    if not config_file and hou:
        try:
            config_file = hou.findFile("config/Help/bookish.cfg")
        except hou.OperationFailed:
            pass

    configure_app(config_obj=config_obj, config_file=config_file, **kwargs)
    return app
Beispiel #17
0
def buildPyFilterCommand(node):
    """Construct the mantra command with PyFilter."""
    import hou

    try:
        script_path = hou.findFile("pyfilter/customPyFilter.py")

    # If we can't find the script them log an error and return nothing.
    except hou.OperationFailed:
        logger.error("Could not find pyfilter/customPyFilter.py")

        return ""

    # Build the wrapped -P command with out script and arg string.
    cmd = '-P "{} {}"'.format(
        script_path,
        buildArgStringFromNode(node)
    )

    return cmd
Beispiel #18
0
    def get_dependencies(frame_begin, frame_end, step):
        """Finds all file dependencies in the project for specific range of frames.

    Args:
      frame_begin: First frame (inclusive) of range to render.
      frame_end: Last frame (inclusive) of range to render.
      step: Frame range step.

    Returns:
      set of str, List of detected dependencies.
    """
        refs = hou.fileReferences()
        frames = xrange(int(frame_begin), int(frame_end) + 1, int(step))

        result = set()

        wildcards = ['<udim>', '$SF']
        wildcard_regex = [
            re.compile(re.escape(wc), re.IGNORECASE) for wc in wildcards
        ]

        for frame in frames:
            for parm, _ in refs:
                if parm:
                    file_path = parm.evalAtFrame(frame)
                    if file_path in result:
                        continue
                    for wildcard in wildcard_regex:
                        file_path = wildcard.sub('*', file_path)
                    for file in glob.glob(file_path):
                        try:
                            if hou.findFile(file) and file not in result:
                                result.add(file)
                        except hou.OperationFailed:
                            pass
        return result
Beispiel #19
0
	def getHQueueCommands(remote_hfs, num_cpus=0):
		"""Return the dictionary of commands to start hython, Python, and mantra.
		Return None if an error occurs when reading the commands
		from the HQueueCommands file.
		If `num_cpus` is greater than 0, then we add a -j option
		to each command so that the application is run with a maximum
		number of threads.
		"""
		import hou
		# HQueueCommands will exist in the Houdini path.
		cmd_file_path = hou.findFile(
			"soho/python%d.%d/HQueueCommands" % sys.version_info[:2])
	
		hq_cmds = {}
		cmd_file = open(cmd_file_path, "r")
		cmd_name = None
		cmds = None
		continue_cmd = False
		for line in cmd_file:
			line = line.strip()
	
			# Check if we need to continue the current command.
			if continue_cmd:
				# Add line to current command.
				cmds = _addLineToCommands(cmds, line)
				if line[-1] == "\\":
					continue_cmd = True
				else:
					cmds = _finalizeCommands(cmd_name, cmds, remote_hfs, num_cpus)
					if cmds is None:
						return None
					hq_cmds[cmd_name] = cmds
					continue_cmd = False
				continue
	
			# Ignore comments and empty lines.
			if line.startswith("#") or line.strip() == "":
				continue
	
			# Ignore lines with no command assignment.
			eq_op_loc = line.find("=")
			if eq_op_loc < 0:
				continue
	
			# Start a new command.
			cmd_name = line[0:eq_op_loc].strip()
			cmds = None
			line = line[eq_op_loc+1:]
	
			# Add line to current command.
			cmds = _addLineToCommands(cmds, line)
			if line[-1] == "\\":
				continue_cmd = True
			else:
				cmds = _finalizeCommands(cmd_name, cmds, remote_hfs, num_cpus)
				if cmds is None:
					return None
				hq_cmds[cmd_name] = cmds
				continue_cmd = False
	
		return hq_cmds