PDA

View Full Version : Update Text


[LP] it is me!!
03-09-2009, 01:26 PM
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.

ZeBoxx2
03-09-2009, 01:49 PM
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?

[LP] it is me!!
03-09-2009, 02:19 PM
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.

ZeBoxx2
03-09-2009, 03:04 PM
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.

Bobo
03-09-2009, 03:46 PM
it is me!!']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.

RTFM! :)

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

[LP] it is me!!
03-09-2009, 05:34 PM
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!

j-man
03-10-2009, 12:11 PM
Looks like you're out of a job Bobo!

J.

JHN
03-10-2009, 01:08 PM
Looks like you're out of a job Bobo!

J.

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

;)ohan

ZeBoxx2
03-10-2009, 01:09 PM
Looks like you're out of a job Bobo!

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' ;\

djlane
03-10-2009, 03:05 PM
After having to learn scripting in competing 3d products I soon realised how fantastic the mxScript docs really are.

LoneRobot
03-10-2009, 08:40 PM
I'm not buying that, I read somewhere there where some plans to rename max to 3dsBobo... only to find that link....

;)ohan

I love it! here's a screenshot of the UI -

http://www.lonerobot.com/images/3dsbobo.jpg

[LP] it is me!!
03-11-2009, 05:19 PM
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 + "\r\n ."
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

dutch_delight
03-12-2009, 02:55 PM
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"

dellis
03-12-2009, 03:27 PM
LoneRobot...thats hilarious...took me a second to get the joke. Now where did i put that coffee....

[LP] it is me!!
03-12-2009, 08:03 PM
Thanks for the replies..
Yeh its checking to see if a folder exists which is how i want it.
There are no strange characters in the text file.
It doesnt break at a specific point and if you restart the script from where it broke it will do that name fine.
I think the renderer is crashing it halts at the render line, I read in the manual that you should change text using a controller else the renderer crashes, not really sure how to do that.. any ideas?

ZeBoxx2
03-12-2009, 08:05 PM
the example should be fine, actually - that warning is only when you're trying to render an animation (which is not really appropriate in this case as you're reading lines from a text file - you'd have to set the animation range to match the number of lines in that file first, etc.)

That said - an example of how to change text, using a controller, is in the topic Bobo mentioned near the top of this thread :)

JHN
03-13-2009, 09:10 AM
That said - an example of how to change text, using a controller, is in the topic Bobo mentioned near the top of this thread :)
*proest

-Johan

[LP] it is me!!
03-13-2009, 11:24 AM
that warning is only when you're trying to render an animation
Dont really understand what you mean by that.. I am rendering an animation for each line of text in a text file.

As I said i have read that section of the manual but its not clear to me, I do only have 3 days experience with maxscript :sad:

ZeBoxx2
03-13-2009, 01:18 PM
I'll elaborate :)

The example given in the MaxScript documentation - and which includes the warning that you should use a controller - is for when rendering an actual animation range through the standard 3ds Max render scene dialog/etc. The same as you would render any specific animation.

When going with the script I posted earlier, you're not really rendering an 'animation' - you're rendering one single frame each time, and saving that out. The difference to us humans is pretty vague, but as far as 3ds Max is concerned, there's a whole world of difference.

For example, you can't create/delete objects when rendering an animation in 3ds Max, as 3ds Max 'caches' some of the information about the scene when rendering an animation, and it doesn't pick up on these node changes. But you're absolutely free to render one single frame, after which max clears that cache, then create/delete the object(s), then render one single frame again, etc.

You could use the controller form.. then it'd look something like this:

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

on pick_txt picked obj do ( obj_text = obj )
on btn_selinfile pressed do ( f_in = getOpenFilename() )
on btn_doit pressed do (
local f = openFile f_in mode:"r"
persistent global textLines
textLines = #()
while (not (eof f)) do (
append textLines (readline f)
)
close f

animationRange = (interval 1 textLines.count)
sc = (obj_text.kerning.controller = float_script())
sc.addNode "textObject" obj_text
sc.script = "
if (textLines != undefined) then (
try ( textObject.text = textLines[(currentTime as integer / ticksPerFrame)] )
catch ( textObject.text = \"-- error --\" )
)
else ( \"-- textLines missing --\")
1.0"
)
)
createDialog roll_test

Note that you no longer pick a camera or the output filename - you would just render whatever viewport / camera view you would like, to whatever filename you would like, through the Render Scene Dialog.

The meat of the script is that it...
1. reads all lines from the text file into an persistent array (saves with the .max scene file)
2. changes the scene's animation range to range from 1 to the number of lines read
3. sets up a controller on the text object's 'kerning' value (making the presumption you don't use that) that...
4. changes the text of the text object to the Nth string in the aforementioned array, where N depends on the current frame

You can scrub the viewport and see the effect - same should happen when rendering (make sure you render the active time segment - if you render outside of the valid range of lines, the text will read "-- error --")

[LP] it is me!!
03-13-2009, 05:23 PM
Ah ok I guess I will stick with what I've got as im not clued up on maxscript enough to do anything more advanced.. the script I have works it just needs some user interaction when the error occurs, not too much of a big deal.
Thanks for the advice, i appreciate it.

CGTalk Moderation
03-13-2009, 05:23 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.