def add_reference(self, asset, proxy, visible): # Convert the asset object to an asset string using the "wizard.asset.main" module string_asset = asset_core.asset_to_string(asset) # Set the count to 1 by defaults count = 1 # Iterate the references list to check if this namespace already exists # Uses the function "get_namespace" to build the name space of the asset while self.get_name_space(asset, count) in self.references_list: # Convert the count int to a string with 4 characters # Example : # 1 > 0001 # 24 > 0024 # Uses the "zfill" string function count = str(int(count) + 1).zfill(4) # Build the name space using the "get_name_space" function name_space = self.get_name_space(asset, count) # Set the reference and return the count using the "set_reference" function return self.set_reference(string_asset, count, name_space, proxy, visible)
def save(): asset = asset_core.string_to_asset(os.environ[defaults._asset_var_]) asset.version = prefs.asset(asset).software.get_new_version() hou.hipFile.save(file_name=asset.file) string_asset = asset_core.asset_to_string(asset) os.environ[defaults._asset_var_] = string_asset send_signal.save_request_signal(asset.file, string_asset)
def replace_reference(self, asset, count, old_namespace=None, proxy=0, visible=1): # This function access the main references dictionnary and override the imported asset # Using the namespace key if old_namespace: if old_namespace in self.references_dic.keys(): del self.references_dic[old_namespace] if old_namespace in self.references_list: self.references_list.remove(old_namespace) # Build the name space using the "get_name_space" function # Iterate the references list to check if this namespace already exists # Uses the function "get_namespace" to build the name space of the asset while self.get_name_space(asset, count) in self.references_list: # Convert the count int to a string with 4 characters # Example : # 1 > 0001 # 24 > 0024 # Uses the "zfill" string function count = str(int(count) + 1).zfill(4) name_space = self.get_name_space(asset, count) # Convert the asset to a string using the "wizard.asset.main" module string_asset = asset_core.asset_to_string(asset) # Create an empty dictionnary to override the old one # Assign the differents variables to the namespace dictionnary # All the keys are stored in the "defaults" wizard module reference_dic = {} reference_dic[defaults._string_asset_] = string_asset reference_dic[defaults._count_] = count reference_dic[defaults._proxy_] = proxy reference_dic[defaults._visible_] = visible # If an old_namespace is given, delete it and # assign the new namespace dictionnary to the main references dictionnary # Assign the new namespace dictionnary to the main references dictionnary # The key is the new asset namespace self.references_dic[name_space] = reference_dic # Write the main references dictionnary to the ".prefs" file # Using the "prefs" wizard module self.asset_prefs.software.set_references(self.references_dic) # Return the namespace count return count
def set_current_asset(asset): string_asset = asset_core.asset_to_string(asset) os.environ[defaults._scene_current_asset_] = string_asset
def string_to_asset(string_asset): '''Convert a string object to an asset''' asset = asset_core.asset_to_string(string_asset) return asset
def asset_to_string(asset): '''Convert an asset object to a string''' string_asset = asset_core.asset_to_string(asset) return string_asset