Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

[MEL] Change attributes via script for Camera/Imageplane

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
niktr96
744 Views, 4 Replies

[MEL] Change attributes via script for Camera/Imageplane

ok so currently i have this

string $cam[] = `ls -sl`;
string $camR[] = listRelatives($cam[0]);
string $camC[] = listConnections($camR[0]);

if (getAttr($camC[0]+".depth" == 2)){
setAttr $camC[0]+".depth" = 10000;
setAttr $camC[0]+".alpha" = 0.5;
setAttr $camR[0]+".nearClipPlane" = 1;
};


which should give you a rough idea of what im trying to do.
it needs to be dynamic so it works with any camera, any name and multiple connections/relations attached to that camera. Basically, if it's a camera that has an imagePlane attached, this script must edit all attributes.

Any suggestions?

Tags (3)
Labels (3)
4 REPLIES 4
Message 2 of 5
Kahylan
in reply to: niktr96

Hi!

 

If I understand you correctly, you want to change attributes on all cameras that have connected image planes.

 

For that you just need to understand some fundamentals about hierarchy and object types.

 

The shape nodes of Cameras have type "camera" which has its own tag in the ls command.

 

The shapeNodes of imagePlanes are type "imagePlane" which can be queried during listRelatives. Also imageplanes are children of the shape node of the Camera.

 

//get all Cameras

string $cams[] = `ls -cameras`;

// loop through cameras
for ($c in $cams){
    //get all image Planes parented to camera    
    string $planes[] = `listRelatives -ad -typ "imagePlane" $c`;
    //check if there are image planes
    if (size($planes) !=  0){
        //setAttr on cam
        setAttr ($c + ".nearClipPlane") 1;
        //setAttr for all imagePlanes
        for($p in $planes){
            setAttr ($p +".depth") 10000;
            setAttr ($p +".alphaGain") 0.5;
        }
    }
}

 

This worked for me. But it just made my plane disappear because 10000 is an extremely high depth value.

I hope this helps!

Message 3 of 5
niktr96
in reply to: niktr96

Thank you for the reply.

your code does work, but i need it to work for a specific Selection of cameras.
Which is why i used
string $cams[] = `ls -sl`;

could you please modify your code for this scenario?

Message 4 of 5
Kahylan
in reply to: niktr96

Ah ok, I understand.

 

Just exchange the declaration of $cams with:

string $cams[] = `ls -sl -dag -lf -cameras`;

 

Depending on your maya version you'll have to restart your maya before executing the modified script, because the old variable $cams will still be stored in memory.

 

I hope this helps!

Message 5 of 5
niktr96
in reply to: niktr96

thanks a lot 🙂
and yea i wish there was a way to clear script cache so variables don't get permanently saved into the session.
I've had so many issues because of that "feature"

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report