|
|
|
Tell us what you think of the site.
|
Autodesk Media & Entertainment User Community
|
Autodesk® 3ds Max®
|
|
Autodesk® Maya®
|
|
Autodesk® Softimage®
|
|
Autodesk® MotionBuilder®
|
|
Autodesk® Mudbox™
|
|
Autodesk® ImageModeler™
|
|
Autodesk® Sketchbook® Pro
|
|
Autodesk® Smoke on Mac®
|
| Simple function question, -- Argument count error: *** wanted 2, got 1 <<
|
|
|
Hello there!
I am very new in maxscripts, please help me.
I d like to paste a string again an again into a file:
I get this:
-- Argument count error: appendtosavefile wanted 2, got 1 <<
my code:
appendtosavefile "MY_MODEL" filename
and my function:
fn appendtosavefile txt filename = (
print "------------------------"
print filename
print "------------------------"
myfile = openFile filename mode:"at"
format txt "%\n" to:myfile
close myfile -- !
--logtofile ("file appended "+txt) )
filename is:
“C:\kkk.lc3”
Thanks,
Leslie
|
|
|
|
( local filename = "C:/kkk.lc3" -- note forward slash! or use \\
fn appendtosavefile txt filename =
(
print "------------------------"
print filename
print "------------------------"
myfile = openFile filename mode:"at" -- file MUST exist!
format "%\n" txt to:myfile -- parameter order!
close myfile -- !
)
appendtosavefile "MY_MODEL" filename )
Unsure, without the full script, why you’re getting the parameter count error. The above works as expected.
A few points to note.
Max and backslashes - sometimes they work and sometimes they don’t. Use double backslashes or single forward slash (a la Unix) - they do work.
mode:"at" - the file MUST exist or you’ll get a “myfile undefined” error. Script should test if the file exists first, and if not, create it.
You have the parameters for “format” the wrong way round. the “format string” comes first, followed by the variables (or constant values) you want to print to the file and the “to:” last.
Max 4.2 through 2013.
XP-64 (SP2)
NVidia 9800GTX-512 (Driver 266.58).
Core 2 Quad Q6600 2.4GHz, 8Gb Ram, DX9.0c.
|
|
|
|
|
filename is coming from this:
selectedfilename=getsavefilename caption:"Save to LC3” filename:selectedlastfile types:"Lacroix LC3 (*.lc3)|*.lc3|All Files (*.*)|*.*|”
Is there a way to replace the \ to / with a replace function?
Leslie
Author: lacroix82
|
| Replied: 12 January 2012 11:53 PM
|
|
|
|
|
|
fn appendtosavefile txt = (
f=fopen selectedfilename "at"
writestring f (txt+"\r\n")
fclose f )
this is working, only matter:
in the lines begin I get a “null” character, why?
Author: lacroix82
|
| Replied: 13 January 2012 12:01 AM
|
|
|
|
|
Firstly, you didn’t tell us how you were deriving the filename. As I said, sometimes they work and sometimes they don’t - filenames returned from functions like getSaveFileName generally do work.
Secondly, the script in your 1st comment/reply won’t work (here) because you haven’t included the initialisation of “selectedlastfile” thus causing the script to fail. Try and provide code fragments which should work “as is” otherwise anyone answering the question will get different errors to the ones you are seeing (as in this case).
Finally - why have you changed the method of writing out the file when the original method works perfectly, and given yourself an easily avoidable new problem in the process? Stick with the openFile and format...to: thus avoiding the nulls issue entirely.
Max 4.2 through 2013.
XP-64 (SP2)
NVidia 9800GTX-512 (Driver 266.58).
Core 2 Quad Q6600 2.4GHz, 8Gb Ram, DX9.0c.
|
|
|
|
|
|