PDA

View Full Version : Add a dynamic text in panel rollout


ejann99
04-05-2008, 01:19 AM
Hi,all. I made a scripted primitive in Create panel . When this scripted primitive created , I switch to Modify panel. I loaded a file by clicking a button in panel rollout . Now I want to show the file name in the edittext or label format in Modifier panel rollout. Could someone help me?

Bobo
04-05-2008, 02:13 AM
Hi,all. I made a scripted primitive in Create panel . When this scripted primitive created , I switch to Modify panel. I loaded a file by clicking a button in panel rollout . Now I want to show the file name in the edittext or label format in Modifier panel rollout. Could someone help me?

What exactly does NOT work? Anything you have tried and failed?

In general, you just assign the string to the .text property of an edittext or label control and it will be displayed. If the edittext is connected to a paramblock parameter, whatever is entered in the field will be stored in the parameter and saved with the Max file, plus the display will be handled automatically.

ejann99
04-05-2008, 02:52 AM
Below is a portion code.
So ...need help:)
parameters main rollout: params ( chgName type:#integer animatable:false ui:chkBtn default:0
on chgName set val do (if val == 1 then (
--how to code here to change text in edittext box.
)
)
)

rollout params "Change text" ( checkbutton chkBtn "Click to change None"
edittext edtName text:"None"
)

Bobo
04-05-2008, 06:17 AM
Checkbutton and Checkbox should be connected to a Boolean parameter, not Integer. MAXScript, other than most other languages, does NOT use Integers to perform boolean operations directly. 0 is not the same as false and non-zero is not true in MAXScript, so you have to use the dedicated Boolean value.

Here is a quick demo of how it is done:

plugin simpleObject TestObject
name:"TestObject"
classid:#(0x68175071, 0x60425371)
category:"Tests"
(
local params --pre-declare the rollout to make it visible to the paramblock

parameters main rollout: params
(
chgName type:#boolean animatable:false ui:chkBtn default:false --change to boolean
on chgName set val do --if state changed,
(
if val then --if the value is true or false, show different strings
params.edtName.text = "Somebody Checked Me!"
else
params.edtName.text = "I am Soooo Unchecked..."
)
)

rollout params "Change text"
(
checkbutton chkBtn "Click to change None"
edittext edtName text:"None"
)

tool create
(
on mousePoint click do
(
case click of
(
1: (nodeTM.translation = gridPoint; #stop)
)
)
)
)

Copy, evaluate, go to Create>Tests category, click the TestObject button and click once in the viewport. It does not have any mesh representation, but the UI will be there. Switch to Modify panel and play with the checkbox...

Bobo
04-05-2008, 06:50 AM
Here is an alternative version. Instead of setting the string in the rollout, this one creates a parameter linked to the edittext field in the rollout. The handler in the paramBlock simply sets that parameter's value and the edittext is updated automatically. This is better because the parameter would be saved with the file, so next time you open the scene, the text would still be correct!

plugin simpleObject TestObject
name:"TestObject"
classid:#(0x68175071, 0x60425371)
category:"Tests"
(
parameters main rollout: params
(
chgName type:#boolean animatable:false ui:chkBtn default:false
nameString type:#string ui:edtName default:"None"
on chgName set val do
(
nameString = if val then
"Somebody Checked Me!"
else
"I am Soooo Unchecked..."
)
)

rollout params "Change text"
(
checkbutton chkBtn "Click to change None"
edittext edtName text:"None"
)

tool create
(
on mousePoint click do
(
case click of
(
1: (nodeTM.translation = gridPoint; #stop)
)
)
)
)



Yet another way to do it (but not as good) would be to handle the text display in the rollout code only. Each time the checkbox is checked or the rollout is open, you would have to update the string by calling a special user-defined function. This method is useful if the string itself plays no role in the code of the plugin and you don't want to pollute the paramBlock with extra parameters just to store some message.
Also note that if somebody would change the state of the parameter in the paramBlock externally via another script or whatever, the UI will NOT know about the change and will not refresh automatically, while the previous versions would as they depend on the parameter handler's notification.

plugin simpleObject TestObject
name:"TestObject"
classid:#(0x68175071, 0x60425371)
category:"Tests"
(
parameters main rollout: params
(
chgName type:#boolean animatable:false ui:chkBtn default:false
)

rollout params "Change text"
(
checkbutton chkBtn "Click to change None"
edittext edtName text:"None"

fn updateText =
(
edtName.text = if chgName then
"Somebody Checked Me!"
else
"I am Soooo Unchecked..."
)
on chkBtn changed state do updateText()
on params open do updateText()
)

tool create
(
on mousePoint click do
(
case click of
(
1: (nodeTM.translation = gridPoint; #stop)
)
)
)
)

ejann99
04-05-2008, 10:32 PM
Thanks a lot, bobo.Now I have a new problem...
I set up a controller and give it to a parameter "myNumber". The problem is when I move the time slider, the spinner changes its value . While the spinner's value is changing throug time to time, nothing happened to it's event handle.
plugin simpleObject TestObject
name:"TestObject"
classid:#(0x68175071, 0x60425371)
category:"Tests"
(
local params --pre-declare the rollout to make it visible to the paramblock

parameters main rollout: params
(
myNumber type:#integer animatable:true ui:spnNum default:0 --change to boolean
on myNumber set val do (
format "mynumber:%\n" val
params.edtName.text = "myNumber is " + ( val as string)
)
)

rollout params "Change text"
(
button btnTest "setAnimation"
edittext edtName text:"None"
spinner spnNum "myNumber" range:[-1000,1000,0]
fn setAnimation =
(
local tmpCntrl = linear_float()
addnewkey tmpCntrl 10
addnewkey tmpCntrl 80
tmpCntrl.keys[1].value = 100
tmpCntrl.keys[2].value = 800
myNumber.controller = tmpCntrl
)
on btnTest pressed do setAnimation()
)

tool create
(
on mousePoint click do
(
case click of
(
1: (nodeTM.translation = gridPoint; #stop)
)
)
)
)

Bobo
04-06-2008, 03:54 AM
Animation via controller is NOT a SET event for the handler - the controller is part of the track and changing time is not considered by the handler.
Only if you spin the spinner with the mouse or change the track via MAXScript by saying

$TestObject01.myNumber = 110
-->mynumber:110
-->110

or

$TestObject01.params.spnNum.value = 120
-->mynumber:120
-->120

the event handler will be executed and the text will be printed.
I am not sure what exactly you are trying to do, but this is how things work. You should probably explain what you want to do with your script and why you feel MAXScript is not letting you do it... :)

ejann99
04-07-2008, 05:58 AM
I want to create a object , it can read external file frame by frame.
Thank u bobo, eventually, I solved the problem.

CGTalk Moderation
04-07-2008, 05:58 AM
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.