ScriptSpot

Forum topic · General Scripting

How to save nested arrays variables with the scene?

By 6ill9re9 · 2016-05-12

Description

Hi,

I wrote a script for handling multiple scene setups for rendering by storing multiple properties and their associated "objects" in variables that I store in a rollout of a custom attribute. It saves with the scene and it works pretty well as long as I don't close the Max session.
If I close and reopen Max I think what happens is that the rollout gets opened and so reset its local variables. Damn...
I don't want to use params because that means I have to split somehow every properties by type and I was avoiding that thanks to the fact that arrays can contain any type of data.

Basically I was storing in one array the array of property names first and property values second like that

objProps = #()
for obj in Objects do
(
names = #()
values = #()
for i in getPropNames obj do
(
append names i
append values (getproperty obj i)
)
append objProps #(obj, names, values)
)

(sorry I don't know how to add TABulations)

is there any way???

Comments (10)

6ill9re9 · 2016-05-23

Thanks!

I know about these renderPass scripts and they are great but a lot too generic and complex to use for my staff...
I am trying to do something quickly customisable for each project, thats why I am looking for doing my own functions to store values and controllers...

I am actually close to success, i did a function to turn the classOf a property value into a type:#name of parameters... I wonder why it doesn't exist natively... like a typeOf()

I am again bumping into a wall with that last issue, if a value is undefined, that means has not been set by the user it is impossible to know the type...
for example I usually have nothing in #adv_irradmap_saveFileName so if I getProperty of that it outputs undefined but if I try to setProperty to undefined I get an error.
I would like to set to something empty, like ""for this property but I can't test if it is a string without trying every type of value...

I can do a specific workaround for Vray and for now but I would like to make it more generic to be able to tweak future version of this pass manager and keep it as simple as I can on the user side...

Any clue on how to guess the type of an undefined value in a defined param ?

`

pixamoon · 2016-05-23

hey, just sent you an email, but quickly you are on very good track.

write/read your parameters

TsveTan · 2016-05-15

Write the initial settings for a given control to a file and when you open the rollout read these settings (setINIsettings..., getINIsettings) or use custom attributes as miauu suggested.

.

miauu · 2016-05-13

Use Node User-Defined Properties and Methods, or Use Custom Attributes.

To add tabulations put the code between "

" "code here" "

"
without the quotes.

6ill9re9 · 2016-05-15

I probably don't understand properly but my understanding of user props is that it is limited to string.
I am currently finding a work around with strings in a custom attribute as parameters since it seems to be the only way to have it saved with the scene and not reset with new max session. I am r ally looking forward to understanding better but such short answer is hard for me who has no coding background and is struggling with the lingo of the help files.

`

pixamoon · 2016-05-16

You can use Custom Attributes as Miauu suggested.

But to store mixed array as u want is not that easy.

Start form example:
http://forums.cgsociety.org/archive/index.php?t-369543.html

What you need to do is create Dummy, put it on some safe layer zzz_Scene_Paramiters and hide. (just named it as you want to)

than run this:


a = attributes yourData
(
	parameters yourParam
	(
		yourArray1 type:#intTab tabSizeVariable:true  
		-- only Integer values can be stored in that array

		yourArray2 type:#stringTab tabSizeVariable:true  
		-- only Integer values can be stored in that array

		yourArray3 type:#nodeTab tabSizeVariable:true
		-- only nodes can be stored in that array or use #maxObjectTab
		-- etc
	)
)

custAttributes.add $Dummy001 a

than you can access it by:


$Dummy001.yourArray1
--or
$Dummy001.yourData.yourArray1

more info:
http://docs.autodesk.com/3DSMAX/15/ENU/MAXScript-Help/index.html?url=fil…

Hope it helps,
Best,
Pixamoon

6ill9re9 · 2016-05-18

that is what I am trying to do right now but it is a hell of complexity... always bumping into walls of special case...
for example storing/restoring VRay setting with array is as simple as:

Vrender = renderers.current
propNames = #()
propValues = #()

--Get Vray Properties
for i in getPropNames Vrender do
(
val = getProperty Vrender i
if val != undefined then
(
append propNames i
append propValues val
)
)
--Set Vray properties
for i = 1 to propNames.count do
(
setProperty Vrender propNames[i] propValues[i]
)

I am about to give up setting CA since converting string is limited to certain classes only. Converting some superclass like "filter" doesn't even seem to be possible

I am not yet giving up but...

6ill9re9 · 2016-05-18

How do you insert maxscipt code in your post?

`

pixamoon · 2016-05-18

Hi,

to post script here do that:

<_code_>
...
...
<_/code_>

just without underscore _ in <_code_> and <_/code_>

`

pixamoon · 2016-05-18

to save render setting in scene, take a look on:

http://www.scriptspot.com/3ds-max/scripts/l-pass-manager
or
http://www.scriptspot.com/3ds-max/scripts/prism

or one more thing...

converting string back to different type of variables: (boolean, color, Point2, Point3... etc) you can use just:

a = execute ("color 10 10 10")

or even to Array with different types inside:

arr = execute ("#(12, true, [10,10,10], color 10 10 10)")

this way u can even store it as string in dummy with Node User-Defined Properties



-- to save it:
setUserProp $Dummy001 "prop1" ( (color 10 10 10) as string )

-- and to get it back:
a = execute (getUserProp $Dummy001 "prop1")

One thing you can't story this way is node or arrays of nodes
(include / exclude)
for that you can store node handles (obj.handle) or store them in #nodeTab array