Author Topic: [RESOLVED] Lock / Unlock Object - Toolbar Button  (Read 4218 times)

2020-06-11, 22:01:57

cjwidd

  • Active Users
  • **
  • Posts: 1077
    • View Profile
    • Artstation
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!

Code: [Select]
(
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
)
« Last Edit: 2020-06-13, 01:24:31 by cjwidd »

2020-06-11, 23:44:13
Reply #1

romullus

  • Global Moderator
  • Active Users
  • ****
  • Posts: 8887
  • Let's move this topic, shall we?
    • View Profile
    • My Models
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.
I'm not Corona Team member. Everything i say, is my personal opinion only.
My Models | My Videos | My Pictures

2020-06-11, 23:51:14
Reply #2

cjwidd

  • Active Users
  • **
  • Posts: 1077
    • View Profile
    • Artstation
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.
« Last Edit: 2020-06-12, 07:38:18 by cjwidd »

2020-06-12, 10:02:55
Reply #3

romullus

  • Global Moderator
  • Active Users
  • ****
  • Posts: 8887
  • Let's move this topic, shall we?
    • View Profile
    • My Models
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.
I'm not Corona Team member. Everything i say, is my personal opinion only.
My Models | My Videos | My Pictures

2020-06-12, 11:40:57
Reply #4

cjwidd

  • Active Users
  • **
  • Posts: 1077
    • View Profile
    • Artstation
By the way, i don't see how toggle would be better than two separate commands for this action

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.

2020-06-12, 12:22:28
Reply #5

clemens_at

  • Active Users
  • **
  • Posts: 142
    • View Profile
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.

Code: [Select]
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

2020-06-12, 12:37:20
Reply #6

romullus

  • Global Moderator
  • Active Users
  • ****
  • Posts: 8887
  • Let's move this topic, shall we?
    • View Profile
    • My Models
By the way, i don't see how toggle would be better than two separate commands for this action

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.
I'm not Corona Team member. Everything i say, is my personal opinion only.
My Models | My Videos | My Pictures

2020-06-12, 12:54:15
Reply #7

clemens_at

  • Active Users
  • **
  • Posts: 142
    • View Profile
By the way, i don't see how toggle would be better than two separate commands for this action

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.

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

2020-06-13, 01:24:15
Reply #8

cjwidd

  • Active Users
  • **
  • Posts: 1077
    • View Profile
    • Artstation
I think two separate buttons is simpler and more reliable solution.

+1