Bobo's "fast tool development" video

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 04 April 2013   #16
Originally Posted by Mambo4: what about


 
 [...]
 
                  local owner = if owner != undefined do owner
 
 [...]
  		on create do
  		(
  			destroy()
  			rollouts.owner = this
  		)
 
 


the latter part seems to set a .owner property to the struct
but what's the first part do? seems odd to "do" a property...


that's also the trick that belongs to me... this little hack prevents the property from overwriting at the time of a rollout creating.
 
Old 04 April 2013   #17
Originally Posted by denisT: that's also the trick that belongs to me... this little hack prevents the property from overwriting at the time of a rollout creating.

I can't clearly understand it. Any example?
Originally Posted by denisT: so the modern paradigm for a tool is "one tool - one global"

usually, I tend to construct a definite file structure to manage my tool files.
Like
init.ms at the top of my file structure maybe with only two lines in it.
global myTool_path = getFilenamePath(getSourceFileName());
fileIn "FileStructrue/tool.ms"

under FileStructrue folder there is tool.ms with many include like

include "FileStructrue/lib/UIlib.ms"
include "FileStructrue/lib/Functionlib.ms"
.....

I like the idear "one tool - one global". But I also want to keep my fileStucture to keep things clear. Is there a general pratical way to do this? note that the variable "myTool_path" in the init.ms is important for most of my tool is drop-in tool.
 
Old 04 April 2013   #18
Originally Posted by HuaMuLan: I can't clearly understand it. Any example?

my snippet is a sample. try to remove the owner definition and check the difference
Quote: usually, I tend to construct a definite file structure to manage my tool files.
Like
init.ms at the top of my file structure maybe with only two lines in it.
global myTool_path = getFilenamePath(getSourceFileName());
 fileIn "FileStructrue/tool.ms"
 

under FileStructrue folder there is tool.ms with many include like

 include "FileStructrue/lib/UIlib.ms"
 include "FileStructrue/lib/Functionlib.ms"
 .....
 


i never use include in my max scripting. i use filein only in macroscripts to call main code.
 
Old 04 April 2013   #19
That's odd. I comment out parts of the code like this

local owner -- = if owner != undefined do owner

My listener says

>> MAXScript Rollout Handler Exception: -- Unknown property: "dialogWidth" in undefined <<
>> MAXScript Rollout Handler Exception: -- Unknown property: "dialogWidth" in undefined <<

According to the code logic, if owner is undefined "do owner" will not execute. So logically, there are no difference before and after I comment out these codes.
I am lost. Ha~.
 
Old 04 April 2013   #20
Originally Posted by denisT: here is it:

 global GeneralSceneOps 
 (
 	struct GeneralSceneStruct
 	(
 		fn destroy = try(closeRolloutFloater GeneralSceneOps.dialog) catch(),
 		
 		title = "General Scene Helpers",
 		dialogWidth = 250,
 		dialogHeight = 400,
 		dialog,
 		
 		MatStruct =
 		(
 			struct MatStruct (material, slot)
 		),
 		ObjectRollout = rollout ObjectRollout "Objects"
 		(
 			local owner = if owner != undefined do owner
 			button deleteall_bt "Delete All Objects" align:#left width:(owner.dialogWidth - 30) offset:[-5,0] 
 			on deleteall_bt pressed do undo "Delete All" on
 			(
 				format ">>> %\n" owner
 				delete objects
 			)
 		),
 		materials = #(),
 		MaterialRollout = rollout MaterialRollout "Materials"
 		(
 			local owner = if owner != undefined do owner
 			button collectmats_bt "Collect Editor Materials" align:#left width:(owner.dialogWidth - 30) offset:[-5,0]
 			on collectmats_bt pressed do 
 			(
 				owner.materials = for k=1 to 24 collect (owner.MatStruct (medit.GetTopMtlSlot k) k)
 				format "mats: %\n" owner.materials
 			)
 		),
 		rollouts = #(ObjectRollout, MaterialRollout),
 		fn show = 
 		(
 			destroy()
 			dialog = newRolloutFloater title dialogWidth dialogHeight
			for r in rollouts do addRollout r dialog
		),
 		on create do
 		(
 			destroy()
 			rollouts.owner = this
 		)
 	)
 	GeneralSceneOps = GeneralSceneStruct()
 	ok
 )
 GeneralSceneOps.show()
 

this snippet mostly shows my style of tool design. don't try to find a sense in the button functions


What about this error ?
It seems that you cannot use nested structs with this tool design. Try this:
global genericGlobal
(
    struct genericTool
    (
        Element =
        (
            struct Element ( member )
        ),

        ElementArray =
        (
            struct ElementArray ( objs = #(Element) )
        ),

        testArray = #(),

        on create do
        (
            print (ElementArray());
        )
    )
    genericTool();
)


Denis, have you ever had this kind of problems ?
 
Old 04 April 2013   #21
Originally Posted by feranti: What about this error ?
It seems that you cannot use nested structs with this tool design. Try this:
global genericGlobal
 (
     struct genericTool
     (
         Element =
         (
             struct Element ( member )
         ),
 
         ElementArray =
         (
             struct ElementArray ( objs = #(Element) )
         ),
 
         testArray = #(),
 
         on create do
         (
             print (ElementArray());
         )
     )
     genericTool();
 )


Denis, have you ever had this kind of problems ?

there is no problem in your sample. it looks just as wrong definition for me. here is how i would do the same:

global genericGlobal
(
	struct genericTool
	(
		Element =
		(
			struct Element ( member )
		),

		ElementArray =
		(
			struct ElementArray ( objs = #() )
		),

		testArray = #(),

		on create do
		(
			print (ElementArray objs:#(Element));
		)
	)
	genericTool();
)

but it doesn't make sense for me to have a struct definition (Element) as array item instead of have its instance.
 
Old 04 April 2013   #22
Quote: but it doesn't make sense for me to have a struct definition (Element) as array item instead of have its instance.

In that simple case, I agree with you. It was only a short snippet to highlight the nested structs design. The array is a bad idea there because it often starts empty...

This following snippet might be more the problematic case:
global genericGlobal
(
	struct genericTool
	(
		Element =
		(
			struct Element (member)
		),
		
		NestedElement = 
		(
			struct NestedElement
			(
				nested = Element(),
				anotherMember
			)
		),
		
		testArray = #(),
		
		on create do
		(
			local test = NestedElement();
			print test
		)
	)
	genericTool();
)


This kind of nested definition can occur often enough, in my opinion.

I wanted to know if there was any workaround for that. This kind of structure definition works when the struct are not nested under one single struct.

Edit: Obviously, you could fill the "nested" property each time you create one instance of the NestedElement() struct but it is a pain...

Last edited by feranti : 04 April 2013 at 03:16 PM.
 
Old 04 April 2013   #23
here is a workaround:
global genericGlobal
(
	struct genericTool
	(
		NestedElement = 
		(
			struct NestedElement
			(
				Element =
				(
					struct Element (member)
				),
				nested = Element(),
				anotherMember
			)
		),
		
		testArray = #(),
		
		on create do
		(
			local test = NestedElement()
			print test
		)
	)
	genericTool()
)
 
Old 04 April 2013   #24
Ok... I still think it is quite dirty because you need to declare the Element struct as many times as you want to nest it into another struct but... it is a workaround !
 
Old 04 April 2013   #25
Originally Posted by feranti: Ok... I still think it is quite dirty because you need to declare the Element struct as many times as you want to nest it into another struct but... it is a workaround !

i'm not sure that you clear understand how structs and struct definitions works...
there is another way to do want you want:
global genericGlobal
(
	struct Element (member)
	struct genericTool
	(
		NestedElement = 
		(
			struct NestedElement
			(
				nested = Element(),
				anotherMember
			)
		)
	)
	genericTool()
)

use nested structs where they work...
 
Old 04 April 2013   #26
We agree on that last one !
I ended up with that, too.

At first, I was trying to declare all my structs inside the genericTool struct because I don't use (at the moment...) the big global encapsulating brackets design (cf. my posts earlier).
So, to avoid having my structs declared as global, I was looking for a way to embed their declarations in my tool struct.
Then I hit this nested definition problem...

Anyways, thanks for the quick answers Denis
I think it is time to convert myself to the global encapsulation religion
 
Old 04 April 2013   #27
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 06:31 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.