So I'm making an exporter in maxscript
I have troubles writing the export path into a .txt file and reading it.
This is what I have:
-------------------------------------------------------------------------------------------
label labelExportFolder "Export folder" pos:[10,600]
edittext folderPathTxt "" pos: [10,620] width:140
button btnBrowse "..." pos: [160,620]
on btnBrowse pressed do
(
Global MyPath = ""
local dir = getSavePath caption:"path..."
if (dir != undefined) do ( folderPathTxt.text = dir )
append MyPath folderPathTxt.text as string
maxRootDir = getdir #maxroot
global TextFileName = (maxRootDir +"\\ExportPath.txt") if doesFileExist (maxRootDir +"\\ExportPath.txt") == false do
(
global TextFile = (createFile TextFileName)
format MyPath to:TextFile
close TextFile
)
if doesFileExist (maxRootDir +"\\ExportPath.txt") == true do
(
local replaceTxt = ""
MyPath = (openFile TextFileName mode:"r") as string
folderPathTxt.text = MyPath
close TextFile
)
)
-------------------------------------------------------------------------------------------
So I hope it's clear what I'm trying to do.
I'm not sure whether I should use the TxtFile or TextFileName
when i do "close TextFile" or "MyPath = (openFile TextFileName mode:"r")"
I guess the TextFileName just contains the path to the file that is created,
but I don't know what the TextFile variable is exactly. I'm confused
Replies
Max Help INI Files: http://goo.gl/Ex7LVx
try destroyDialog ::exportStuff catch() rollout exportStuff ( label labelExportFolder "Export folder" editText folderPathTxt across:2 button btnBrowse "..." button btnExport "Export" on btnBrowse pressed do ( local path = getSaveFileName types:"Text(*.txt)|*.txt|" if path != undefined do folderPathTxt.text = path ) on btnExport pressed do ( local fileName = folderPathTxt.text local textFile = if doesFileExist fileName then openFile fileName mode:"r+" else createFile fileName -- do the export here -- i.e. format ... to:textFile close textFile ) ) createDialog exportStuff
There's a 'How To ... Read/Write Geometry Data From/To Text File' topic in the help file, definitely read also 'Scope of Variables' and 'FileStream Values'.also for future reference, how do you put code in a separate window like you did?
I found some info on the MAXScript help but this didn't make any sense to me
setINISetting <filename_string> <section_string> <key_string> <key_value_string> [ forceUTF16:<boolean> ]
the <filename_string> is used to give the file a name and place.
I don't understand what the <section_string> , <key_string> and <key_value_string> do exactly. Couldn't wrap my head arround it.
Changed my code a bit, now I get this error:
--Runtime error: FileStream cannot create: E:\Max\3ds Max 2016\\ExportPath.txt
global MyPath = "no path"
maxRootDir = getdir #maxroot -- get max root file path
global TextFileName = (maxRootDir +"\\ExportPath.txt")
fn CreateTextFile =
(
global TextFile = (createFile TextFileName)
format MyPath to:TextFile
close TextFile
messagebox "created"
)
if doesFileExist (maxRootDir +"\\ExportPath.txt") == false do
(
CreateTextFile()
messagebox "file didn't exist, creating one"
)
label labelExportFolder "Export folder" pos:[10,600]
edittext folderPathTxt "" text:MyPath pos: [10,620] width:140 text: MyPath
button btnBrowse "..." pos: [160,620]
on btnBrowse pressed do
(
local dir = getSavePath caption:"path..."
if (dir != undefined) do ( folderPathTxt.text = dir )
MyPath = folderPathTxt.text as string -- get edittext content and put in MyPath
fs = openFile TextFileName mode:"r+" --opens the file -- <--- THIS IS WHERE THE ERROR HAPPENS
format "put this in" to:fs --this writes your text to the now open file
close TextFile
)
but i get this error: --Unable to convert: undefined to type: FileName
code is working, here it is: