ScriptSpot

Forum topic · General Scripting

save max file as maxversion 2010

By W DIGITAL · 2012-09-30

Description

hi
i was wondering how i can make a button that saves a max file as a previous version
i found the help but could not get the code to work

max file save [SaveAsVersion:2010]

or saveMaxFile etc. tried lots of things but never worked

what should i do?

thanks

Comments (8)

Hey Ian

Anubis · 2012-10-01

maybe something like this...

-- get the base file name w/o the extention ".max"
maxFile1 = getFilenameFile MaxFileName

-- remove the trail numbers
maxFile2 = trimRight maxFile1 "1234567890"

-- & get the trail numbers as Integer
intTrail = (subString maxFile1 (maxFile1.count-maxFile2.count) maxFile2.count) as Integer

-- format it to string with 4 digits
strNumb = formattedPrint (intTrail+1) format:"4.4d"

-- build the new file name
newFile = MaxFilePath + maxFile1 + strNumb + ".max"

-- & save
saveMaxFile newFile saveAsVersion:2010 quiet:on

barigazy · 2012-10-01

Hi Anubis.
Nice one, but if file is not saved before you run this code then

 
maxFile1 = getFilenameFile MaxFileName
-->""
-- remove the trail numbers
maxFile2 = trimRight maxFile1 "1234567890"
-->""
intTrail = (subString maxFile1 (maxFile1.count-maxFile2.count) maxFile2.count) as Integer
-- Error occurred in anonymous codeblock
--  Frame:
-- Runtime error: substring start out of range: 0

First you need to check if MaxFileName != ""

Yes, I know :)

Anubis · 2012-10-01

I think that Ian know this as well and w'd not try to increment unsaved scene, but you're right that the final code need to test for untitled scene.

Also I think that I s'd correct myself (in above code), as there a lot of time gone from my last work with Max :) and I presume that my untested code have some more logical mistakes, especially at the line where I extract the trailing numbers :)

So, if am not wrong, this s'd be more correct:

intTrail = (subString maxFile1 (maxFile2+1) -1) as Integer

barigazy · 2012-10-01

I fully understand you. Beside of that I also agree that every tester even try to detect small errors in the code and optimize the code for yourself.For me this is the most interesting part.
BTW I'm glad you're coming back on the scene. :)

W DIGITAL · 2012-09-30

thank barigazy!

do you know how to change this
newFile = MaxFilePath + MaxFileName
saveMaxFile newFile saveAsVersion:2010 clearNeedSaveFlag:false useNewFile:false quiet:true

to use max saveplus command?

max saveplus saves incrementally, but i cannot get it to work with this saveAsVersion code

W DIGITAL · 2012-10-01

no i dont need that one

just need the - max save plus -code to work with saveAsVersion:2010

barigazy · 2012-09-30

Are you try something like this

newFile = @"C:\Temp\testFile.max"
saveMaxFile newFile saveAsVersion:2010 clearNeedSaveFlag:false useNewFile:false quiet:true