[RESOLVED] Lock / Unlock Object - Toolbar Button

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
)

3ds Max maxscript help has some examples, amongst them there are two simple scripts for locking/unlocking objects. I’m using them all the time.

link? or script?

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.

checkbutton is what you want I think.
https://help.autodesk.com/view/3DSMAX/2016/ENU/?guid=__files_GUID_084BC777_9353_455E_A869_9F5C514E0CE6_htm

this is really rough and will fail if you have nothing selected. I will take a closer look later. hope this helps.


try(destroyDialog ro)catch()
rollout ro "LockObjects" 
(
	checkbutton btn1 "Lock" width:95 height:30

	on btn1 changed state do
		(
			if state == on then
				(
					setTransformLockFlags $ #all
				)
			else setTransformLockFlags $ #none
		)
)
createDialog ro 130 40

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.

they cant be flipped since it will always be overridden either with locked or not locked.
But there are other problems with a checkbutton :wink:

+1