ScriptSpot

Forum topic · General Scripting

gui help

By roosterMAP · 2012-09-18

Description

I want to create a GUI that is basically a ton of buttons with different images, where each button runs a command who's name is based on the names of other scripts i have.

First, I don't know how to house all the buttons on a grid so that there is a scroll bar if need be.

Second, I want the buttons to be created depending on the files in my script folder. Each button will run a script in my script folder.

In summary, the buttons need to be generated, but I don't know how to procedurally create buttons, their names, and what they do (even though all that info is given by the title of the files in the script folder.)

Comments (22)

barigazy · 2012-09-18

buttons are not solution for that.
better try to use listbox, listview, or dopdown list.

roosterMAP · 2012-09-18

ok, i figured it out.

now I want to run commands i'v loaded in as strings.

for example:

myFiles[nameIndex] = "ringBolt()"

I want to run the command ringBolt()

Try

barigazy · 2012-09-18

execute "ringBolt()"

roosterMAP · 2012-09-18

strange, it didn't do what i expected.

Basically, I have converted a bunch of greebles into plugins using that primitive maker script. (http://www.scriptspot.com/3ds-max/scripts/primitive-maker)
I want to make a GUI that will let me browse through my primitives quickly. So i now have a listbox that automatically loads in all my plugins and when I select one, it spawns a primitive at the origin.
At the top of the GUI, an image of the currently selected greeble is displayed.

What I want it to do is make it exactly like when you click on one of "create primitive" buttons... where u can create and re-size a primitive when u click in a viewport.

So I guess my question is, whats the difference between running Box() in the listener, and actually clicking the button? and how can I replicate the button click in a listbox?

Use this line [your plugin class]

barigazy · 2012-09-18

StartObjectCreation
--example
StartObjectCreation Box
StartObjectCreation Line
StartObjectCreation Teapot
--etc.

roosterMAP · 2012-09-18

Kinda back to the last problem tho.
I keep getting this error: --Runtime error:startObjectCreation() requires a scene object class parameter, got "eyeBolt04"

Since it thinks eyeBolt04 is a string, it doesn't know what to do.
I tried it in the listener, and it works perfectly if I type in:
StartObjectCreation eyeBolt04

I just need to convert the string "eyeBolt04" into the command eyeBolt04.

Then my script will be finished!

barigazy · 2012-09-18

You need to know what is the plugin class name
Do following:
Create tour plugin object
in listener type next line

classof $


If listener throw, let say eyeBolt
then try whit this
startObjectCreation eyeBolt

Try this

MKlejnowski · 2012-09-18

Try doing what you did before with

execute "ringBolt()"

except create a new string with the StartObjectCreation


--Provided myFiles[nameIndex] is the string
Execute ("StartObjectCreation " + myFiles[nameIndex])

Or you could also use


StartObjectCreation (readvalue ("eyeBolt" as stringstream))

Also make sure its the

classof

of the object and nt th nam as barigazy has stated.

roosterMAP · 2012-09-18

thx! it works perfectly!

roosterMAP · 2012-09-19

new problem. lol

I am trying to update a bitmap everytime I click on an option in the listbox.

Here's what I tried, but it doesn't work. Any ideas?

Global String displayImage = "C:\Program Files\Autodesk\3ds Max 2011\plugins\greebles\images\blank.jpg"
bitmap templateBmp fileName: displayImage

--on testbox selection do:
displayImage = "C:\Program Files\Autodesk\3ds Max 2011\plugins\greebles\images\\" + finalString + ".jpg"
reload templateBmp

--finalString is the name of the image selected in the listbox

MKlejnowski · 2012-09-20

Are you trying to get something to change every time you change the selection of the listbox?

Are we talking about a Bitmap UI controller or are you referring to a simple bitmap?

Also doesn't hurt to throw up your actually code with to get and idea of what you are doing wrong and what could be done better.

I normally create a function with in the rollout called UpdateUI and just have the function run with each event handler to keep copies of code to a minimum. Also help in keeping debugging to a minimum if I only need to fix it in one place.


fn UpdateUI =
(
   --have all my code which affects the presentation of the ui go here
)

and then when i run an event handler for one of my controllers i always add the funtion to be executed last

UpdateUI()

barigazy · 2012-09-20

yep, without code we are chasing ghosts here.
Post the code or snippet if you know where is the problem if you want any help.That is the simple rule

roosterMAP · 2012-09-20

Here is what I got for my script. I just need to make the bitmap update. Iv tried the whole "create ui refresh within the rollout... but i kept getting errors.


(
	--_greebles.ms cannot be bigger than 700KB
	
	Global String finalString = "blank"
	Global String displayImage = "C:\Program Files\Autodesk\3ds Max 2011\plugins\greebles\images\ " + finalString + ".jpg"
	myFiles = getFiles "C:\Program Files\Autodesk\3ds Max 2011\plugins\greebles\\*.ms"
	folder = "C:\Program Files\Autodesk\3ds Max 2011\plugins\greebles"
	displayImage = replace displayImage 64 1 ""
	print displayImage
	--displayImage = bitmap 300 300 
	--display displayImage
	
	rollout gpGUI "Greebles Placment GUI" width:1024 height:1500
	(
		bitmap templateBmp fileName: displayImage
		checkbox autoGrid "AutoGrid" pos:[10,60]
		listbox greeblesListBox "Greebles:" items:(myFiles) pos:[0, 400] selection:1 height:50 readOnly:false
		button startCreate "GO!"
		
		on autoGrid changed theState do
		(
			actionMan.executeAction 0 "40462"  -- Views: AutoGrid
		)
		
		on greeblesListBox selected nameIndex do
		(
			--run command
			s = myFiles[nameIndex]
			s_temp = replace s (s.count-11) 12 ""
			s = replace s_temp 1 56 ""
			finalString = s
			reloadGUI()
		)
		
		on startCreate pressed do
			(
				execute ("StartObjectCreation " + finalString)
			)
	)
	createdialog gpGUI width: 1024 height:1024 --run template
	
	fn reloadGUI =
	(
		createdialog gpGUI width: 1024 height:1024 --run template
	)
)

?

barigazy · 2012-09-20

Can you describe step by step again what exactley you want to achive
with this tool. I fix a code a little but i don't know why do you need this size of UI. The code:

(
--_greebles.ms cannot be bigger than 700KB
local folder = @"C:\Program Files\Autodesk\3ds Max 2011\plugins\greebles"
local finalString = "blank"
local displayImage = folder + "\\" + finalString + ".jpg"
local myFiles = getFiles (folder+"\\*.ms")

local displayImage = replace displayImage 64 1 ""
print displayImage
--displayImage = bitmap 300 300
--display displayImage

rollout gpGUI "Greebles Placment GUI" width:1024 height:1500
(
bitmap templateBmp fileName:displayImage
checkbox autoGrid "AutoGrid" pos:[10,60]
listbox greeblesListBox "Greebles:" items:(myFiles) pos:[0,400] selection:1 height:50
button startCreate "GO!"

on autoGrid changed state do maxOps.autoGrid = state --AutoGrid
on greeblesListBox selected nameIndex do
(
--run command
local s = myFiles[nameIndex]
s_temp = replace s (s.count-11) 12 ""
s = replace s_temp 1 56 ""
finalString = s
reloadGUI()
)
on startCreate pressed do (execute ("StartObjectCreation " + finalString))
)
createdialog gpGUI width: 1024 height:1024 --run template

fn reloadGUI =
(
createdialog gpGUI width: 1024 height:1024 --run template
)
)

roosterMAP · 2012-09-20

basically, i've converted a bunch of my models into scripts. And I want to have this gui where i have a list of all these models in a list. I click on an object in the list and the bitmap updates to show me exactly what is being selected (i have a folder with one jpg per model).

now, when I select an object and press "go," and click and drag in the viewport, it will spawn and scale whichever model I have selected.

Right now, I have everything working except for the updating image.

barigazy · 2012-09-20

And what about this

(
--_greebles.ms cannot be bigger than 700KB
local folder = @"C:\Program Files\Autodesk\3ds Max 2011\plugins\greebles"
local finalString = "blank"
local displayImage = folder + "\\" + finalString + ".jpg"
local myFiles = getFiles (folder+"\\*.ms")
local displayImage = replace displayImage 64 1 ""

rollout gpGUI "Greebles Placment GUI" width:1024 height:1500
(
bitmap templateBmp fileName:displayImage
checkbox autoGrid "AutoGrid" pos:[10,60]
listbox greeblesListBox "Greebles:" items:(myFiles) pos:[0,400] selection:1 height:50
button startCreate "GO!"

on autoGrid changed state do maxOps.autoGrid = state --AutoGrid
on greeblesListBox selected nameIndex do
(
--run command
local s = myFiles[nameIndex]
s_temp = replace s (s.count-11) 12 ""
s = replace s_temp 1 56 ""
finalString = templateBmp.filename = s
)
on startCreate pressed do (execute ("StartObjectCreation " + finalString))
)
createdialog gpGUI width: 1024 height:1024 --run template
)

roosterMAP · 2012-09-20

Bitmap still not updating. I made a few changes to ur code (nothing substantial), but the bitmap is still stuck at C:\Program Files\Autodesk\3ds Max 2011\plugins\greebles\blank.jpg

Is there a command to redraw the bitmap with a new given filename?


(
	--_greebles.ms cannot be bigger than 700KB
	local folder = @"C:\Program Files\Autodesk\3ds Max 2011\plugins\greebles"
	local finalString = "blank"
	local displayImage = folder + "\\" + finalString + ".jpg"
	local myFiles = getFiles (folder+"\\*.ms")
 
	rollout gpGUI "Greebles Placment GUI" width:1024 height:500
	(
		bitmap templateBmp fileName:displayImage
		checkbox autoGrid "AutoGrid" pos:[10,60]
		button startCreate "GO!" pos:[10,100] width:50 height:50
		listbox greeblesListBox "Greebles:" items:(myFiles) pos:[12,328] selection:1 height:50
 
		on autoGrid changed state do maxOps.autoGrid = state --AutoGrid
 		on greeblesListBox selected nameIndex do
		(
			--run command
			local s = myFiles[nameIndex]
			s_temp = replace s (s.count-11) 12 ""
			s = replace s_temp 1 56 ""
			finalString = templateBmp.filename = s
		)
 		on startCreate pressed do (execute ("StartObjectCreation " + finalString))
	)
	createdialog gpGUI width: 1024 height:1024 --run template
)

barigazy · 2012-09-20

The problem must be string path
Try this
above line *finalString = templateBmp.filename = s*
put this


format "pathstring = %\n" s

and see what Listener throw.
Is path is correct than try another trick
above line *finalString = templateBmp.filename = s*
put this line

 
templateBmp.filename = undefined

This will remove current bitmap file and next line will be add new one.
And if all of that not help then the problem is map resolution for sure.

roosterMAP · 2012-09-20

Now it works. It was the path string that was wrong.

The problem was the line where you reinitialize finalString.

I just replaced it with the following:


finalString = templateBmp.filename = folder + "\\" + s + ".jpg"

Now it works.

Thx so much for all ur help! Still learnin. :)

barigazy · 2012-09-20

glad i'm help man.
Just keep up
Cheers!

MKlejnowski · 2012-09-21

why not nest the local variables into the actual rollout and set them with the rollout "open" event handler? Wouldn't that remove the need to nest the code in brackets?

barigazy · 2012-09-21

It is the same.I always place locls / globals at the top for the clality. The bruckets can be used later if the user decide to create macroscript.
By the way, all scripters has a different style,but if everyone used the same pattern, then the MXS and other languaes would not be much interesting. Agreed!

:)