Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk 3ds® Max® / MaxScript / Multiple dialogs or floater instances from a single rollout definition?
  RSS 2.0 ATOM  

Multiple dialogs or floater instances from a single rollout definition?
Rate this thread
 
46728
 
Permlink of this thread  
avatar
  • Total Posts: 5
  • Joined: 30 August 2010 01:32 PM

Hi,

Is there a way to structure or scope rollout definitions in a way that supports multiple instances of the same UI running in multiple dialogs?  Or does there have to be a unique rollout def for each call to CreateDialog? 

I’d love to have 4 instances of a custom UI open for the user but can’t figure out how to make that happen without copy/pasting the code.

Thanks!
-Kurt



Replies: 0
avatar

I can’t come up with anything better than pulling out the handling code for each callback. If there’s a better option I’d love to hear about it.  Below is a simplified example.  I should be fired for the amount of duplicated code in the real version…
Thanks,
-K

-- generalized handler for the Set button
fn HandleSetObjectButton dlg 
=
(
   if( 
selection[1] != undefined then
      dlg
.lbl_CurrentObj.text "Current Object: " selection[1].name
)

-- 
Rollout definition for 1st dialog
g_dlg1 
rollout def1 "Dialog 1"
(

   
button btn_SetObj "Set >" toolTip:"Select object to edit"
   
label lbl_CurrentObj "Current Object:" 

   
on btn_SetObj pressed do
   (
      
HandleSetObjectButton def1
   
)
)

-- 
Rollout definition for 2nd dialog
g_dlg2 
rollout def2 "Dialog 2"
(

   
button btn_SetObj "Set >" toolTip:"Select object to edit"
   
label lbl_CurrentObj "Current Object:" 

   
on btn_SetObj pressed do
   (
      
HandleSetObjectButton def2
   
)
)

-- 
Rollout definition for 3rd dialog
g_dlg3 
rollout def3 "Dialog 3"
(

   
button btn_SetObj "Set >" toolTip:"Select object to edit"
   
label lbl_CurrentObj "Current Object:" 

   
on btn_SetObj pressed do
   (
      
HandleSetObjectButton def3
   
)
)

-- 
Rollout definition for 4th dialog
g_dlg4 
rollout def4 "Dialog 4" 
(
   
button btn_SetObj "Set >" toolTip:"Select object to edit"
   
label lbl_CurrentObj "Current Object:" 

   
on btn_SetObj pressed do
   (
      
HandleSetObjectButton def4
   
)
)

-- 
keep around a list of the dialogs to help with searchingreopeningetc
g_vDialogs 
#(g_dlg1, g_dlg2, g_dlg3, g_dlg4)

-- elsewhere in the UI CreateDialog gets called
CreateDialog g_dlg1
CreateDialog g_dlg2
CreateDialog g_dlg3
CreateDialog g_dlg4


Replies: 0
avatar
  • lo_
  • Posted: 31 August 2010 06:36 AM

I don’t have an answer for how, but I’d love to hear why you would want this



VFB+ : An enhanced 3dsmax frame buffer (free)

Replies: 1
/img/forum/dark/default_avatar.png

We have a custom editor for object properties and it’s nice having more than one open at a time so you can reference other objects’ settings, copy/paste, etc.

Author: KurtReiner

Replied: 31 August 2010 08:14 AM  
avatar
  • Anubis
  • Posted: 31 August 2010 09:04 AM

Seems needed a unique rollout def for each call to CreateDialog.
I hope this test helps somehow.

-- generalized handler for the Set button
fn HandleSetObjectButton dlg 
=
(
   if( 
selection[1] != undefined then
      dlg
.lbl_CurrentObj.text "Current Object: " selection[1].name
)

-- 
Rollout definition for 1st dialog
g_dlg1 
rollout def1 "Dialog 1"
(

   
button btn_SetObj "Set >" toolTip:"Select object to edit"
   
label lbl_CurrentObj "Current Object:" 

   
on btn_SetObj pressed do
   (
      
HandleSetObjectButton def1
   
)
)

g_dlg2 g_dlg1 -- make instance
g_dlg3 
copy g_dlg1 -- make copy

CreateDialog g_dlg1
CreateDialog g_dlg2
CreateDialog g_dlg3

g_dlg1
.isDisplayed -->> true
g_dlg2
.isDisplayed -->> true
g_dlg3
.isDisplayed -->> true
-- but only one dialog is visible

-- I pick a Teapot01 object...
g_dlg1.lbl_CurrentObj.text -->> "Current Object: Teapot01"
g_dlg2.lbl_CurrentObj.text -->> "Current Object: Teapot01"
g_dlg3.lbl_CurrentObj.text -->> "Current Object: Teapot01"

DestroyDialog g_dlg1 -- seems it close all dialogs

g_dlg1
.isDisplayed -->> false
g_dlg2
.isDisplayed -->> false
g_dlg3
.isDisplayed -->> false

-- the answer is here -- all of them called "def1":
g_dlg1 -->> Rollout:def1
g_dlg2 
-->> Rollout:def1
g_dlg3 
-->> Rollout:def1
g_dlg1 
== g_dlg2 -->> true
g_dlg1 
== g_dlg3 -->> true


Max 9 through 2009, XP-Pro x64 SP2
ASUS EAH3450 Series (Driver 8.470).
Core 2 Duo E8400 3GHz, 4Gb Ram, DX9.0c.

Replies: 3
/img/forum/dark/default_avatar.png

P.S. - You can rid of multiple codes by saving the code of rollout body to a separate script and using include().

rollout def1 "Dialog 1" ( include "rollout_source.ms" )
rollout def2 "Dialog 2" ( include "rollout_source.ms" )
rollout def3 "Dialog 3" ( include "rollout_source.ms" )
rollout def4 "Dialog 4" ( include "rollout_source.ms" )
Author: Anubis

Replied: 31 August 2010 09:31 AM  
/img/forum/dark/default_avatar.png

Thanks Anubis.  This suggestion

“rollout def1 “Dialog 1” ( include “rollout_source.ms” )”

gets me a step closer but the dialogs’ callback handlers (on open, on okToClose, on resized, etc.) all require the rollout name in their definition (def1, def2, etc.)

Author: KurtReiner

Replied: 01 September 2010 02:40 AM  
/img/forum/dark/default_avatar.png

Yes, that complicate the issue…
Maybe the include() can help again?

rollout def1 "Dialog 1" (
   include 
"rollout_source.ms"
   
include "def1_handlers.ms"
)
rollout def2 "Dialog 2" (
   include 
"rollout_source.ms"
   
include "def2_handlers.ms"
)
Author: Anubis

Replied: 01 September 2010 07:30 PM  
avatar
  • lo_
  • Posted: 31 August 2010 10:02 AM

I don’t think you need to save it in a seperate file:

rollout rol "the rollout" 
(
 
button b1 "bla bla"
)

createdialog rol

rol2
=deepcopy rol
createdialog rol2

rol3
=deepcopy rol
createdialog rol3

etc
...


VFB+ : An enhanced 3dsmax frame buffer (free)

Replies: 1
/img/forum/dark/default_avatar.png

am afraid that deepcopy() is for arrays only

rol2=deepcopy rol --> return error"Unable to convert: Rollout:rol to type: Array"
Author: Anubis

Replied: 31 August 2010 12:50 PM  
avatar
  • lo_
  • Posted: 31 August 2010 06:47 PM

oh sorry it worked for me because of a mistake



VFB+ : An enhanced 3dsmax frame buffer (free)

Replies: 0
avatar
  • hobbs
  • Posted: 01 September 2010 04:31 AM

If you just want copies of the same rollout.  I do this by having them in a struct, and then just make an instance of the struct.  Then you really don’t have to change your code much, because all the calls are the same.



Replies: 1
/img/forum/dark/default_avatar.png

Could you please post a sample code to prove your point?

Author: denisT

Replied: 01 September 2010 01:18 PM  
avatar
  • hobbs
  • Posted: 02 September 2010 04:00 AM

Hey, its hectic at work, so i won’t be able to test this, as my tool is way to large to post

but in essence.

You have a global variable, and a structure

-- This code is Not tested, more of psuedo code

(
global 
MultiRollout

struct RolloutClass
(
 
_ui,
 ------
 
fn init_roll =
 (
   
rollout _ui 
   
(
   )
  ),
 -----
  
fn Display =
  (
     
CreateDialog _ui
   
),
 -----
  
fn Run =
  (
    
init_roll()
   )
)
 
MultiRollout #()


MultiRollout[MultiRollout.count 1] =  RolloutClass()
MultiRollout[MultiRollout.count].Run()
MultiRollout[MultiRollout.count].Display()

/* repeat */

)

I think thats about it...sorry quick post



Replies: 1
/img/forum/dark/default_avatar.png

You said that you “… do this by having them in a struct...”. But the code that you posted can’t work. It can’t create multiple dialogs.

Author: denisT

Replied: 02 September 2010 11:21 AM  
avatar
  • hobbs
  • Posted: 03 September 2010 04:43 AM

ok, here...working code

just keep executing for multiple dialogs.. it even offsets for you.  Button prints the index of the rollout

(
 global 
MultiRollout

 struct _RolloutClass
 
(
 
this,
 
_ui,
 
_flag#notactive,
 
_index 1,
 
pos  [40,122],
 
width 100,
 
 ------
 
fn init_roll =
 (
 
rollout _ui "" height:100 width:100
 
(
 
button rollBtn "Print Count"  width:80 height:21
 
 local _index
 
 on rollBtn pressed 
do 
 ( 
messageBox ("Rollout Index " _index as string) )
 )
 ),
 -----
 
fn _Display =
 ( 
CreateDialog _ui pos:pos
 _ui
._index _index
 
),
 -----
 
fn GetPosition =
 ( 
 if 
_ui != undefined then 
 _pos 
getDialogPos(_ui )
 else 
_pos pos
 
 
/* return */ _pos
 
),
 -----
 
fn Run _classObj =
 ( 
 
_classObj.this _classObj
 _flag 
#active
 
init_roll()
 
_Display()
 )
 )

 --
////////////////////////////////
 
-- Run Tool
 
--///////////////////////////////
 
fn Multi 
 ( if 
MultiRollout == undefined then MultiRollout #()
 
 
local count MultiRollout.count
 local newCount 
count 1
 
 
case count of
 
(
 
0:( MultiRollout[newCount] _RolloutClass() )
 
 default:
 ( for 
1 to count do
 (
 if  
MultiRollout[i]._flag == #notactive then 
 
newCount i
 -- 
this makes it so if no ui's present, put back to original position
 if i !=1 then count = i-1
 else count = 1
 exit
 )
 )
 local _previous = MultiRollout[count]
 local _uiPosition  = _previous.GetPosition()
 
 MultiRollout[newCount] = _RolloutClass() -- create object
 MultiRollout[newCount].pos = [ _uiPosition [1] + _previous.width + 10, _uiPosition[2]] -- offset
 )
 )
 MultiRollout[newCount]._index = newCount
 MultiRollout[newCount].Run(MultiRollout[newCount])
 gc light:true
 ) 
 
 on execute do
 (
 Multi()
 
 )

/* repeat */

)


Replies: 0