These properties give you access to scene object user properties. The MAX SDK provides a way to get at the user defined properties in the Object Properties dialog in two ways -- either as one single string representing the entire contents or as a set of key/property pairs in the form:
<key1> = <property1>
<key2> = <property2>
...
where the keys are identifiers (with the same syntax as names in MAXScript) and the properties can be numbers, booleans (true/false) or text strings. If you set up the property box in the above form, there are two new MAXScript methods for setting and getting individual keyed properties. There are two other methods that let you treat the property text as a single big string, which can also be used to save and load property sets in the key/property form.
Caution: There is currently a bug in the get/set property functions in the MAX SDK for text string properties that truncates retrieved string properties at the first space character in the string value.
The <node> methods are:
getUserProp <node> <key_string>
retrieves the node's user property with the given key
setUserProp <node> <key_string> <value>
sets the node's user property with the given key to the given value (values must be either numbers, booleans or strings)
getUserPropBuffer <node>
retrieves the entire user property buffer as a string containing all the user property settings. This is effectively the contents of the User Defined Properties box in the MAX Object Properties dialog
setUserPropBuffer <node> <buffer_string>
sets the user property buffer to the given string
The following two example code fragments save and load user properties for objects in a scene:
The first one creates a file and loops through all objects outputting for each the object name and user property buffer string. Note that the object name goes out in a form that will come back in (via a readValue()) as a direct reference to a scene object. Also, the user property string is output using print() so it will be in a quoted form to be read as one (long) string literal by a corresponding readValue().
The second code fragment reads in the file created by the first piece and applies the user properties to any same-named object in the current scene. Note that readValue() can read in pathnames ($<name>) and will yield either the named scene object or undefined if the named object is not in the scene. The readValue() function can also read in a multi-line string literal in one pass.
-- create file and for all objects,
-- dump object name and user props
f = createFile "foo.dat"
for o in objects do
(
format "$%\n" o.name to:f -- ouput name in a pathname form
print (getUserPropBuffer o) to:f -- out buf as a string literal
)
close f
-- open file and read in object names and
-- user properties to set
f = openFile "foo.dat"
while not eof f do
(
o = readValue f -- read object
if o != undefined then -- if present, read and set user prop string
setUserPropBuffer o (readValue f)
)
close f