def _create_reference(self, path, sg_publish_data): """ Create a reference with the same settings Cinema would use if you used the create settings dialog. :param path: Path to file. :param sg_publish_data: Shotgun data dictionary with all the standard publish fields. """ if not os.path.exists(path): raise TankError("File not found on disk - '%s'" % path) namespace = "%s %s" % (sg_publish_data.get("entity").get("name"), sg_publish_data.get("name")) namespace = namespace.replace(" ", "_") doc = c4d.documents.GetActiveDocument() xref = c4d.BaseObject(c4d.Oxref) doc.InsertObject(xref) xref.SetParameter(c4d.ID_CA_XREF_FILE, path, c4d.DESCFLAGS_SET_USERINTERACTION) xref.SetParameter(c4d.ID_CA_XREF_NAMESPACE, "", c4d.DESCFLAGS_SET_USERINTERACTION) xref.SetName(namespace) c4d.EventAdd()
def _do_import(self, path, sg_publish_data): """ Create a reference with the same settings Blender would use if you used the create settings dialog. :param path: Path to file. :param sg_publish_data: Shotgun data dictionary with all the standard publish fields. """ if not os.path.exists(path): raise TankError("File not found on disk - '%s'" % path) _, extension = os.path.splitext(path) extension_name = extension.lower()[1:] context = get_view3d_operator_context() if extension_name in ("abc", ): bpy.ops.wm.alembic_import(context, filepath=path, as_background_job=False) elif extension_name in ("dae", ): bpy.ops.wm.collada_import(context, filepath=path, as_background_job=False) elif extension_name in dir(bpy.ops.import_scene): importer = getattr(bpy.ops.import_scene, extension_name) importer(filepath=path) elif extension_name in dir(bpy.ops.import_mesh): importer = getattr(bpy.ops.import_mesh, extension_name) importer(filepath=path) elif extension_name in dir(bpy.ops.import_curve): importer = getattr(bpy.ops.import_curve, extension_name) importer(filepath=path) elif extension_name in dir(bpy.ops.import_anim): importer = getattr(bpy.ops.import_anim, extension_name) importer(filepath=path) else: raise TankError("File extension not supported %s - '%s'" % (extension_name, path))
def _create_reference(self, path, sg_publish_data): """ Create a reference with the same settings Clarisse would use if you used the create settings dialog. :param path: Path to file. :param sg_publish_data: Shotgun data dictionary with all the standard publish fields. """ app = self.parent if not os.path.exists(path): raise TankError("File not found on disk - '%s'" % path) with disabled_updates(): context = ix.get_current_context() ix.reference_file(context, path)
def _create_append(self, path, sg_publish_data): """ Create a reference with the same settings Blender would use if you used the create settings dialog. :param path: Path to file. :param sg_publish_data: Shotgun data dictionary with all the standard publish fields. """ if not os.path.exists(path): raise TankError("File not found on disk - '%s'" % path) with bpy.data.libraries.load(path, link=False) as (data_from, data_to): data_to.collections = data_from.collections for collection in data_to.collections: new_collection = bpy.data.objects.new(collection.name, None) new_collection.instance_type = "COLLECTION" new_collection.instance_collection = collection bpy.context.scene.collection.objects.link(new_collection)
def _do_import(self, path, sg_publish_data): """ Create a reference with the same settings Cinema would use if you used the create settings dialog. :param path: Path to file. :param sg_publish_data: Shotgun data dictionary with all the standard publish fields. """ doc = c4d.documents.GetActiveDocument() if not os.path.exists(path): raise TankError("File not found on disk - '%s'" % path) import_project_extensions = (".c4d") _, extension = os.path.splitext(path) if extension.lower() in import_project_extensions: c4d.documents.MergeDocument(doc, path, 0) c4d.EventAdd()
def _do_import(self, path, sg_publish_data): """ Create a reference with the same settings Clarisse would use if you used the create settings dialog. :param path: Path to file. :param sg_publish_data: Shotgun data dictionary with all the standard publish fields. """ if not os.path.exists(path): raise TankError("File not found on disk - '%s'" % path) image_extensions = ix.api.ImageIOFileFormat.get_supported_extensions() image_extensions = [ ".%s" % image_extension for image_extension in image_extensions ] import_scene_extensions = (".lws", ".abc") import_geometry_extensions = (".lwo", ".obj") import_volume_extensions = ("vdb", ) import_project_extensions = ix.application.get_project_extension_name() import_project_extensions = [ ext.lower() for ext in import_project_extensions ] _, extension = os.path.splitext(path) with disabled_updates(): if extension.lower() in import_scene_extensions: ix.api.IOHelpers.import_scene(ix.application, path) elif extension.lower() in import_project_extensions: ix.import_project(path) elif extension.lower() in image_extensions: ix.import_image(path) elif extension.lower() in import_geometry_extensions: ix.import_geometry(path) elif extension.lower() in import_volume_extensions: ix.import_volume(path)
def __init__(self, parent=None, engine=None): """ Initialize the console widget. :param parent: The console's parent widget. """ super(ShotgunPythonConsoleWidget, self).__init__(parent) # Use the engine passed in or default to the current engine self._engine = engine or current_engine() # if not running in an engine, then we're hosed if not self._engine: raise TankError( "Unable to initialize ShotGridPythonConsole. No engine running" ) self._settings_manager = settings.UserSettings( sgtk.platform.current_bundle()) # add a welcome message to the output widget welcome_message = ( "Welcome to the SG Python Console!\n\n" "Python %s\n\n" "- A tk API handle is available via the 'tk' variable\n" "- A SG API handle is available via the 'shotgun' variable\n" "- Your current context is stored in the 'context' variable\n" "- The shell engine can be accessed via the 'engine' variable\n\n" % (sys.version, )) add_sg_globals = lambda i: self.tabs.widget( i).input_widget.add_globals(self._get_sg_globals()) # lambda to add the welcome message to a tab at a given index add_welcome_msg = lambda i: self.tabs.widget( i).output_widget.add_input(welcome_message, prefix=None) # set globals as new tabs are created self.tabs.tab_added.connect(add_sg_globals) # when a new tab is added, add the welcome message self.tabs.tab_added.connect(add_welcome_msg) # try to restore previous tabs scope = self._settings_manager.SCOPE_ENGINE tab_info_list = self._settings_manager.retrieve( "tab_info", None, scope) if tab_info_list: for tab_info in tab_info_list: index = self.tabs.add_tab( name=tab_info.get("tab_name"), contents=tab_info.get("tab_contents"), ) else: self.tabs.add_tab() cur_tab_index = self._settings_manager.retrieve( "current_tab", None, scope) if cur_tab_index is not None: self.tabs.setCurrentIndex(cur_tab_index) # make sure the settings are saved before the application quits app = QtGui.QApplication.instance() app.aboutToQuit.connect(self._save_settings)