72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179 | class MaxSceneLoader(load.LoaderPlugin):
"""Max Scene Loader."""
product_types = {
"camera",
"maxScene",
"model",
}
representations = {"max"}
order = -8
icon = "code-fork"
color = "green"
mtl_dup_default = "promptMtlDups"
mtl_dup_enum_dict = {
"promptMtlDups": "Prompt on Duplicate Materials",
"useMergedMtlDups": "Use Incoming Material",
"useSceneMtlDups": "Use Scene Material",
"renameMtlDups": "Merge and Rename Incoming Material"
}
@classmethod
def get_options(cls, contexts):
return [
EnumDef("mtldup",
items=cls.mtl_dup_enum_dict,
default=cls.mtl_dup_default,
label="Material Duplicate Options")
]
def load(self, context, name=None, namespace=None, options=None):
from pymxs import runtime as rt
mat_dup_options = options.get("mtldup", self.mtl_dup_default)
path = self.filepath_from_context(context)
path = os.path.normpath(path)
# import the max scene by using "merge file"
path = path.replace('\\', '/')
rt.MergeMaxFile(path, rt.Name(mat_dup_options),
quiet=True, includeFullGroup=True)
max_objects = rt.getLastMergedNodes()
max_object_names = [obj.name for obj in max_objects]
# implement the OP/AYON custom attributes before load
max_container = []
namespace = unique_namespace(
name + "_",
suffix="_",
)
for max_obj, obj_name in zip(max_objects, max_object_names):
max_obj.name = f"{namespace}:{obj_name}"
max_container.append(max_obj)
return containerise(
name, max_container, context,
namespace, loader=self.__class__.__name__)
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)
# delete the old container with attribute
# delete old duplicate
# use the modifier OP data to delete the data
node_list = get_previous_loaded_object(node)
rt.select(node_list)
prev_max_objects = rt.GetCurrentSelection()
transform_data = object_transform_set(prev_max_objects)
for prev_max_obj in prev_max_objects:
if rt.isValidNode(prev_max_obj): # noqa
rt.Delete(prev_max_obj)
material_option = self.mtl_dup_default
if not is_headless():
window = MaterialDupOptionsWindow(self.mtl_dup_enum_dict)
window.exec_()
material_option = window.material_option
rt.MergeMaxFile(path, rt.Name(material_option), quiet=True)
current_max_objects = rt.getLastMergedNodes()
current_max_object_names = [obj.name for obj
in current_max_objects]
max_objects = []
for max_obj, obj_name in zip(current_max_objects,
current_max_object_names):
max_obj.name = f"{namespace}:{obj_name}"
max_objects.append(max_obj)
max_transform = f"{max_obj}.transform"
if max_transform in transform_data.keys():
max_obj.pos = transform_data[max_transform] or 0
max_obj.scale = transform_data[
f"{max_obj}.scale"] or 0
update_custom_attribute_data(node, max_objects)
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)
|