def _translate_file(self, source_path, target_path, item): _rootNode = vrScenegraph.getRootNode() vrNodePtr = None for _n in range(0, _rootNode.getNChildren()): _childNode = _rootNode.getChild(_n) if _childNode.getType() == "Geometry": if (_childNode.getName() == item.name and _childNode.fields().getID() == item.properties["node_id"]): vrNodePtr = _childNode break if vrNodePtr is None: e = "Failed to Get Node " + item.name self.logger.error("Error ocurred {!r}".format(e)) raise Exception("Error ocurred {!r}".format(e)) else: # Save file to publish path try: vrFileIO.saveGeometry(vrNodePtr, target_path) except: e = ("Failed to save Node ( " + item.name + " )Geometry OSB file for " + target_path) self.logger.error("Error ocurred {!r}".format(e)) raise Exception("Error ocurred {!r}".format(e))
def init(self): engine = sgtk.platform.start_engine("tk-vred", self.context.sgtk, self.context) # Set the version text in the plugin dialog once the engine is initialized self.version_label.setText("tk-vred {}".format(engine.version)) file_to_open = os.environ.get("SGTK_FILE_TO_OPEN", None) if file_to_open: vrFileIO.load( [file_to_open], vrScenegraph.getRootNode(), newFile=True, showImportOptions=False, )
def get_geometry_nodes(): """ Returns all the geometry nodes of the current VRED scene :return: A list of VRED geometry nodes :rtype: list """ root_node = vrScenegraph.getRootNode() node_list = [] for n in range(0, root_node.getNChildren()): child_node = root_node.getChild(n) if child_node.getType() != "Geometry": continue node_list.append(child_node) return node_list
def create_reference(self, path): if not os.path.exists(path): raise Exception("File not found on disk - '%s'" % path) self.load_file([path], vrScenegraph.getRootNode(), False, False)
def _load_for_review(self, sg_data, confirm_action=False): """ Find an associated published file from the entity defined by the `sg_data`, and load it into VRED. :param sg_data: The ShotGrid data for the entity to load for review. :type sg_data: dict :param confirm_action: True will ask the user to confirm executing this action, or False to execute the action immediately. :type confirm_action: bool :return: True for success, else False :rtype: bool """ # The current entity. This entity dictionary will be the return value to # trigger a context change in SG Panel to this entity. entity = {"type": sg_data["type"], "id": sg_data["id"]} # Load for review action only supports Version entity type if sg_data["type"] != "Version": return True # Ask the user if they want to proceed with loading the Version for review. if confirm_action: answer = QtGui.QMessageBox.question( None, "Load for Review?", "Do you want to load this {} for review?".format( sg_data["type"]), QtGui.QMessageBox.Yes | QtGui.QMessageBox.No | QtGui.QMessageBox.Cancel, ) if answer == QtGui.QMessageBox.Cancel: # Abort this action altogether. return False if answer == QtGui.QMessageBox.No: # Continue this action but do not load for review. return True # Check for unsaved changes and do not load new scene until changes are resolved. engine = self.parent.engine resolved = engine.save_or_discard_changes() if not resolved: return False # OK to proceed with loading the Version for review published_file_entity_type = sgtk.util.get_published_file_entity_type( self.sgtk) accepted_published_file_types = engine.get_setting( "accepted_published_file_types", []) published_files = self.parent.engine.shotgun.find( published_file_entity_type, [ ["version", "is", entity], [ "published_file_type.PublishedFileType.code", "in", accepted_published_file_types, ], ], fields=["id", "path"], order=[{ "field_name": "version_number", "direction": "desc" }], ) if not published_files: raise sgtk.TankError( "Version has no published files to load for review.") if len(published_files) != 1: raise sgtk.TankError( "Failed to load Version for review with VRED because there is more than one PublishedFile entity with the same PublishedFileType associated for this Version" ) # Load the Version's "latest" PublishedFile, the one with the highest version. published_file = published_files[0] if published_file: path = _get_published_file_path(published_file) if not path: raise sgtk.TankError( "Unable to determine the path on disk for published file with id '{}'." .format(published_file["id"])) QtGui.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor) vrFileIO.load( [path], vrScenegraph.getRootNode(), newFile=True, showImportOptions=False, ) QtGui.QApplication.restoreOverrideCursor() return True
def import_file(self, path): """ :param path: Path of file to import """ parent = vrScenegraph.getRootNode() vrFileIOService.importFiles([path], parent)
def execute(self, operation, file_path=None, context=None, parent_action=None, file_version=None, read_only=None, **kwargs): """ Main hook entry point :param operation: String Scene operation to perform :param file_path: String File path to use if the operation requires it (e.g. open) :param context: Context The context the file operation is being performed in. :param parent_action: This is the action that this scene operation is being executed for. :param file_version: The version/revision of the file to be opened. :param read_only: Specifies if the file should be opened read-only or not :returns: Depends on operation: 'current_path' - Return the current scene file path as a String all others - True for success, else False """ self.logger.debug( "{self} executing operation '{op}' on file '{path}'".format( self=self, op=operation, path=file_path)) success = True if operation == "current_path": current_path = vrFileIO.getFileIOFilePath() return "" if current_path is None else current_path if operation == "open": vrFileIO.load( [file_path], vrScenegraph.getRootNode(), newFile=True, showImportOptions=False, ) self.parent.engine.set_render_path(file_path) elif operation == "save": if file_path is None: file_path = vrFileIO.getFileIOFilePath() self.parent.engine.save_current_file(file_path) elif operation == "save_as": self.parent.engine.save_current_file(file_path) elif operation == "reset": success = self.parent.engine.save_or_discard_changes( override_cursor=QtCore.Qt.ArrowCursor) if success: vrController.newScene() return success