Notifications
Clear all

[Closed] CustomAttribute Array?

–Let’s say we make a custAttribute definition:

def = attributes testDef
(
parameters params
(
test type:#float –How do I create an Array value here ? if Possible
)
)

theBox = box() –Then, we create a box.
custAttributes.add theBox def –Then add the CA to the box

This is doin’ my head in, maybe I’m coming at it from the wrong angle but the the help file says it’s possible to have an Array consisting of Point3 values, or any viable types:

Do I need to look at ParameterBlock ?

Ideally I would like a Ca which holds Point3 values in an Array and be accessed like thebox.test[1]

Thanks in advance for helping a noon scripter.

8 Replies

 def = attributes testDef (
   parameters params (
 	test type:#floatTab tabSizeVariable:true
 	p3test type:#point3Tab tabSizeVariable:true
   )
  )
 

Keep in mind that when you access ‘tab’ type parameters, that their class is ArrayParameter, not Array. The difference is subtle, but look up the topic on ArrayParameters anyway

For more information on tab parameters and other parameters you can use in a Custom Attributes block, see the “Scripted Plug-in Clauses” topic. CA’s are pretty much just scripted plug-ins with the plug-in definition itself saved with the scene.[color=white][font=Verdana][size=2][/color][/size][/font][color=white][/color]

Many thanks fella – got it !The help for Ca’s

…etc
[left] Matrix3
[/left]
[left] Point2
[/left]
[left] Color
[/left]
[left] Arrays containing any of the above value types
[/left]

but gave no indication of terminology to use and I still don’t know my way around enough this part of Max to know what to look for…anyway in short very grateful.!

OK, just to take this a step further can a :#point3Tab hold Multi Dimensional arrays or how do you create them?

a=#(#([4,4,4],[5,5,5]),#([2,2,2]))
def = attributes testDef (
parameters params ( p3test type:#point3Tab tabSizeVariable:true)
)
custAttributes.add myp def
myp.p3test=a – will fail as the Ca isas a Point3 value whereas
myp.p3test=a[1] – will work as a[1] is an array #([4,4,4], [5,5,5])

thanks again for looking at this.

I don’t think it can hold a multi-dimensional array, although I hope someone can correct me on this. A work around I started using was to convert the multi array as a string, then store it in a #string parameter. Afterwards you can always execute the string and continue on.

It can hold just about anything if you save it as a string.

I wish I could correct you on that – but at least in Max 2008, there’s still no ‘array’ type parameter (the *Tab parameters are arrays of a specific type, of course) that itself would accept arrays.

There’s many ways to get around it – converting to string and back is one. I’ve only ever had the need for a multidimensional array once and got around it by creating a dummy plugin that holds array parameters that I can access. Instances of that plugin then get stuck into other instances of that plugin, or into the custom attribute, with the parameter set to maxObjectTab.

This is just base example code (hence the iffy classid’s – best not to use ‘as is’):


test_ca = attributes test_ca version:1 attribid:#(0xdeadbeef,0xbaadf00d) (
	parameters params (
		varTab type:#maxObjectTab tabSizeVariable:true
	)
)
<AttributeDef:test_ca>

plugin simpleMod array_plugin name:"Array Plugin - For scripting purposes only" classID:#(0xbaadf00d,0xdeadbeef) invisible:true (
	parameters params (
		floatArray type:#floatTab tabsizeVariable:true
		colorArray type:#colorTab tabsizeVariable:true
		-- add other classes if/where appropriate
		maxObjectArray type:#maxObjectTab tabsizeVariable:true
	)
)
array_plugin

custAttributes.add $ test_ca
true

$.test_ca.varTab[1] = array_plugin()
array_plugin:Array Plugin - For scripting purposes only

$.test_ca.varTab[1].floatArray
#()

for i = 1 to 10 do ( append $.test_ca.varTab[1].floatArray i )
OK

$.test_ca.varTab[1].floatArray
#(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0)

$.test_ca.varTab[1].floatArray[1]
1.0

Caveats abound…
You can’t access it as you would any standard multi-dimensional array… i.e. test_ca.varTab[x][y] does not work, it has to be test_ca.varTab[x].parametername[y] .
As it uses a scripted plugin, you need to have this plugin ‘installed’ so that the scene can use it again. The reason it’s a scripted plugin is so that it can exist in the scene without needing to be attached to some other object, and has no problems with existing more than once (multiple copies of the same CA on the same object gets iffy).

An upside is that everything referring to nodes, texture maps, etc. remains as such without having to update the strings you’d store whenever an object’s name changes, gets deleted, etc.

All the same, it would have been nice to at least have some sort of multidimensional facility in parameters. I know that in some other languages where this type of restriction exists, the multidimensionality is achieved by keeping a single array, and then keeping a set of integer parameter that defines the number of elements in the each lower dimension.

For example, if you originally have:


twoDimArray = #(
#(1,2,3),
#(7,8,9)
)

You would then get…


singleDimArray = #(1,2,3,7,8,9)
singleDimSize = 2

With that information, you can re-build the multidimensional array in-memory, or simply access the correct value directly:


twoDimArray[2][3]
9

singleDimArray[2 * singleDimSize + (3 - 1)]
9

Also don’t forget there are User Defined Properties.

Edit: Nevermind… go ahead and forget User Properties. They don’t have arrays at all

Ok dokey, thanks guys. Jason, I did think of using a #string value and converting. Eventually the arrays would be saved out as a file anyway so that’s not such a bad way to go.
The reason for holding everything in one multiarray was for convenience really , (storing positions of several objects that are linked in a chain in one array, and having lots of chains…)
but I could create an array per chain…it’s just that you end up with a lot more ca’s on the object.

Anyway both your ‘skills’ (Napoleon dynamite voice) are way above mine and I shall plod along
cheers