setAttr for selection

setAttr for selection

The-Digital-Shaman
Advocate Advocate
559 Views
1 Reply
Message 1 of 2

setAttr for selection

The-Digital-Shaman
Advocate
Advocate

Hi there,

 

It's heavily searched and polluted topic.

 

I want to be able to make changed to the seleciton by code.

 

Why would it be, that the first procedure works and second does not (// Error: line 4: setAttr: No object matches name: pSphere2subdivisionsAxis //)?

 

 

string $array[] = `ls -sl`;
for ($item in $array)
{
setAttr ($item + ".scale") 2.0 2.0 2.0;
}

 

Edit:

Code breaks when trying to use with with flags (no idea where to squeeze them in);

 

string $array[] = `ls -sl`;
for ($item in $array)
{
setAttr ($item + ".scale -r") 1.05 1.05 1.05;
}

 

or on a sphere;


string $array[] = `ls -sl`;
for ($item in $array)
{
setAttr ($item + ".subdivisionsAxis") 24;
}

 

Also, such code breaks when put into -c "" 🤔

Does one need to source anything that is more than 1 command long, if wants to assign to a button/checkbox?

 

Cheers,

DS

0 Likes
560 Views
1 Reply
Reply (1)
Message 2 of 2

Kahylan
Advisor
Advisor

Hi!

 

 

 

string $array[] = `ls -sl`;
for ($item in $array)
{
setAttr ($item + ".scale -r") 1.05 1.05 1.05;
}

 

 

 The setAttr attribute has no flag called "r", check the documentation on what flags can be used:

https://help.autodesk.com/cloudhelp/2017/ENU/Maya-Tech-Docs/Commands/setAttr.html

Also you are putting the flag inside the name, the right sythax would be:

 

 

string $array[] = `ls -sl`;
for ($item in $array)
{
setAttr ($item + ".scale") -r valueForRHere 1.05 1.05 1.05;
}

 

 

but once again, there is no flag r so this won't work.

 

Ok now to this command:

 

 

string $array[] = `ls -sl`;
for ($item in $array)
{
setAttr ($item + ".subdivisionsAxis") 24;
}

 

 

This works perfecly fine, but you have the wrong item selected. The "subdivisionsAxis" attribute is on the history node, not the transform of the sphere, so you would have to select the history node directly for it to work

hist.png

 

If you want this to work with viewport selection, you would have to first find the history node before setting the attriubte:

 

 

string $array[] = `ls -sl`;
for ($item in $array)
{
string $histN[] = `listConnections -s 1 ($item + ".inMesh")`;
setAttr ($histN[0] + ".subdivisionsAxis") 25;
}

 

 

 

I dont know what you mean with this sentence, sorry:

Also, such code breaks when put into -c "" 🤔

 

I hope this helps!

0 Likes