class ObjLoader(load.LoaderPlugin):
"""Obj Loader."""
product_base_types = {"model"}
product_types = product_base_types
label = "Load Model (Obj)"
representations = {"*"}
extensions = {"obj"}
order = -9
icon = "code-fork"
color = "white"
def load(self, context, name=None, namespace=None, data=None):
from pymxs import runtime as rt
filepath = os.path.normpath(self.filepath_from_context(context))
self.log.debug("Executing command to import..")
rt.Execute(f'importFile @"{filepath}" #noPrompt using:ObjImp')
folder_name = context["folder"]["name"]
namespace = unique_namespace(
name + "_",
prefix=f"{folder_name}_",
suffix="_",
)
# create "missing" container for obj import
selections = rt.GetCurrentSelection()
# get current selection
for selection in selections:
selection.name = f"{namespace}:{selection.name}"
container = containerise(
name, selections, context,
namespace, loader=self.__class__.__name__)
# OBJ has no hierarchy; parent the parts to the container so the
# product can be transformed as a whole.
for selection in selections:
selection.parent = container
return container
def update(self, container, context):
from pymxs import runtime as rt
repre_entity = context["representation"]
path = os.path.normpath(self.filepath_from_context(context))
node_name = container["instance_node"]
node = rt.getNodeByName(node_name)
namespace, _ = get_namespace(node_name)
node_list = get_previous_loaded_object(node)
rt.Select(node_list)
previous_objects = rt.GetCurrentSelection()
transform_data = object_transform_set(previous_objects)
for prev_obj in previous_objects:
if rt.isValidNode(prev_obj):
rt.Delete(prev_obj)
rt.Execute(f'importFile @"{path}" #noPrompt using:ObjImp')
# get current selection
selections = rt.GetCurrentSelection()
for selection in selections:
selection.name = f"{namespace}:{selection.name}"
# keep every part under the container, see 'load'
selection.parent = node
object_transform_restore(selection, transform_data)
update_custom_attribute_data(node, selections)
with maintained_selection():
rt.Select(node)
lib.imprint(container["instance_node"], {
"representation": repre_entity["id"],
"project_name": context["project"]["name"]
})
def switch(self, container, context):
self.update(container, context)
def remove(self, container):
from pymxs import runtime as rt
node = rt.GetNodeByName(container["instance_node"])
remove_container_data(node)