Trying to create a toolbar button to toggle lock / unlock selected objects (including cameras).
This script from Maico G. achieves this, but does so within a UI rollout. Given the simplicity of the operation, I’d rather just click a toolbar button once to lock or unlock; or assign to hotkey and toggle lock / unlock from a hotkey.
I’ve tried revising the script, but have not been successful. Any tips or suggestions are welcome!
(
Rollout caption "LockCamera & Objects" width:168 height:200
(
label lbl1 "Maico G. " pos:[104,160] width:48 height:16
label lbl2 "Lock or unlock the camera movements or objects." pos:[16,29] width:136 height:32
button btn1 "Lock" pos:[35,72] width:95 height:30
groupBox grp2 "Lock" pos:[8,9] width:152 height:176
button btn2 "Unlock" pos:[36,115] width:95 height:30
on btn1 pressed do
setTransformLockFlags $ #all
on btn2 pressed do
setTransformLockFlags $ #none
)
newroll = newrolloutfloater "Lock Camera" 170 220
addRollout caption newroll
)
EDIT: I think you might be referring to this article, but it doesn’t address the issue, per se. It does show the code that locks transform flags for an object, and how to disable the flags, but my question really hinges around how to construct an if / else statement - or whatever is required - to toggle the locks.
I have two buttons in toolbar, one of them locks transforms, the other one unlocks them. If you want toggle, then you need to modify the script. Sorry, but i can’t help you with this.
By the way, i don’t see how toggle would be better than two separate commands for this action, unless you want to assign the script to keyboard shortcut and don’t want to memorize too many shortcuts.
Yeah, I suppose it’s just about parsimony really; it would be convenient to be able to select an arbitrary object and unlock it if it’s locked or lock it if it’s unlocked by pressing a single button - or better, by pressing a single hotkey.
But what if you select multiple objects with mixed transform lock state, then your toggle will flip their state and you won’t have a clue which state particular object has. I think two separate buttons is simpler and more reliable solution.