PDA

View Full Version : A few basic script questions...


ApocX
09-05-2006, 05:39 PM
Just working on a new script, and I've run into a few issues. Basically the script is supposed to export a txt file based on user information provided (which is later used in final model compiling) Anyways -

1.) Is there a way to implement a button that allows the user to choose a directory to output the file to? I assume this will only be stored once per session though - so additionally, is there a way for the script to remember the last path used?

2.) I'm using format to output the user data (so I can get rid of quotes etc...) But I have a condition which basically says:

If the user chooses this option from the dropdown - output line of text A. Otherwise output line of text B.

I've tried a number of things, but I've either gotten both lines output, or an error message indicating the if statement is looking for a boolean..

Thanks for any help you guys can offer!

_stev_
09-05-2006, 05:58 PM
In answer to #1, use the "GetSaveFileName" command and assign it to your button. You can store the chosen file name with path in your script with a variable, and display it in at text field.

Stev

davestewart
09-05-2006, 06:42 PM
Post the script...

_stev_
09-05-2006, 06:52 PM
Here's a small sample:


rollout sakTestRollout "Get Save File" (
local saveFile

button getButton "Get File"
editText getFile_text

on getButton pressed do (
saveFile = GetSaveFileName filename:"*.txt" types:"Text File (*.txt)|*.txt"
getFile_text.text = saveFile
)
)
createDialog sakTestRollout

ApocX
09-05-2006, 07:20 PM
on LC_Create pressed do
(
string_LC_Name = LCName.text
string_LC_Model = LCModelName.Text
string_LC_Type = LCType.selected

outputFile = createFile ("c:\\" + LCName.text + ".txt")

format "$modelname %.txt \n" string_LC_Model to:outputFile
format "$% \n" string_LC_Type to:outputFile

close outputFile
)


I'm still just dumping all this stuff down, and pretty new to maxscript, so don't mind the shotty layout :)

Anyways - my second question referred to placing an if statement around:

format "$% \n" string_LC_Type to:outputFile

I have a dropdown at the top that has three options. If I selected "static" then output:

format "$% \n" string_LC_Type to:outputFile

Otherwise output something else.

_stev_
09-05-2006, 08:11 PM
You can query the dropdown list selection when output to the file:

on LC_Create pressed do
(
string_LC_Name = LCName.text
string_LC_Model = LCModelName.Text
string_LC_Type = LCType.selected

if (myDropDownList.selection == 1) then (
outputFile = createFile ("c:\\" + LCName.text + ".txt")
format "$modelname %.txt \n" string_LC_Model to:outputFile
format "$% \n" string_LC_Type to:outputFile
)
if (myDropDownList.selection == 2) then (
<something else. . .>
)

close outputFile
)

Getting closer?
Stev

ApocX
09-06-2006, 10:54 PM
Thanks for your help stev!

One quick question - I'm having difficulty with the "format" command. I'm trying to out a line like this:

model "root" "root_model.x"

where root model is actually stored as a string - so the code looks something like this

format "model \"root\" % \n" string_LC_BodyModel to:outputFile

That comes out like

model "root" root_model.x

Just missing the last set of quotes around the model file.

Any help on this last bug of mine would be appreciated :)

HalfVector
09-06-2006, 11:08 PM
Should look like this:

format "model \"root\" \"%\"\n" string_LC_BodyModel to:outputFile

ApocX
09-07-2006, 12:29 AM
awesome - thats it. Thanks for your help!

ApocX
09-07-2006, 06:37 PM
Bah! One more problem - seems the compiler doesn't like an absolute path stored so I need to chop the following

modelname "C:\Projects\project\models\props_dev\dev_test.x"

to this:

modelname "props_dev\dev_test.x"

I'm actually storing the model path right now as:

string_LC_Model = LCGen_Common.LCModelName.Text

Searched the forums a bit, but haven't been able to get anything working the way I want it to...

Appreciate any help you guys can offer!

HalfVector
09-07-2006, 07:17 PM
Hi.

If you want to trim the full path:

"C:\Projects\project\models\props_dev\dev_test.x"

to:

"props_dev\dev_test.x"

You'll have to specify what the base path is. In this case would be:

"C:\Projects\project\models\\"

So you can write a function like this one:

fn trimPath basePath fullPath = (
if (findString fullPath basePath) != undefined do (
return ( substring fullPath (basePath.count + 1) (fullPath.count - basePath.count) )
)
return undefined
)

And make use of it like this:

basePath = "C:\Projects\project\models\\"
fullPath = "C:\Projects\project\models\props_dev\dev_test.x"
trimPath basePath fullPath

That will return the relative path:

"props_dev\dev_test.x"

Hope it helps.

ApocX
09-07-2006, 08:53 PM
Thanks - got it working now.

max8 supports an "initialdir" property when calling getsavepath(). Unfortunately this doesn't port over to max7. I'd like to setup starting directorys for each of the inputs...is this doable in max7?

CGTalk Moderation
09-07-2006, 08:53 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.