Camera Lock Script?

Once I settle in on a camera angle, I like to lock my rendering camera down by locking the translation and rotation transforms. It's not a huge effort, I'd really love a script to have one-clock lock/unlock of transforms. Unfortunately, when I open up the scripting window, I'm completely lost. I don't know how to target the camera or how to switch between lock and unlocked modes for transforms. Has anybody written such a script? Or, if not, would it be easier to write than I think?

Comments

  • // Camera lock// (c) Richard haseltine, Jan 2017// get list of selected itemsvar selectedNodes = Scene.getSelectedNodeList();var control;// go through listfor ( var n = 0 ; n < selectedNodes.length ; n++ ) {	// is it a camera?	if ( selectedNodes[ n ].inherits( "DzCamera" ) ) {		// get and lock its transforms		control = selectedNodes[ n ].getXPosControl();		if ( control ) {			control.lock( true );		}		control = selectedNodes[ n ].getYPosControl();		if ( control ) {			control.lock( true );		}		control = selectedNodes[ n ].getZPosControl();		if ( control ) {			control.lock( true );		}		control = selectedNodes[ n ].getXRotControl();		if ( control ) {			control.lock( true );		}		control = selectedNodes[ n ].getYRotControl();		if ( control ) {			control.lock( true );		}		control = selectedNodes[ n ].getZRotControl();		if ( control ) {			control.lock( true );		}	}}

    change true to false throughout for an unlock script

  • Thanks Richard, that's excellent

  • mjc1016mjc1016 Posts: 15,001

    Here's a couple of icons for this...

    Rename them CameraLock.dsa.png/CameraUnlock.dsa.png (if that's what you named the scripts) and drop them along side the scripts.

    CameraLock.dsa.png
    91 x 91 - 10K
    CameraUnlock.dsa.png
    91 x 91 - 10K
  • FirePro9FirePro9 Posts: 456

    Just curious, can I include this camera lock script in a commercial product as a very useful tool but not the primary purpose of the product?  Thank you.

  • OmnifluxOmniflux Posts: 377

    Here's a version with undo and unlock support you can use

    // DAZ Studio version 4.12.1.118 filetype DAZ Script// Lock (or unlock) selected cameras position and rotation.//// Hold SHIFT when running script to unlock.//// Author: Omniflux// Version: 1// Date: 2021-01-21(function (bUnlock) {	function lockControls (object) {		functions = [object.getXPosControl, object.getYPosControl, object.getZPosControl,		             object.getXRotControl, object.getYRotControl, object.getZRotControl];		functions.forEach (function (control) { if (control) control().lock (!bUnlock) });	}	function undoString() {		var sUndo = bUnlock ? "Unlock" : "Lock";		var sName = (Scene.getNumSelectedCameras() == 1) ? Scene.getSelectedCamera (0).getLabel() : "Cameras";		return "%1 %2".arg (sUndo).arg (sName);	}	if (Scene.getNumSelectedCameras() == 0)		MessageBox.warning ("This action requires one or more cameras to be selected.", "Selection Error", "&OK", "");	else {		beginUndo();		Scene.getSelectedCameraList().forEach (lockControls);		acceptUndo (undoString());	}})(App.modifierKeyState() & 0x02000000);

    If you want to use it as two separate scripts to lock / unlock, change the last line

    })(true);	// Unlock})(false);	// Lock

     

  • FirePro9FirePro9 Posts: 456

    Omniflux, thank you very much!

  • TugpsxTugpsx Posts: 738
    edited May 2022

    Guys if it's ok with you,  I'm merging the codes into another old  camera project. We will rename it project since there are a lot of us on it.

    mcjcamlock2022.PNG
    408 x 234 - 10K
    Post edited by Tugpsx on
  • TugpsxTugpsx Posts: 738

    @Omniflux here is the shell for the project.

     

  • TugpsxTugpsx Posts: 738
    edited May 2022

    New version of CamLock2022 has been released. Check out the related video.

    CamLock2022v2 allows you to easiy lock your Beauty/Production camera during scene composition.

    Updated with "Camera Locked" scene indicator.

    Files linked below

    https://sites.google.com/site/mcasualsdazscripts9/camlock2022v2

    Click image below for video tutorial

    CamLock2022v2.PNG
    1075 x 713 - 2M
    Post edited by Tugpsx on
  • AnEye4ArtAnEye4Art Posts: 766
    edited May 2022

    Tugpsx said:

    New version of CamLock2022 has been released. Check out the related video.

    CamLock2022v2 allows you to easiy lock your Beauty/Production camera during scene composition.

    Cool. Thanks. 

    Post edited by AnEye4Art on
  • TugpsxTugpsx Posts: 738

    Be sure to grab the new version it has the camera locked scene indicator.

  • FirePro9FirePro9 Posts: 456

    Got it, thanks Tugpsx, nice update!

    I did a Create Custom Action to save it to the Scripts Menu, then, because I use it a lot, I gave it a keyboard shortcut:  "Window>Workspace>Customise find the script's entry under Custom on the left, right-click on it, Change Keyboard Shortcut, and press the combo you want."

  • TugpsxTugpsx Posts: 738

    FirePro9 said:

    Got it, thanks Tugpsx, nice update!

    I did a Create Custom Action to save it to the Scripts Menu, then, because I use it a lot, I gave it a keyboard shortcut:  "Window>Workspace>Customise find the script's entry under Custom on the left, right-click on it, Change Keyboard Shortcut, and press the combo you want."

    Glad you are enjoying the update. The shortcuts do come in handy. Thanks for sharing. 

  • mCasualmCasual Posts: 4,607

    Hi there

    I posted CamLock2022V2 on its own google-sites site page

    this way :  https://sites.google.com/site/mcasualsdazscripts9/camlock2022v2

    i will also make a thread for it in the freebies forum

     

    camlockpromo.jpg
    1013 x 493 - 83K
    item503.png
    240 x 240 - 28K
  • gitika1gitika1 Posts: 948

    Nice idea.  Didn't work for me.  Perhaps it is because I still use 4.12

    2022-05-09 17:56:40.663 WARNING: Script Error: Line 80
    2022-05-09 17:56:40.663 WARNING: TypeError: Result of expression 'wLockBtn.clicked.scriptConnect' [undefined] is not a function.

  • OmnifluxOmniflux Posts: 377

    @gitka1

    Yes, Function::scriptConnect isn't available in DS versions older than Jan. 2021, it was introduced when Function::connect was deprecated.

    Just for you, here is a modified version that I believe will work with 4.12. Please respond if it does!

    zip
    zip
    camlock2022v2Modified.zip
    11K
  • TugpsxTugpsx Posts: 738

    @Omniflux thanks for the update and addressing the issue.

Sign In or Register to comment.