Error Checking vs existing xref

Sorry for having to ask for help on such a simple script, but I'm really at my wits end.. 3 hours later, and I can't get this to work.. I'm trying to check to make sure that I'm not adding an xref to a scene that might already exist in the scene.. but I get nothing but errors that I can not figure out.. if you look in the Fn LoadXref you'll see my attempts at checking my new files vs existing xrefs.. but I can't seem to make it work.. the commented out code is what I want to happen once I verify that the file is not a duplicate, and it and the rest of the script work fine.. Any suggestions I'd greatly appreciate.


load_xrefs.ms4.65 KB


Comment viewing options

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

glad to help

Declare the variables as locals is just good scripting practice that will helps you in more complex scripts.

The LoadXref function you can define where you want, but the Resize function call your rollout and its elements, so - you can do 2 things: 1) if you like to put this function out of the rollout, then be sure its defined after the rollout, and 2) if you like to define this function out and before the rollout def, then supply access to the rollout via variable argument, i.e. something like:

fn Resize roll Y =
	OHXbx1 = roll.XBx1.Height
	NewXBX1Ht = (TFC *= 13.5)
	if NewXBX1Ht <= 600 and  NewXBX1Ht >= OHXBX1 then
	roll.XBx1.height = NewXBX1Ht else roll.XBx1.height = OHXbx1
	NHXbx1 = roll.XBx1.Height
	OHRO = roll.Height
	DHXBx1 = (NHXbx1 -= OHXbx1)
	roll.Height = (OHRO += DHXBx1)
	OP1posY = roll.pb1.pos 
	Show OP1posy
	roll.pb1.pos = (OP1posy += [0,DHXBX1])
	OPGoBtn = roll.GoBtn.pos
	roll.GoBtn.pos = (OPGoBtn += [0,DHXBX1])


my recent MAXScripts RSS (archive here)

Anubis's picture

try this

fn LoadXref file = 
	local MatchFound = #()
	XRcnt = xrefs.getXRefFileCount()
	if XRcnt > 0 do (
		MatchFound = for i=1 to Xrcnt where \
		((xrefs.getXRefFile i).fileName == file) collect i
	if XRcnt == 0 or MatchFound.count == 0 do (
		NewXRef = xrefs.addNewXRefFile file #noload
		NewXRef.boxdisp = true
		--NewXRef.disabled = true --?... that block updating
		updateXRef NewXRef

my recent MAXScripts RSS (archive here)

xXDambielXx's picture


Hey thanks a lot, that worked great. As to the line you commented out, it causes the loaded xref to be disabled initially when loaded.

Out of curiosity, do you know why the two functions I define in the script can't be declared outside the rollout? I started the script with a ( so anything beyond that should be local to the script, but every time I try to move them out of the rollout itself suddenly they stop working.

Also you explicitly defined MatchFound as local.. Is there a need to do that, or is that just good scripting practice?

Thanks again for your assistance.


Comment viewing options

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