[Closed] Deleting user property?
I know how to set and I know how to get a user prop from a node.
Does anyone know how clear/delete the property – if I want to clean up a scene after my script.
Assigning an empty value doesn’t remove the property form the user tab
You can get and set the complete UserPropBuffer string and perform operations on it.
Since it is just a large string with a new line for each property, it should be as simple as either using a stringStream and readLine() to collect all lines, check against your properties and skip those you want to delete, then build a new string from the remaining lines (VRay for example uses that buffer for render properties, so clearing everything is usually a bad idea) and assigning the new string to the buffer.
Alternatively, get the buffer, call (filterString theBuffer “
“) to create an array of all properties, loop through the array and collect only the ones you want to keep into a string delimited with “
“, then assign that string back to the buffer.
I had similar case where i needed to check for invalid user props and add and delete some properties. What I did was that I used [font=Verdana]getUserPropBuffer()-method to get whole property buffer into a string and then I just parsed it to my own structs. Then I had whole buffer neatly organized and I could easily check for valid entries and possibly fix them. After everything was checked, I just created new buffer string based my structs and put whole buffer back to node using setUserPropBuffer(). I dont know if parsing buffer string is best way in your case, but in my case it was only reasonable method I could figure out. [/font]
If you’re just setting a short term string var on the object, consider AppData… Especially if you expect to execute on large scenes as it’s way faster…
(
start = timeStamp()
for g in geometry do setappdata g 79901 "My Value"
end = timeStamp()
format "AppData Processing % nodes took % seconds
" geometry.count ((end - start) / 1000.0)
start = timeStamp()
for g in geometry do setUserProp g "My Att" "My Value"
end = timeStamp()
format "SetUserProp Processing % nodes took % seconds
" geometry.count ((end - start) / 1000.0)
)
AppData Processing 2000 nodes took 0.015 seconds
SetUserProp Processing 2000 nodes took 0.047 seconds
Clean up’s is real easy and fast too.
for g in geometry do deleteAppData g 79901
The ‘79901’ is an arbitrary value I’ve selected for the demo code, check the MSX help file for more info on this…
“Access to MAXWrapper AppData [left]
NOTE:
[/left]
[left][i]The AppData is stored in the scene file only if its object is in the sceneif, for example, you create a material in MAXScript and do not assign it to any object or the material editor, it will not be saved in the scene file nor will its AppData.
[/i]Access to MAXWrapper AppData[left]If you want to associate certain AppData strings with the scene as a whole, it is recommended that you create a hidden dummy node with a unique name and attach the scene AppData to that node.”
[/left]
[left]
[/left]
so what if i merge nodes ?
is that why it´s good to use a ‘hidden node’ to store AppData ?
[/left]
[left]
[/left]
AppData might be used with any MAXObject including nodes, modifiers, materials, controllers, etc.
if you merge any MAXObject to the scene it will be merged with its appData
[/left]
One thing to note if you copy an object the copy doesn’t have any copied appdata in it.
-Johan