PDA

View Full Version : selection changes update text string


GPorter
02-20-2006, 08:31 PM
I am trying to get into maxscript to make a few scripts that make acad users a bit faster in max. I am having a really difficult time understanding the maxscript help file that comes with 3ds. Seems everytime I change to a new topic and think I understand the 'code' I wind up with the wrong syntax etc...

alright, here is what I have so far:
--GUI------------------------
Rollout MoveTool "MoveTool"
(
button btn1 "Done" pos:[23,79] width:109 height:20
spinner spn3 "x" pos:[18,11] width:119 height:16 range:[-10000,10000,0] type:#worldunits
spinner spn5 "y" pos:[18,33] width:119 height:16 range:[-10000,10000,0] type:#worldunits
spinner spn6 "z" pos:[18,56] width:119 height:16 range:[-10000,10000,0] type:#worldunits
label thelabel "ready" pos:[20,110]
-- on select $ changed do
-- (
-- ary=getcurrentselection()
-- x=ary.count as string
-- thelabel.text=(x + " selected")
-- )
on movetool open do
(
ary=getcurrentselection()
x=ary.count as string
thelabel.text=(x + " selected")
)
on btn1 pressed do
(
destroydialog movetool
)
on spn3 changed val do
(
move $ [spn3.value,0,0]
spn3.value = 0
thelabel.text="moved"
)
on spn5 changed val do
(
move $ [0,spn5.value,0]
spn5.value = 0
)
on spn6 changed val do
(
move $ [0,0,spn6.value]
spn6.value = 0
)
)
CreateDialog movetool 150 130 mouse.screenpos.x mouse.screenpos.y

-------------
The lines I have remarked out are the ones I am trying to get working.

Whenever the current selection changes I want the label of the dialog to update with the number of items currently selected.

When I get that taken care of, I want to have the spinners greyed out if there are 0 objects selected.

I have looked at the event handlers section of the help and can't make heads or tails of how I need to write this correctly.

Can anyone point me to a source where I can learn the right way of constructing maxscripts rather than hunting and pecking until it finally works???

Thanks,
Greg

Bobo
02-21-2006, 02:52 AM
Can anyone point me to a source where I can learn the right way of constructing maxscripts rather than hunting and pecking until it finally works???



Look up "General Event Callback Mechanism".
You were trying to use an on select $ changed() handler which does not exist in a rollout.
The documentation cannot make right assumptions about what wrong assumptions a user might make. Callbacks are an advanced topic but you assumed it is something everybody does all the time (which is not the case)

Welcome to the MAXScript syntax hunt! :)

GPorter
02-21-2006, 03:17 PM
Ok... I spent all night trying to figure this one out. I think I am close, but I am missing something. I simplified the whole thing, so I am just working with the label... I have got my function working when I press my button, but it doesn't work when I change selections. Can anyone see what I am doing wrong.
------------------------
global selnum_ro
rollout selnum_ro "Selection Set Number"
(
button but1 "press"
label thelabel "ready"
fn updatetext x =
(
x.text=selection.count as string
)
--on but1 pressed do updatetext(thelabel)
on selnum_ro close do callbacks.removescripts #selectionsetchanged id:#cb1
)
callbacks.addScript #selectionSetChanged "selnum_ro.updatetext(thelabel)" id:#cb1 createdialog selnum_ro width:200 Height:200

GPorter
02-21-2006, 10:04 PM
I got it!!! I needed to have (selnum_ro.theLabel) instead of thinking that maxscript could read my mind.

Thanks for the help BOBO!

I would still like to know a source so I can find out the proper construction for scripts. Seems like every tutorial starts in the middle somewhere. When I look stuff up in the help it always says:
Formally, the syntax of a <rollout_clause> is defined as follows:

<rollout_clause> ::= <local_variable_decl> | <local_function_decl> | <local_struct_decl> | <global_variable_decl>|<mousetool> | <user_interface_item> | <item_group> | <event_handler>

I know if I type stuff in with <> and | I get problems, sometimes I need quotes or {} or []. Where can I find the base information of how to read and understand the maxscript help?

Thanks again,
Greg

Bobo
02-21-2006, 11:04 PM
I got it!!! I needed to have (selnum_ro.theLabel) instead of thinking that maxscript could read my mind.

Thanks for the help BOBO!

I would still like to know a source so I can find out the proper construction for scripts. Seems like every tutorial starts in the middle somewhere. When I look stuff up in the help it always says:
Formally, the syntax of a <rollout_clause> is defined as follows:

<rollout_clause> ::= <local_variable_decl> | <local_function_decl> | <local_struct_decl> | <global_variable_decl>|<mousetool> | <user_interface_item> | <item_group> | <event_handler>

I know if I type stuff in with <> and | I get problems, sometimes I need quotes or {} or []. Where can I find the base information of how to read and understand the maxscript help?

Thanks again,
Greg

There is a chapter John Wainwright (the MAXScript creator) wrote in the original MAXScript Reference explaining all these syntax rules. It is called "Syntax Definitions in this document".
In addition, I wrote a Frequently Asked Questions entry (under the chapter with that name, sub-chapter "MAXScript Syntax and Terminology") called "How Do I understand the function defintions in this document". It explains what a < rule > is, what an [ optional parameter ] is and should give you the basics.
Also see the other topics in this chapter...

In short, your example means that a rollout clause can be any of these: local variable, a local function, a local struct, a global variable, a mouse tool, a user interface control, a group or an event hander. This basically explains what the parser is expecting when reading the body of a rollout.

Examples:

rollout test "Test" (
local bobo = "Bobo" --local variable
global bobo2 = "MAXscript" --global variable
fn testFunction arg = (print arg) --a local function
group "My Controls" --a UI group
(
spinner spn_value "Value" --a User Interface item (control)
)
on spn_value changed val do testFunction val --an event handler
)

As you can see, all these (and more) are allowed by the syntax definition.

But

rollout test2 "Test No Workie"
(
print "Opening Rollout..."
)

Will cause an error because PRINT doesn't match any of the rules.

-- Syntax error: at string, expected name
-- In line: print "Opening Rollout..."

GPorter
02-23-2006, 05:38 PM
perfect... That's what I needed.


Thanks again.

CGTalk Moderation
02-23-2006, 05:38 PM
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.