Notifications
Clear all

[Closed] Update Text

Is it possible to use maxscript to change the text of a 3d text item and then render it and then go through the process many times? I know .net but not maxscript.

19 Replies

yes.

An Extruded Text shape:


 myTextObj = Text()
 select myTextObj
 addModifier myTextObj (extrude())
 

If you already have the Extruded Text shape object, select it, and use this this line:

myTextobj = $

An array of texts:


 myTexts = #("Hello","World","of","MaxScript")
 

You could then do something like:


 for myText in myTexts do (
 	myTextObj.text = myText
 	max zoomext sel
 	render()
 )
 

Which sets the text on the text shape, zooms the (non-camera) viewport so that the object fits within view, and then renders it.

The result of that render() can be sent to a bitmap file/etc.

Anything in particular you’re looking for?

wow thanks for the reply.
In particular I have a text object already in my scene which is animated, I want to be able to select it in code change the text value then render it to tgas or via format if possible, the render would be from a camera which is in the scene. this needs to be looped about 150 times reading in text from a file if possible.

well, the very basics would look something a little like this, perhaps…


rollout roll_test "test" (
	local obj_text, obj_cam, f_in, f_out
	pickbutton pick_txt "pick text object"
	pickbutton pick_cam "pick camera"
	button btn_selinfile "select input file"
	button btn_setoutfile "set output file"
	button btn_doit "do it"

	on pick_txt picked obj do ( obj_text = obj )
	on pick_cam picked obj do ( obj_cam = obj )
	on btn_selinfile pressed do (
		f_in = getOpenFilename()
	)
	on btn_setoutfile pressed do (
		f_out = getBitmapSaveFileName()
	)
	on btn_doit pressed do (
		local f = openFile f_in mode:"r"
		local counter = 0
		f_out_path = getFilenamePath f_out
		f_out_base = getFilenameFile f_out
		f_out_ext = getFilenameType f_out
		local displayBmp = bitmap renderWidth renderHeight
		while (not (eof f)) do (
			str = readline f
			counter += 1
			obj_text.text = str
			outFilename = f_out_path + f_out_base + (substring ((10000 + counter) as string) 2 -1) + f_out_ext
			render camera:obj_cam outputfile:outFilename vfb:false to:displayBmp
			display displayBmp
		)
		close f
	)
)
createDialog roll_test

There’s 5 buttons there. The first four you must press and pick valid targets (i.e. a text for the text button, a camera for the camera button, the input file for the file button and some bitmap filename for the output file) before you can press the ‘do it’ button.

When that button is pressed, the input file is opened and a line is read from it, that line is set as the text for the text object, then a render is called with the picked camera as its viewpoint. The result is then saved to the specified output bitmap file name with a counter added into the filename so that the filename with 0001 is from line 1 in the text file. It does this until it reaches the end of the input text file.

RTFM!

Look for “How do I change the text in a Text Shape dynamically?”

I did look in the manual first and obviously because I didnt find anything I thought I would ask some 3dsmax skilled people who seem to not mind giving me advice.
ZeBoxx2’s reply was much easier to understand than what is in the manual anyway.

What can I search for in the manual to learn how to call maxscript from .net, bobo? as this is my next topic ; )

that was a great bit of code btw ZeBoxx, thanks!

Looks like you’re out of a job Bobo!

J.

3 Replies
 JHN
(@jhn)
Joined: 11 months ago

Posts: 0

I’m not buying that, I read somewhere there where some plans to rename max to 3dsBobo… only to find that link…

;)ohan

(@lonerobot)
Joined: 11 months ago

Posts: 0

I love it! here’s a screenshot of the UI –

(@zeboxx2)
Joined: 11 months ago

Posts: 0

Oh goodness, I hope not – Bobo’s our best hope as far as the documentation goes

That said… the example referred to still uses ‘dependsOn’ ;\

After having to learn scripting in competing 3d products I soon realised how fantastic the mxScript docs really are.

So I have a script now that works well for my needs except that every so often in produces a unkown system exception error and I have to restart max and run it again.

Any help on why the below code might be causing this much appreciated : )

rollout roll_test "test" (
 	local obj_text, obj_cam, f_in, f_out
 	pickbutton pick_txt "pick text object"
 	pickbutton pick_cam "pick camera"
 	button btn_selinfile "select input file"
 	button btn_setoutfile "set output file"
 	button btn_doit "do it"
 
 	on pick_txt picked obj do ( obj_text = obj )
 	on pick_cam picked obj do ( obj_cam = obj )
 	on btn_selinfile pressed do (
 		f_in = getOpenFilename()
 	)
 	on btn_setoutfile pressed do (
 		f_out = getBitmapSaveFileName()
 	)
 	on btn_doit pressed do (
 		local f = openFile f_in mode:"r"
 		 while (not (eof f)) do (
 			 str = readline f
 			obj_text.text = str + "
																																										."
 			prefix = "Z:/PLAYERNAMES/" + str + "IN/" 
 			outfix = ".tga"
 			outputPath = prefix + str + outfix
 			if doesFileExist prefix == false then (
 				makedir prefix
 				render camera:obj_cam fromframe:0 toframe:16 outputfile:outputPath vfb:off
 				prefix = "Z:/PLAYERNAMES/" + str + "OUT/" 
 				makedir prefix
 				outfix = ".tga"
 				outputPath = prefix + str + outfix
 				render camera:obj_cam fromframe:25 toframe:50 outputfile:outputPath	vfb:off
 			)			
 		)
 		 close f
 	)
 )
 createDialog roll_test

Do you have any funky characters in the text file? like ” or / or \

Also, from what i gather you are checking to see if a file exists, but the string you are giving is a folder:

if doesFileExist prefix == false then (

Should it be this:?
if doesFileExist outputPath == false then (

Because prefix at that point is:
“Z:/PLAYERNAMES/” + str + “IN/”
and outputPath is:
“Z:/PLAYERNAMES/” + str + “IN/” + str + “.tga”

Page 1 / 2