Skip to content

plugin

3dsmax specific AYON/Pyblish plugin definitions.

MaxCacheCreator

Bases: Creator, MaxTyFlowDataCreatorBase

Source code in client/ayon_max/api/plugin.py
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
class MaxCacheCreator(Creator, MaxTyFlowDataCreatorBase):
    skip_discovery = True
    settings_category = "max"

    def create(self, product_name, instance_data, pre_create_data):
        tyflow_op_nodes = get_tyflow_export_operators()
        if not tyflow_op_nodes:
            raise CreatorError("No Export Particle Operators"
                               " found in tyCache Editor.")
        instance_node = self.create_instance_node(product_name)
        instance_data["instance_node"] = instance_node.name
        product_type = instance_data.get("productType")
        if not product_type:
            product_type = self.product_base_type
        instance = CreatedInstance(
            product_type=product_type,
            product_base_type=self.product_base_type,
            product_name=product_name,
            data=instance_data,
            creator=self,
        )
        # Setting the property
        node_list = [sub_anim.name for sub_anim in tyflow_op_nodes]
        rt.setProperty(
            instance_node.modifiers[0].AYONTyCacheData,
            "tyc_handles", node_list)
        self._add_instance_to_context(instance)
        imprint(instance_node.name, instance.data_to_store())

        return instance

    def collect_instances(self):
        self.cache_instance_data(self.collection_shared_data)
        for instance in self.collection_shared_data["max_cached_instances"].get(self.identifier, []):  # noqa
            created_instance = CreatedInstance.from_existing(
                read(rt.GetNodeByName(instance)), self
            )
            self._add_instance_to_context(created_instance)

    def update_instances(self, update_list):
        for created_inst, changes in update_list:
            instance_node = created_inst.get("instance_node")
            new_values = {
                key: changes[key].new_value
                for key in changes.changed_keys
            }
            product_name = new_values.get("productName", "")
            if product_name and instance_node != product_name:
                node = rt.getNodeByName(instance_node)
                new_product_name = new_values["productName"]
                if rt.getNodeByName(new_product_name):
                    raise CreatorError(
                        "The product '{}' already exists.".format(
                            new_product_name))
                instance_node = new_product_name
                created_inst["instance_node"] = instance_node
                node.name = instance_node

            imprint(
                instance_node,
                created_inst.data_to_store(),
            )

    def remove_instances(self, instances):
        """Remove specified instance from the scene.

        This is only removing AYON-related parameters based on the modifier
        so instance is no longer instance, because it might contain
        valuable data for artist.

        """
        for instance in instances:
            instance_node = rt.GetNodeByName(
                instance.data.get("instance_node"))
            if instance_node:
                count = rt.custAttributes.count(instance_node.modifiers[0])
                rt.custAttributes.delete(instance_node.modifiers[0], count)
                rt.Delete(instance_node)

            self._remove_instance_from_context(instance)

remove_instances(instances)

Remove specified instance from the scene.

This is only removing AYON-related parameters based on the modifier so instance is no longer instance, because it might contain valuable data for artist.

Source code in client/ayon_max/api/plugin.py
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
def remove_instances(self, instances):
    """Remove specified instance from the scene.

    This is only removing AYON-related parameters based on the modifier
    so instance is no longer instance, because it might contain
    valuable data for artist.

    """
    for instance in instances:
        instance_node = rt.GetNodeByName(
            instance.data.get("instance_node"))
        if instance_node:
            count = rt.custAttributes.count(instance_node.modifiers[0])
            rt.custAttributes.delete(instance_node.modifiers[0], count)
            rt.Delete(instance_node)

        self._remove_instance_from_context(instance)

MaxCreator

Bases: Creator, MaxCreatorBase

Source code in client/ayon_max/api/plugin.py
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
class MaxCreator(Creator, MaxCreatorBase):
    skip_discovery = True
    settings_category = "max"
    selected_nodes = []

    def create(self, product_name, instance_data, pre_create_data):
        if pre_create_data.get("use_selection"):
            self.selected_nodes = rt.GetCurrentSelection()
        if rt.getNodeByName(product_name):
            raise CreatorError(f"'{product_name}' is already created..")

        instance_node = self.create_instance_node(product_name)
        instance_data["instance_node"] = instance_node.name
        product_type = instance_data.get("productType")
        if not product_type:
            product_type = self.product_base_type
        instance = CreatedInstance(
            product_type=product_type,
            product_base_type=self.product_base_type,
            product_name=product_name,
            data=instance_data,
            creator=self,
        )
        if pre_create_data.get("use_selection"):

            node_list = []
            sel_list = []
            for i in self.selected_nodes:
                node_ref = rt.NodeTransformMonitor(node=i)
                node_list.append(node_ref)
                sel_list.append(str(i))

            # Setting the property
            rt.setProperty(
                instance_node.modifiers[0].AYONData,
                "all_handles", node_list)
            rt.setProperty(
                instance_node.modifiers[0].AYONData,
                "sel_list", sel_list)

        self._add_instance_to_context(instance)
        imprint(instance_node.name, instance.data_to_store())

        return instance

    def collect_instances(self):
        self.cache_instance_data(self.collection_shared_data)
        for instance in self.collection_shared_data["max_cached_instances"].get(self.identifier, []):  # noqa
            created_instance = CreatedInstance.from_existing(
                read(rt.GetNodeByName(instance)), self
            )
            self._add_instance_to_context(created_instance)

    def update_instances(self, update_list):
        for created_inst, changes in update_list:
            instance_node = created_inst.get("instance_node")
            new_values = {
                key: changes[key].new_value
                for key in changes.changed_keys
            }
            product_name = new_values.get("productName", "")
            if product_name and instance_node != product_name:
                node = rt.getNodeByName(instance_node)
                new_product_name = new_values["productName"]
                if rt.getNodeByName(new_product_name):
                    raise CreatorError(
                        "The product '{}' already exists.".format(
                            new_product_name))
                instance_node = new_product_name
                created_inst["instance_node"] = instance_node
                node.name = instance_node

            imprint(
                instance_node,
                created_inst.data_to_store(),
            )

    def remove_instances(self, instances):
        """Remove specified instance from the scene.

        This is only removing `id` parameter so instance is no longer
        instance, because it might contain valuable data for artist.

        """
        for instance in instances:
            instance_node = rt.GetNodeByName(
                instance.data.get("instance_node"))
            if instance_node:
                count = rt.custAttributes.count(instance_node.modifiers[0])
                rt.custAttributes.delete(instance_node.modifiers[0], count)
                rt.Delete(instance_node)

            self._remove_instance_from_context(instance)

    def get_pre_create_attr_defs(self):
        return [
            BoolDef("use_selection", label="Use selection")
        ]

remove_instances(instances)

Remove specified instance from the scene.

This is only removing id parameter so instance is no longer instance, because it might contain valuable data for artist.

Source code in client/ayon_max/api/plugin.py
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
def remove_instances(self, instances):
    """Remove specified instance from the scene.

    This is only removing `id` parameter so instance is no longer
    instance, because it might contain valuable data for artist.

    """
    for instance in instances:
        instance_node = rt.GetNodeByName(
            instance.data.get("instance_node"))
        if instance_node:
            count = rt.custAttributes.count(instance_node.modifiers[0])
            rt.custAttributes.delete(instance_node.modifiers[0], count)
            rt.Delete(instance_node)

        self._remove_instance_from_context(instance)

MaxCreatorBase

Bases: object

Source code in client/ayon_max/api/plugin.py
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
class MaxCreatorBase(object):

    @staticmethod
    def cache_instance_data(shared_data):
        if shared_data.get("max_cached_instances") is not None:
            return shared_data

        shared_data["max_cached_instances"] = {}
        shared_data["max_cached_legacy_instances"] = {}

        cached_instances = []
        for id_type in [AYON_INSTANCE_ID, AVALON_INSTANCE_ID]:
            cached_instances.extend(lsattr("id", id_type))

        for i in cached_instances:
            creator_id = rt.GetUserProp(i, "creator_identifier")
            if "openpype" in creator_id:
                # Legacy creator instance
                shared_data["max_cached_legacy_instances"].setdefault(
                    creator_id, []).append(i.name)
            else:
                shared_data["max_cached_instances"].setdefault(
                    creator_id, []).append(i.name)

        return shared_data

    @staticmethod
    def create_instance_node(node):
        """Create instance node.

        If the supplied node is existing node, it will be used to hold the
        instance, otherwise new node of type Dummy will be created.

        Args:
            node (rt.MXSWrapperBase, str): Node or node name to use.

        Returns:
            instance
        """
        if not isinstance(node, str):
            raise CreatorError("Instance node is not at the string value.")

        node = rt.Container(name=node)
        attrs = rt.Execute(MS_CUSTOM_ATTRIB)
        modifier = rt.EmptyModifier()
        rt.addModifier(node, modifier)
        node.modifiers[0].name = "AYON Data"
        rt.custAttributes.add(node.modifiers[0], attrs)

        return node

create_instance_node(node) staticmethod

Create instance node.

If the supplied node is existing node, it will be used to hold the instance, otherwise new node of type Dummy will be created.

Parameters:

Name Type Description Default
node (MXSWrapperBase, str)

Node or node name to use.

required

Returns:

Type Description

instance

Source code in client/ayon_max/api/plugin.py
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
@staticmethod
def create_instance_node(node):
    """Create instance node.

    If the supplied node is existing node, it will be used to hold the
    instance, otherwise new node of type Dummy will be created.

    Args:
        node (rt.MXSWrapperBase, str): Node or node name to use.

    Returns:
        instance
    """
    if not isinstance(node, str):
        raise CreatorError("Instance node is not at the string value.")

    node = rt.Container(name=node)
    attrs = rt.Execute(MS_CUSTOM_ATTRIB)
    modifier = rt.EmptyModifier()
    rt.addModifier(node, modifier)
    node.modifiers[0].name = "AYON Data"
    rt.custAttributes.add(node.modifiers[0], attrs)

    return node

MaxTyFlowDataCreatorBase

Bases: MaxCreatorBase

Source code in client/ayon_max/api/plugin.py
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
class MaxTyFlowDataCreatorBase(MaxCreatorBase):
    @staticmethod
    def create_instance_node(node):
        """Create instance node.

        If the supplied node is existing node, it will be used to hold the
        instance, otherwise new node of type Dummy will be created.

        Args:
            node (rt.MXSWrapperBase, str): Node or node name to use.

        Returns:
            instance
        """
        if not isinstance(node, str):
            raise CreatorError("Instance node is not at the string value.")
        node = rt.Container(name=node)
        attrs = rt.Execute(MS_TYCACHE_ATTRIB)
        modifier = rt.EmptyModifier()
        rt.addModifier(node, modifier)
        node.modifiers[0].name = "AYON TyCache Data"
        rt.custAttributes.add(node.modifiers[0], attrs)

        return node

create_instance_node(node) staticmethod

Create instance node.

If the supplied node is existing node, it will be used to hold the instance, otherwise new node of type Dummy will be created.

Parameters:

Name Type Description Default
node (MXSWrapperBase, str)

Node or node name to use.

required

Returns:

Type Description

instance

Source code in client/ayon_max/api/plugin.py
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
@staticmethod
def create_instance_node(node):
    """Create instance node.

    If the supplied node is existing node, it will be used to hold the
    instance, otherwise new node of type Dummy will be created.

    Args:
        node (rt.MXSWrapperBase, str): Node or node name to use.

    Returns:
        instance
    """
    if not isinstance(node, str):
        raise CreatorError("Instance node is not at the string value.")
    node = rt.Container(name=node)
    attrs = rt.Execute(MS_TYCACHE_ATTRIB)
    modifier = rt.EmptyModifier()
    rt.addModifier(node, modifier)
    node.modifiers[0].name = "AYON TyCache Data"
    rt.custAttributes.add(node.modifiers[0], attrs)

    return node