ScriptSpot

Forum topic · General Scripting

how to enabled when select object!

By fajar · 2009-08-06

Description

Howdy everyone , im kind of trying to writte maxscript but I stuck in here , please help me, here is the sample script:

====================================================================================
rollout dynamite "Untitled"
(
editText edt4 "" pos:[1,3] width:155 height:24 enabled:false
)
createDialog dynamite 162 35
====================================================================================

the problem is how to enable/disabled editText in dialog when I select/deselect or object count more than 1 and less than 1 the object.

Thank!

Comments (6)

mertens3d · 2009-08-09

oh cool!....you can do this


 function enable_event = (

  callbacks.addScript #selectionSetChanged "check_selection()" id:#m3dLearnEvent

 )

  function disable_event = (

  callbacks.addScript #selectionSetChanged "check_selection()" id:#m3dLearnEvent

 )

 ------------------------------

 function check_selection = (

  this_sel_count = (selection as array).count

  dynamite.lbl_num_picked.text = "num picked: " + (this_sel_count as string)

  if this_sel_count == 1 then (

   dynamite.edt4.enabled = true

   dynamite.edt4.text = "enabled"

  )

  else

  (

   dynamite.edt4.enabled = false

   dynamite.edt4.text = "disabled"

  )

 )

rollout dynamite "Untitled" width:231 height:65

(

 edittext edt4 "" pos:[1,3] width:155 height:24 enabled:false

 label lbl_num_picked "Num Picked: 0" pos:[8,35] width:118 height:25

 on dynamite close do (

  disable_event()

 )

 on dynamite open do

 (

   check_selection()

   enable_event()

  )

)

createDialog dynamite


fajar · 2009-08-06

OK I got it! THX!

Marco Brunetta · 2009-08-06

Start by looking at the General Event Callback Mechanism entry in the Maxscript reference. There's enough info and examples there.

fajar · 2009-08-06

To Mertens3d:
Thank mertens3d for the answer but this is not what I meant, what I want is whenever you had object in selection, which the quantities equal one, it will enable the edit text box and disable it when the the selection count more than one or less than one,may be just like what marco said about mouse callback function, just like rappa tool maybe, when object in selection is polyOps the button comes to light and if not polyops some button is turn off ...
To marco: could you explain it more !? new in maxscript here......hehehe thank! or give me some lead or example maybe,it'll help me much...one again thank!

Marco Brunetta · 2009-08-06

I think the best way to go about this would be to create a callback that fires whenever the selection is changed, and have the callback update the editText accordingly.

mertens3d · 2009-08-06

something like this maybe?


 function check_selection = (

  this_sel_count = (selection as array).count

  dynamite.lbl_num_picked.text = "num picked: " + (this_sel_count as string)

  if this_sel_count == 1 then (

   dynamite.edt4.enabled = true

   dynamite.edt4.text = "enabled"

  )

  else

  (

   dynamite.edt4.enabled = false

   dynamite.edt4.text = "disabled"

  )

 )

rollout dynamite "Untitled" width:231 height:97

(

 edittext edt4 "" pos:[1,3] width:155 height:24 enabled:false

 label lbl_num_picked "Num Picked: 0" pos:[164,51] width:62 height:40

 button btn4 "Check Selection" pos:[21,44] width:83 height:33

 on dynamite open  do check_selection()

 on btn4 pressed do

 (

  check_selection()

  )

)

createDialog dynamite


there's a mousetool too which seems to give more event driven/reactor type feedback. Maybe that would work better but I don't know how to use it yet.