storing a struct inside CA Params


Im working on a system and I need to store some data on a object. A simple CA could work but it doesnt really give me the flexibility that I need. Idealy I wouldve stored struct instances but AFAIK you cant do that in max.

So I was wondering which solution should I go for
-use a second CA stored on another node and store that node in my first CA
-use an xml string

Each method has their pros and cons but I cant really decide which one to take… Is there a better solution?


what types of data do you want to store?


I need to store matrix and different index and they all need to stay grouped in a specific order.
something like a list of index then each index got a sublist of subindex and each subindex are associated to a matrix.


Well, AFAIK you can store struct instances as persistent globals provided that they are defined at the time the scene is being opened (for example by running a script that contains the struct definition beforehands). Out of curiosity, can you show us what an example struct would look like? I have hard time imagining it given the description.


At first I wanted To have something like
#(struct instance 1, struct instance 2, etc…)

and each struct would be uswd to store data like:
Id: #(1,2,3) – int array
matrix: #( an array of matrix)

Thing is I need to keep my Id array grouped with the matrix array ( there will be 1 matrix per id element).

I hope its clear, sorry if its still unclear I tried my best explaining it using my cellphone :slight_smile:


In that case, there’s no reason to make a complicated setup. I’d use two intTabs and one matrix3Tab - the first intTab would hold the number of items for each of the index/matrix3 array pairs, the second intTab would contain all the indices and the matrix3Tab all the matrices.

So for

#(1,2,3) #(matrix1, matrix2, matrix3)
#(4) #(matrix4)
#(5,6) #(matrix5, matrix6)

the stored values would be

#(matrix1, matrix2, matrix3, matrix4, matrix5, matrix6)


I agree with what Vojtech says: use a simple solution where it works good enough.

but for more complicated cases you can store CAs which mimic you structure. in your case i could be:

StructCA = attributes StructCA attribID:#(0x1010101, 0x2020202)
	parameters params 
		ids type:#inttab tabsizevariable:on animatable:off
		tms type:#matrix3tab tabsizevariable:on
StructHolderCA = attributes StructHolderCA attribID:#(0x1010101, 0x2020203)
	parameters params 
		cas type:#maxobjecttab tabsizevariable:on subanim:off

delete objects
b = box()

holder = createinstance StructHolderCA
for k=1 to 10 do
	ca = createinstance StructCA
	num = random 1 5
	for i=1 to num do
		append ca.ids (id = random 0 1e6)
		append ca.tms (transmatrix [id,0,0])
	append holder.cas ca 

append b.baseobject.custattributes holder
for k=1 to b.cas.count do 
	ca = b.cas[k]
	format "%: %
" k ca
	format "	ids:%
" ca.ids
	format "	tms:%
" ca.tms