Adding Focal Length/Distance Lock to Camera Lock Script

I'm using a script called Camera Lock by Richard Haseltine. It locks all cameras, but leaves out a few things. I'd like to add locking focal length and focal distance to it, but adding code like getFocalLength(), or getFocalDistance() only causes the script to fail. I added them like the working code pieces within the script for locking x position and rotation below. (actual script has more before and after and Googles by the above name and author)

control = selectedNodes[ n ].getXPosControl();

if ( control ) {control.lock( true )}

control = selectedNodes[ n ].getXRotControl();

if ( control ) {control.lock( true );}

Also the script also locks lights which is not what I want. How would I disable that? It could be why focal length and distance code didn't work.

Comments

  • Richard HaseltineRichard Haseltine Posts: 100,842

    Are you sure that's one of mine? I can't see its folder in my scripts folder.

    Avoiding lights could be handled by stopping if the node under consideration was a light - node.inherits( "DzLight" ) would be true.

    The camera's focal length and distance are just numbers, not DzProperty types, so they don't have the features. You would need to get the proeprties on the node which cotrnol those values, and then lock them - DzElement has various findProperty methods.

  • 3dward3dward Posts: 32

    Richard Haseltine said:

    Are you sure that's one of mine? I can't see its folder in my scripts folder.

    Avoiding lights could be handled by stopping if the node under consideration was a light - node.inherits( "DzLight" ) would be true.

    The camera's focal length and distance are just numbers, not DzProperty types, so they don't have the features. You would need to get the proeprties on the node which cotrnol those values, and then lock them - DzElement has various findProperty methods.

     What code would get those properties off the nodes? Your script is here at https://www.daz3d.com/forums/discussion/138541/camera-lock-script

  • Richard HaseltineRichard Haseltine Posts: 100,842

    Ah, I obviosuly didn't save it to disc. OK, to fix locking lights you coudl change

    	if ( selectedNodes[ n ].inherits( "DzCamera" ) ) {

    to

    	if ( selectedNodes[ n ].inherits( "DzCamera" ) && ! selectedNodes[ n ].inherits( "DzLight" ) ) {

    which tells it to handle nodes that are cameras and not lights. DzScene also has a getSelectedCamerasList(), I'm not sure if that would exclude lights.

    For the other two properties, you'd need to use selectedNodes[ n ].findPropertyByLabel( "Focal length" ) in a copy of one of the control = selectedNodes[ n ].getYPosControl(); blocks, and the same for Focal Distance.

     

  • 3dward3dward Posts: 32

    Richard Haseltine said:

    Ah, I obviosuly didn't save it to disc. OK, to fix locking lights you coudl change

    	if ( selectedNodes[ n ].inherits( "DzCamera" ) ) {

    to

    	if ( selectedNodes[ n ].inherits( "DzCamera" ) && ! selectedNodes[ n ].inherits( "DzLight" ) ) {

    which tells it to handle nodes that are cameras and not lights. DzScene also has a getSelectedCamerasList(), I'm not sure if that would exclude lights.

    For the other two properties, you'd need to use selectedNodes[ n ].findPropertyByLabel( "Focal length" ) in a copy of one of the control = selectedNodes[ n ].getYPosControl(); blocks, and the same for Focal Distance.

    Thanks! I got things to work with that code with only a few string name differences. I also added locking "Frame Width (mm)" which seems to do the same thing as "Focal Length (mm)." Not sure why both are there, but I locked both.

Sign In or Register to comment.