PDA

View Full Version : Adding a parameter to a defined Custom Attribute?


TimHawker
12-06-2010, 08:46 AM
Hi guys,

I've been trying to get my head around using Custom Attributes as persistent data storage. So far I have been able to create a CA, add parameters, save the CA to the globaltracks and then read/write to the parameters:


persistentData = attributes "persistentData"
(
parameters main rollout:blank
(
Array1 type:#StringTab tabSizeVariable:true animatable:false
Array2 type:#StringTab tabSizeVariable:true animatable:false
)
rollout blank "blank"
(
)
)
custAttributes.add globaltracks persistentData


globaltracks.persistentData .Array1 =#("1111", "1111")
globaltracks.persistentData .Array2 = #("2222", "2222")


My question is:
Is it possible to add/delete parameters within the CA after it has been defined?

For example, I want to delete Array1 and make Array3, resulting in the CA parameters containing Array2 and Array3. Can this be done?

Thanks for any help provided! Much appreciated. :)

marktsang
12-06-2010, 10:45 AM
Hey Tim
you cannot add attributes to a ca after creation but you can redefine the definition
also you don't have to declare a rollout if you don't use it

mark

PEN
12-06-2010, 12:21 PM
Can you not just change what is stored in array1? instead of removing the variable?

TimHawker
12-06-2010, 02:15 PM
Hey Tim
you cannot add attributes to a ca after creation but you can redefine the definition
also you don't have to declare a rollout if you don't use it

mark

Thanks for the info marktsang. :thumbsup:

Can you not just change what is stored in array1? instead of removing the variable?

Yeah that would be a good thing to do, but I wanted to be able to add more arrays as well as being able to delete any of them further down the line. Not really a problem, there are lots of alternative solutions. Just would have been very handy to do it this way.

Edit: Just realised who replied! Thanks for such fantastic tutorials on your site Paul. They have helped no end with regard to rigging. I also purchased your CGAcademy Rigging tutorials during 3rd year of uni - a fantastic buy :thumbsup:

denisT
12-06-2010, 03:43 PM
Hi guys,

I've been trying to get my head around using Custom Attributes as persistent data storage. So far I have been able to create a CA, add parameters, save the CA to the globaltracks and then read/write to the parameters:


persistentData = attributes "persistentData"
(
parameters main rollout:blank
(
Array1 type:#StringTab tabSizeVariable:true animatable:false
Array2 type:#StringTab tabSizeVariable:true animatable:false
)
rollout blank "blank"
(
)
)
custAttributes.add globaltracks persistentData


globaltracks.persistentData .Array1 =#("1111", "1111")
globaltracks.persistentData .Array2 = #("2222", "2222")




because you don't need to have the data set undoable, and you are using string arrays; you can use MAXWrapper AppData methods to store some custom data with globaltracks node:

setappdata globaltracks 100 "one|two|three"
getappdata globaltracks 100

you can use any separator and easy parse the string with filterString() function.

TimHawker
12-06-2010, 04:23 PM
Fantastic, you've just condensed my script substantially!

Cheers denisT :thumbsup:

One quick question: Is it recommended to save persistent data to rootnode or globaltracks? Or is it personal preference?

Tim

denisT
12-06-2010, 04:34 PM
Fantastic, you've just condensed my script substantially!

Cheers denisT :thumbsup:

One quick question: Is it recommended to save persistent data to rootnode or globaltracks? Or is it personal preference?

Tim

it's definitely up to you where to store a data. I prefer the rootnode. At least because in case of XREF scene you can read stored data from xref $<root>.
like:

getappdata (xrefs.getXRefFile 1).tree 100

TimHawker
12-08-2010, 08:51 AM
Thanks again denisT. Really helpful stuff!

I've been experimenting a bit with all three methods of persistent data storage (persistent globals, CA, setUserData) but have yet to get CA properly working when re-running the script.

If I were to add a custom attribute to the rootnode when a script is run, how would I be able to check that the custom attribute has not been already added when re-running the script? I've tried the following below but it's not working properly. Any help again much appreciated!



--Apply CA

sceneDefs = custAttributes.getSceneDefs()
for i = 1 to sceneDefs.count do
(
if matchPattern (sceneDefs[i] as string) pattern:"*persistentData*" == true then defineCA = false
)
if defineCA != false then
(
persistentData = attributes "persistentData"
(
parameters main
(
Array1 type:#StringTab tabSizeVariable:true animatable:false
)
)
custAttributes.add rootnode persistentData
rootnode.persistentData .Array1 =#("1111", "1111")
)


Also, is it possible to save nested arrays to a Custom Attribute?

TimHawker
12-08-2010, 09:43 AM
Update: I've managed to get the above code working by rewriting the if statement:


if not (isProperty globaltracks #persistentData) then
(
persistentData = attributes "persistentData"
(
parameters main
(
Array1 type:#StringTab tabSizeVariable:true animatable:false
)
)
custAttributes.add globaltracks persistentData
globaltracks.persistentData .Array1 =#("1111", "1111")
)


However I have still yet to work out if nested arrays are possible with Custom Attributes. Is it possible?

PEN
12-08-2010, 11:28 AM
Your well come.

As for nested arrays it is not possible as you need to declare a data type. That being said we found a work around at one point but I'm not sure that I applies. I will give I a go and see if it did what you need as I can't quite remember what it is we were up to on that project.

JHN
12-20-2010, 09:30 PM
if you need to store an array of arrays, I just convert my array to a string

#(#("data1"), #(data2)) as string and store that in a stringTab, you can nest however deep you want. Offcourse this only applies to data that can meaningfully be transformed to strings like transform data and other strings. If you need to convert the string back to it's original value just execute the string value. That's how I store poses in my pose tool, each tab in the stringTab holds all transform values of all nodes that are referenced via a maxObject tab. So each entry in a tab is a pose for all nodes. Hope it makes sense.

-Johan

CGTalk Moderation
12-20-2010, 09:30 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.