Notifications
Clear all

[Closed] Persistent Global Variables

Hello,

I would like a bit of advice about saving variables with a scene please.

I have a tool which would be more useful if the rollout remembered the last entered values between Max sessions. I know an easy way would be to declare the variables as persistent global but the Max Help advises against this. Instead it suggests using scripted custom attributes – see here.

So that is what I’ve done and it works ok but I now get an error message from the render farm about a missing dll if I send scenes I’ve used the tool in. I know how to fix the error but I want to know if there are other ways of storing variables with the scene that don’t require a copy of the script to be installed on every computer that the scene is going to be opened?

Thanks.

10 Replies
 PEN

If you are using a cadef to just store data then there shouldn’t be an issue with the farm. Are you some how leaving a callback persistent as well?

You might want to post some code that shows what you are trying to do as I use methods like this all the time.

Thanks for the reply Paul. I’m not sure what you mean by leaving a callback persistent.

Anyway here’s the code:


-- Wallcovering Script

try (destroyDialog rootnode.WallCoverCA.Wallpaper)
catch ()

fn RBand MPoint =
	(
		TKnots = numKnots $ 1
		if TKnots == 1
			then addKnot $ 1 #corner #line (MPoint * [1,1,0])
			else (
					deleteKnot $ 1 TKnots
					addKnot $ 1 #corner #line (MPoint * [1,1,0])
					)
		updateshape $
	)

fn CreatePaper SkirtH CeilingH PThickJ UseShID ShapeID =
(
	snapMode.active = true
	local NextPt = pickpoint snap:#3D
	if iskindof NextPt point3 do
		(
			local WCSpline = splineShape prefix:"Wallcovering" pivot:NextPt
			addNewSpline WCSpline
			addKnot WCSpline 1 #corner #line (NextPt * [1,1,0])
			select WCSpline
			freeze WCSpline --Prevents snapping to self
			while iskindof NextPt point3 do
				(
					NextPt = pickpoint snap:#3D mouseMoveCallback:RBand
					if iskindof NextPt point3 then 
						(
							addKnot $ 1 #corner #line (NextPt * [1,1,0])
						)
					else
						(
							if (numKnots WCSpline 1) > 1 do updateshape WCSpline
						)
				)
			unfreeze WCSpline
				
			if (numKnots WCSpline 1) > 2
				then
					(
						deleteKnot WCSpline 1 (numKnots WCSpline 1)
						if (numKnots WCSpline 1) > 2 do
							(
								if queryBox "Close spline?" title:"Close" beep:false do
									(
										Close WCSpline 1
									)
							)
							
						applyOffset WCSpline PThickJ
							
						for spl = 1 to (numsplines WCSpline) do
							(
								for seg = 1 to (numSegments WCSpline spl) do
									(
										setmaterialID WCSpline spl seg ShapeID
										setKnotType WCSpline spl seg #corner
									)
							)
						updateshape WCSpline
						move WCSpline [0,0,SkirtH]
						addModifier WCSpline (extrude amount:(CeilingH - SkirtH) useShapeIDs:UseShID mapCoords:true)
						WCSpline.material = WallMat
						select WCSpline
					)
				else
					(
						delete WCSpline
					)
		)
) --End CreatePaper

fn SetWallMaterial =
(
	if (scenematerials ["Wallcovering MSO"] == undefined) and (meditmaterials ["Wallcovering MSO"] == undefined)
	then
		(
			WallMat = multimaterial numsubs:5 name:"Wallcovering MSO"
			for m = 1 to 5 do WallMat[m] = VrayMtl name:("Wall Finish0" + m as string) diffuse: (random (color 100 100 100) (color 200 200 200))
		)
	else
		(
			if scenematerials ["Wallcovering MSO"] == undefined
				then WallMat = meditmaterials ["Wallcovering MSO"]
				else WallMat = scenematerials ["Wallcovering MSO"]
		)
	WallMat
)

WallCoverCADef = attributes WallCoverCA version:1 attribID:#(0x253f541e, 0x6384e660)
(
	parameters main rollout:Wallpaper
	(
		SkirtH type:#float  default:100
		CeilingH type:#float default:2750
	)
	
	rollout WallPaper "Wallpaper 0.2" width:160 height:220
	(
		Local PThick = 2
		Local UseShID = true
		Local ShapeID = 1
		Local JustDir = 1
		Local PThickJ = PThick * JustDir
		local WallMat = SetWallMaterial ()
		
		groupBox Dimensions "Dimensions" pos:[5,3] width:150 height:105
		spinner SpinS "Skirt Height:" pos:[35,20]  width:107 height:16 range:[0,10000,SkirtH] type:#float align:#Right
		spinner SpinC "Ceiling Height:" pos:[30,40]  width:112 height:16 range:[0,10000,CeilingH] type:#float align:#Right
		spinner SpinT "Thickness:" pos:[45,60]  width:97 height:16 range:[0,10000,PThick] type:#float align:#Right
		label JustLab "Justification:" pos:[25,83]
		dropdownlist Just pos:[87,80] width:54 across:2 items:#("Right","Left") align:#Right
		groupBox MatOpt "Options" pos:[5,112] width:150 height:70
		checkbox ChsID "Use shape ID" pos:[15,130] checked:UseShID
		spinner SSID pos:[100,130]  width:50 height:16 range:[0,256,ShapeID] type:#integer align:#Right
		edittext WMat text:(WallMat[ShapeID].name as string) pos:[12,155] readOnly:true
		checkbutton CWP "Create Wallpaper" pos:[10,190] width:140 height:24 highlightcolor:orange
		
		on SpinS changed val do
		(
			SkirtH = SpinS.value
		)
		
		on SpinC changed val do
		(
			CeilingH = SpinC.value
		)
		
		on SpinT changed val do
		(
			PThick = SpinT.value
			PThickJ = PThick * JustDir
		)
		
		on Just Selected Hand do
		(
			case Hand of
			(
				1: 
				(
					JustDir = 1
					PThickJ = PThick
				)
				2:
				(
					JustDir = -1
					PThickJ = PThick * JustDir
				)
			)
			print PThickJ
		)
				
		
		on ChsID changed state do
		(
			UseShID = ChsID.checked
			SSID.enabled = UseShID
			WMat.enabled = UseShID
		)
		
		on SSID changed val do
		(
			ShapeID = SSID.value
			try (WMat.text = (WallMat[ShapeID].name as string))
			catch (WMat.text = "none")
		)
		
		on CWP changed state do
		(
			if CWP.state = true do
				(
					undo "Wallpaper" on
					(
					CWP.highlightcolor = orange
					CreatePaper SkirtH CeilingH PThickJ UseShID ShapeID
					)
				)
			CWP.checked = false
		)
	) --End Rollout
) --End WallCoverCADef 

CustAttributes.add rootnode WallCoverCADef
createdialog rootnode.WallCoverCA.Wallpaper

If you’re not using VRay then line 84 will need editing.

Thanks again and you’ll have to excuse the poor code , I’m a bit of a noob when comes to Maxscript.

 PEN

I don’t have time to test it on my end but I don’t see anything that would be causing the problem. As a test remove the rollout from the def completely. Have the rollout in a function that you run only when needed so that the only thing being stored in the file is the parameter block.

Let me know if that helps.

Thanks, I’ll try that tomorrow and let you know how I get on.

It took me a bit longer than I thought but taking the rollout out of the def worked, render servers no longer ask for the script to be installed.

Thanks again.

 PEN

Now the question is why it is doing this as I can’t see anything that should be getting fired when the scene is being opened or rendered. I’m on my phone at the moment so I will have a closer look when I get into the office.

Question, if you restart max, don’t run the script and just load the max file what happens?

If I use the old script I get two error dialogues on opening the scene. One saying there’s a missing dll,
FileName: Scripted Plugin Class: WallCoverCA SuperClass: 0x1160.

The other is a compile error:
–Compile error: Undeclared variable: SetWallMaterial
–In line: local WallMat = SetWallMaterial (

If I use the new script I don’t get any errors at all.

 PEN

Maybe lines like this are doing it. This is trying to call a function that doesn’t exist. The functions could also be moved inside the rollout.

local WallMat = SetWallMaterial ()

 PEN

This appears to work in 2011 so I’m not sure without doing more tests on it.


fn functionTest=(print "Test")

def=attributes sceneData
-- 	redefine:def
(
	rollout testR "Test"
	(
		local testFn=functionTest()
		
	)
	
	fn openDialog=
	(
		createDialog testR
	)
)
/*
custAttributes.add rootNode def

functionTest=undefined
rootNode.sceneData.openDialog()

*/

Page 1 / 2