Notifications
Clear all

[Closed] Renaming a label

I like your 100 Messages idea Only problem is they will hate me if it crashes their scene

Question, Im going the edittext route, what is the best “on” command to use so my textbox updates? The script I have is working with no errors, but it doesn’t update the change I make to the .text variable… Here is what I have in my button:

rollout SetUpStatus "Setup Status"
			(
				edittext txtIRStatus text:"Setup Status:" align:#center fieldwidth:190 height:350 readonly:true align:#center 
				
				on txtIRStatus changed do
				(
					txtIRStatus.text = "Test"
				)
			)
			createDialog SetupStatus 200 360

Shouldn’t “Setup Status:” get replaced with “Test” ??

First of all, the handler is never called because you set the field as "readOnly" (thus, it cannot be typed in). If you set the readOnly:false, you will get an error message that the argument count is wrong. 

The handler of an edittext control requires one argument after the "changed" and before the "do" which will contain the new text. MAXScript will send the one argument to the function defined by the handler, but since you defined the handler without any arguments, you will get the "expected 0, got 1" error.

This handler is called once per keystroke, while on yourTextControl Entered txt do() will be called when the text field loses focus (on Enter, Tab or mouse click outside of it).
rollout SetUpStatus "Setup Status"
    (
    edittext txtIRStatus text:"Setup Status:" align:#center fieldwidth:190 height:350 readonly:false align:#center
    on txtIRStatus changed txt do
    (
    	txtIRStatus.text = "Test"
    )
    )
    createDialog SetupStatus 200 360
If you type in the field, the word Test will appear instead.


If you want to display text in the field that comes from another source and avoid typing in from the user, you have two choices:

1. Keep the readOnly:true and remove the event handler (as it does not work). Instead, write a user function you can call with a string that will append to the text in the field and display the result.
rollout SetUpStatus "Setup Status"
    (
    	local infoString = "Setup Status:"
    	local theCounter = 0
    	button btn_pressMe "Press Me!"
    	edittext txtIRStatus text:infoString align:#center fieldwidth:190 height:350 readonly:true align:#center
    	fn updateInfo txt =
    	(
    		infoString += "
" + txt
    		txtIRStatus.text = InfoString
    	)
    	on btn_pressMe pressed do 
    	(
    		theCounter += 1
    		updateInfo ("The button was pressed " + theCounter as string + (if theCounter == 1 then " time" else " times"))
    	)
    )
    createDialog SetupStatus 200 360
2. Remove the readOnly or set it to false and use the event handler to override the entered text with the actual info text you want on each keypress. THis way, the user will TRY but never succeed to enter anything. See 1. for the way to display data.
rollout SetUpStatus "Setup Status"
    (
    	local infoString = "Setup Status:"
    	local theCounter = 0
    	button btn_pressMe "Press Me!"
    	edittext txtIRStatus text:infoString align:#center fieldwidth:190 height:350 readonly:false align:#center
    	fn updateInfo txt =
    	(
    		infoString += "
" + txt
    		txtIRStatus.text = InfoString
    	)
    	on txtIRStatus changed txt do txtIRStatus.text = InfoString
    	on btn_pressMe pressed do 
    	(
    		theCounter += 1
    		updateInfo ("The button was pressed " + theCounter as string + (if theCounter == 1 then " time" else " times"))
    	)
    )
    createDialog SetupStatus 200 360

The cool thing about this approach is that the user can still select text from the box and COPY it from there to paste into some text file or whatever…

I personally prefer using a ListBox for this kind of info because it can scroll down automatically. Obviously, you could do the same with the edittext above by prepending instead of appending the string:
	fn updateInfo txt =
    	(
    		infoString =  txt + "
" + infoString
    		txtIRStatus.text = InfoString
    	)
This will cause the latest line to be on top of the list and the old stuff will scroll off.

Here is how I would have done it:
rollout SetUpStatus "Setup Status"
    (
    	local theCounter = 0
    	button btn_pressMe "Press Me!"
	listbox lbx_Info items:#("Setup Status:")  width:195 align:#center height:24
    	fn updateInfo txt =
    	(
   		lbx_Info.items = append lbx_Info.items txt
   		lbx_Info.selection = lbx_Info.items.count
    	)
    	on btn_pressMe pressed do 
    	(
    		theCounter += 1
    		updateInfo ("The button was pressed " + theCounter as string + (if theCounter == 1 then " time" else " times"))
    	)
    )
    createDialog SetupStatus 200 360

Bobo, it’s working great with your code. I copied the code from the last example you provided and it runs with no problem… You are truely amazing! I will try to modify this code to work with reading from my main rollout and list the camera’s name when a button on my main rollout is pressed…

Thanks again!!

Im getting closer to getting it working correctly, Everything is working except for one minor problem now…

When the user presses the button on the Main Rollout a SECOND time, it does not update the popup rollout with text. It does work when the popup rollout is opened for the first time, but clicking the button again on the Main Rollout will not update my popup rollout, what is wrong with my code?

rollout SetUpStatus "Setup Status"
(
  local theCounter = 0
  listbox lbx_Info items:#("Setup Status:")  width:295 align:#center height:24
  fn updateInfo txt =
  (
	lbx_Info.items = append lbx_Info.items txt
	lbx_Info.selection = lbx_Info.items.count
  )
  on SetUpStatus open do
  (
	theCounter += 1
	selectedCam = viewport.getCamera()
	cameraN = selectedCam.name
	updateInfo ("'" + cameraN + "'" + " was setup for Irradience Map.")
  )
  on MainRollout.butStart pressed do
  (
	updateInfo ("'" + cameraN + "'" + " was setup for Irradience Map.")
  )
 )
createDialog SetupStatus 300 360

You cannot have a handler from the Main rollout placed in the second rollout.
All event handling is performed in the rollout where the handled controls are defined.
So if the butStart button is in the Main rollout, that’s where the handler should be.

Let’s start from the beginning.

Always put ALL your code in a local scope defined by outer brackets.
Then you can pre-declare the variable SetUpStatus that will be used later for the second rollout, which will make it visible to the first rollout EVEN BEFORE the second rollout has been defined.

Thus, when the handler is executed in the Main rollout, it will be able to call functions in the second rollout.

Here is an example where both rollouts are defined as local in the scope of the script and displayed in a single rollout floater which is global in order to be able to be closed when the script is being run again.

(--start local scope
global theCamScriptFloater --this will be the floater containing the two rollouts
local SetUpStatus --pre-declare the second rollout so the first one can "see" it
rollout MainRollout "Main Rollout"	
(
  button butStart "START!"
  on butStart pressed do
  (
	selectedCam = viewport.getCamera()
	if isValidNode selectedCam then
		SetUpStatus.updateInfo ("'" + selectedCam.name + "'" + " was setup for Irradience Map.")
	else
		SetUpStatus.updateInfo ("Viewport is NOT a Camera!")
  )
)
	
rollout SetUpStatus "Setup Status"
(
  listbox lbx_Info items:#("Setup Status:")  width:295 align:#center height:24
  fn updateInfo txt =
  (
	lbx_Info.items = append lbx_Info.items txt
	lbx_Info.selection = lbx_Info.items.count
  )
 )
try(closeRolloutFloater  theCamScriptFloater)catch() --try to close the floater if already open
theCamScriptFloater = newRolloutFloater "Camera Demo" 320 600 --create a new floater
addRollout mainRollout theCamScriptFloater  --add the main rollout to the floater
addRollout SetUpStatus theCamScriptFloater --add the second rollout to the floater
)--end script

And here is the same with two “independent” dialogs:

(--start local scope
global CameraUtility_MainRollout
global CameraUtility_SetUpStatus 
try(destroyDialog CameraUtility_MainRollout)catch() 
try(destroyDialog CameraUtility_SetUpStatus)catch() 
	
rollout CameraUtility_MainRollout "Main Rollout"	
(
  button butStart "START!"
  on butStart pressed do
  (
	selectedCam = viewport.getCamera()
	if isValidNode selectedCam then
		CameraUtility_SetUpStatus.updateInfo ("'" + selectedCam.name + "'" + " was setup for Irradience Map.")
	else
		CameraUtility_SetUpStatus.updateInfo ("Viewport is NOT a Camera!")
  )
  on CameraUtility_MainRollout moved pos do
	  SetDialogPos CameraUtility_SetUpStatus (pos+[0,225])
)
rollout CameraUtility_SetUpStatus "Setup Status"
(
  listbox lbx_Info items:#("Setup Status:")  width:295 align:#center height:24
  fn updateInfo txt =
  (
	lbx_Info.items = append lbx_Info.items txt
	lbx_Info.selection = lbx_Info.items.count
  )
 )
 
createDialog CameraUtility_MainRollout 200 200 100 100
createDialog CameraUtility_SetUpStatus 300 340 100 325
)--end script

As you will notice, thanks to the ON MOVED handler in the main dialog, the second dialog “sticks” to the first one when you move it, but you can move the second one independently.

These are, of course, just simple examples that do nothing but create dummy UIs.
You can turn either of them into a button on a toolbar by adding a MacroScript definition outside of the outside ( ) brackets, like

MacroScript CameraTool category:"Teriander Tools"
(
... --your code here
)

Bobo, Thanks for the reply on this! Im anxious to test this tomorrow morning! It looks like it should work well. Both methods… Evertime I read your script I learn a new method, or property that I never knew existed. Thanks for your support

Bobo,

I’ve tried both of your scripts, and they both work VERY well. You structured the examples so they are easily able to be modified. Thank you very much!!

Teriander

Page 2 / 2