ScriptSpot

Forum topic · Scripts Wanted

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

By crystal3d · 2012-03-09

Description

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 (16)

No disable xref, but REMOVE

tomastnt · 2014-03-04

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()
)

definitely will look into them

crystal3d · 2012-03-09

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

( do some actions= ( if

miauu · 2012-03-09


(
	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()
	)
)

thats it! it s fabulous!

crystal3d · 2012-03-10

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

miauu · 2012-03-10

Don't forget Anubis.

and absolutely

crystal3d · 2012-03-10

anubis:)

okay one little problem ...

crystal3d · 2012-03-10

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 :)

 

i think i got it :p

crystal3d · 2012-03-10

(
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 · 2012-03-10

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

yes i was surprised this time...

crystal3d · 2012-03-10

but now i believe it s done and very helpful already :)

miauu · 2012-03-10

Glad you like it. :)

do some actions= ( if

miauu · 2012-03-09


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 xref
		for i = 1 to xrefs.getXRefFileCount() do (xrefs.getXRefFile i).disabled = true
		--
		copyFile (maxFilePath + maxFileName) TheFile
		--	enable xref
		for i = 1 to xrefs.getXRefFileCount() do (xrefs.getXRefFile i).disabled = false
	) else checkForSave()
)

testing right now.....

crystal3d · 2012-03-09

thanks already :)

okay great!

crystal3d · 2012-03-09

you made it seem like a piece of cake! but reality is different yes? i am still amazed at how simple, thing can be solved by scripting...

I have one more question, was there a way that i could possibly find the solution in some book or cd? like some book?

thanks again miauu, you are priceless too :)