disable xref scenes + save an incremental copy and enable the disabled xref scenes script :) by anubis and miauu thanks alot

Hey All,

I am trying to form an "xref scene based architectural workflow" but there s one faulty design that spoils it and the only way to solve it goes through two simple commands but i can not find it, and i am 0 at scripting either, incase someone decides to help with it.

i need to have the script disable all xref scenes , d some commands and enable them back.

(
--this line should disable every xref scene loaded into to the current scene

if maxFileName != "" then ( -- if the scene saved
max saveplus -- incremental file save
TheFile = maxFilePath + (trimRight (getFilenameFile maxFileName) "1234567890") + ".max" --remove trailing numbers
if doesFileExist TheFile do deleteFile TheFile
copyFile (maxFilePath + maxFileName) TheFile
) else checkForSave()
--this line should enable every xref scene loaded into to the current scene
)
so this saves a file but it will be removing all xref scenes before saving, and re-enable them forr the artist to go on.
btw, the middle code is written by Anubis ;) thanks to him.
thanks for any input.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
tomastnt's picture

No disable xref, but REMOVE

Hi dear,
I would like to use this script, but I need REMOVE xref, save to separate file and then again ADD xref back and save to previous file. practicaly I would like to create a copy max file where is no sxref and name of that file is every time same. I have modified this script, but it is only disabling xref and I don't know how to rewrite it for removing xref. Here is it. Any help will be much much appreciated! Thanks Tomas.

(
if maxFileName != "" then
( -- if the scene saved
local enabledXRefIndex = #()
for i = 1 to xrefs.getXRefFileCount() where ((xrefs.getXRefFile i).disabled == false) do
(
(xrefs.getXRefFile i).disabled = true -- disable the xref
append enabledXRefIndex i -- store the index of the active xref scenes
)

filename = (maxFilePath + maxFileName)

noxreffilename = "File_No_Xref.max" as string
--noxref = (maxFilePath + noxreffilename)
saveMaxFile (maxFilePath + noxreffilename)
for i in enabledXRefIndex do (xrefs.getXRefFile i).disabled = false
saveMaxFile filename

) else checkForSave()
)

miauu's picture
crystal3d's picture

definitely will look into them

the first book seems really my cup of tea, and the book in the first link you gave looks really a complete release, just that it does not have real pages to flip maybe that s why said that u dont have it.

btw, about this code you gave,i found out that it gets cumbersome on heavy scenes, and i have to ask another thing.

instead of re-enabling all xref scenes
it just has to re-enable that is disabled by the script only:

so if there were 5 scenes loaded to that scene and 7 more that was disabled already
then
it should disable the 5 active ones
and re-enable those 5 disabled ones at the end.

think it is doable?

best regards

miauu's picture

( do some actions= ( if

(
	do some actions=
	(
		if maxFileName != "" then 
		( -- if the scene saved
			max saveplus -- incremental file save
			TheFile = maxFilePath + (trimRight (getFilenameFile maxFileName) "1234567890") + ".max" --remove trailing numbers
			if doesFileExist TheFile do deleteFile TheFile
			--	disable only the active xref
			local enabledXRefIndex = #()
			for i = 1 to xrefs.getXRefFileCount() where ((xrefs.getXRefFile i).disabled == false) do
			(
				(xrefs.getXRefFile i).disabled = true	--	disable the xref
				append enabledXRefIndex i	--	store the index of the active xref scenes
			)
			--
			copyFile (maxFilePath + maxFileName) TheFile
			--	re-enable the disabled xref scenes
			for i in enabledXRefIndex do (xrefs.getXRefFile i).disabled = false
		) else checkForSave()
	)
)
crystal3d's picture

thats it! it s fabulous!

i am so happy now...:)thanks alot again.

miauu's picture
crystal3d's picture
crystal3d's picture

okay one little problem ...

the sequence which the xref scens are enabled are wrong... it saves a file then disables the sref scenes.

"

(
        if maxFileName != "" then
        ( -- if the scene saved
            max saveplus -- incremental file save
            TheFile = maxFilePath + (trimRight (getFilenameFile maxFileName) "1234567890") + ".max" --remove trailing numbers
            if doesFileExist TheFile do deleteFile TheFile
            --    disable only the active xref
            local enabledXRefIndex = #()
            for i = 1 to xrefs.getXRefFileCount() where ((xrefs.getXRefFile i).disabled == false) do
            (
                (xrefs.getXRefFile i).disabled = true    --    disable the xref
                append enabledXRefIndex i    --    store the index of the active xref scenes
            )
            --
            copyFile (maxFilePath + maxFileName) TheFile
            --    re-enable the disabled xref scenes
            for i in enabledXRefIndex do (xrefs.getXRefFile i).disabled = false
        ) else checkForSave()
    )
"

the saved files should not have any enabled xref scenes...that causes alot of problems...

it is very close but it s not there yet :)

 

crystal3d's picture

i think i got it :p

(
if maxFileName != "" then
( -- if the scene saved
local enabledXRefIndex = #()
for i = 1 to xrefs.getXRefFileCount() where ((xrefs.getXRefFile i).disabled == false) do
(
(xrefs.getXRefFile i).disabled = true -- disable the xref
append enabledXRefIndex i -- store the index of the active xref scenes
)
max saveplus -- incremental file save
TheFile = maxFilePath + (trimRight (getFilenameFile maxFileName) "1234567890") + ".max" --remove trailing numbers
if doesFileExist TheFile do deleteFile TheFile
-- disable only the active xref
--
copyFile (maxFilePath + maxFileName) TheFile
-- re-enable the disabled xref scenes
for i in enabledXRefIndex do (xrefs.getXRefFile i).disabled = false
) else checkForSave()
)
i tired to change the order of commands and it looks like solved

miauu's picture

Yep, my mistake. As you can

Yep, my mistake.
As you can see, maxscript it is not so difficult. :)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.