update the obj loader and add maintained_selection for loaders

This commit is contained in:
Kayla Man 2023-03-28 17:26:04 +08:00
parent c20f45e881
commit 32bb42e379
4 changed files with 24 additions and 8 deletions

View file

@ -5,6 +5,7 @@ from openpype.pipeline import (
)
from openpype.hosts.max.api.pipeline import containerise
from openpype.hosts.max.api import lib
from openpype.hosts.max.api.lib import maintained_selection
class ModelAbcLoader(load.LoaderPlugin):
@ -57,12 +58,8 @@ importFile @"{file_path}" #noPrompt
def update(self, container, representation):
from pymxs import runtime as rt
path = get_representation_path(representation)
node = rt.getNodeByName(container["instance_node"])
lib.imprint(container["instance_node"], {
"representation": str(representation["_id"])
})
rt.select(node.Children)
for alembic in rt.selection:
@ -76,6 +73,13 @@ importFile @"{file_path}" #noPrompt
alembic_obj = rt.getNodeByName(abc_obj.name)
alembic_obj.source = path
with maintained_selection():
rt.select(node)
lib.imprint(container["instance_node"], {
"representation": str(representation["_id"])
})
def switch(self, container, representation):
self.update(container, representation)

View file

@ -5,6 +5,7 @@ from openpype.pipeline import (
)
from openpype.hosts.max.api.pipeline import containerise
from openpype.hosts.max.api import lib
from openpype.hosts.max.api.lib import maintained_selection
class FbxModelLoader(load.LoaderPlugin):
@ -59,6 +60,9 @@ importFile @"{path}" #noPrompt using:FBXIMP
""")
rt.execute(fbx_reimport_cmd)
with maintained_selection():
rt.select(node)
lib.imprint(container["instance_node"], {
"representation": str(representation["_id"])
})

View file

@ -5,6 +5,7 @@ from openpype.pipeline import (
)
from openpype.hosts.max.api.pipeline import containerise
from openpype.hosts.max.api import lib
from openpype.hosts.max.api.lib import maintained_selection
class ObjLoader(load.LoaderPlugin):
@ -42,16 +43,19 @@ class ObjLoader(load.LoaderPlugin):
path = get_representation_path(representation)
node_name = container["instance_node"]
node = rt.getNodeByName(node_name)
instance_name, _ = node_name.split("_")
container = rt.getNodeByName(instance_name)
for n in container.Children:
rt.delete(n)
rt.execute(f'importFile @"{path}" #noPrompt using:ObjImp')
# create "missing" container for obj import
container = rt.container()
container.name = f"{instance_name}"
# get current selection
for selection in rt.getCurrentSelection():
selection.Parent = container
container.Parent = node
with maintained_selection():
rt.select(node)
lib.imprint(node_name, {
"representation": str(representation["_id"])

View file

@ -4,6 +4,7 @@ from openpype.pipeline import (
)
from openpype.hosts.max.api.pipeline import containerise
from openpype.hosts.max.api import lib
from openpype.hosts.max.api.lib import maintained_selection
class ModelUSDLoader(load.LoaderPlugin):
@ -60,6 +61,9 @@ class ModelUSDLoader(load.LoaderPlugin):
asset = rt.getNodeByName(f"{instance_name}")
asset.Parent = node
with maintained_selection():
rt.select(node)
lib.imprint(node_name, {
"representation": str(representation["_id"])
})