Add Assignment in aiSetParameter through MEL/Python

Add Assignment in aiSetParameter through MEL/Python

pravin0056
Participant Participant
796 Views
2 Replies
Message 1 of 3

Add Assignment in aiSetParameter through MEL/Python

pravin0056
Participant
Participant

Hi

 

Is there any way to add new assignment in aiSetParameter node through script?

 

pravin0056_0-1703216282758.png

 

I want to add shader through Python but I am not getting any output in script editor while doing the manual process so that I can refer the same and create script.

 

It would be great if anyone guide me to achieve the required step.

 

Accepted solutions (1)
797 Views
2 Replies
Replies (2)
Message 2 of 3

Kahylan
Advisor
Advisor
Accepted solution

Hi!

 

I'm not gonna lie, this node is a pain to work with. appearently the message attriubtes have a preassignet japanese string, no idea why. It doesn't allow to for multiple assignements of the same type, etc.

But I think I figured out a way to do what you want:

 

import maya.cmds as mc


def addAssignement(type = "", attribute = "", aiSetParameterNode = ""):
    
    i = 0
    message = "="
    lenType= len(type)
    
    while "=" in message:
        message = mc.getAttr("{0}.assignment[{1}]".format(aiSetParameterNode,i))
        i= i + 1
        if message[:lenType] == type:
            break
        
    
    mc.setAttr("{0}.assignment[{1}]".format(aiSetParameterNode,i-1), "{0}='{1}'".format(type, attribute), type = "string")
    
addAssignement(type = "shader", attribute = "lambert2", aiSetParameterNode = "aiSetParameter1")

 

the type variable takes the left part of the assignmetn (eg. shader or displacement) and the attribute variable right part of the assignment. (name of shader, type of curve, etc)
the aiSetParameterNode variable takes the name of the Node you want to add the assignment to.

I hope it helps, and happy holidays!

 

0 Likes
Message 3 of 3

pravin0056
Participant
Participant

Hi @Kahylan 

 

Thank you for the quick response.

I really appreciate your help in resolving the issue.

 

Thank you and Happy holiday's