[Closed] Custom Attribute Oddness/Crash
I’m currently creating a dynamic custom attribute on a material based on a file’s data.
Right now everything loads/runs/operates as expected. The problem occurs on loading a maxfile.
for clarification of the problem lets call the material with the custom attribute ‘X’
you have a an object with ‘X’ material with a specific set of properties. You then load another scene that also has an object with ‘X’ material, but it has a different set of dynamic properties.
The issue i’m seeing is the original custom attributes are being passed to the now loaded object, overwriting anything that was in the scene before. I’ve tried making the attribute ‘unique’, but then it seems to crash max.
Has anyone seen this before? Or is there something i’m missing?
I might be able to give some test examples if needed.
why have i asked? the 2010 and 2012 have different behaviors for merged CAs.
there is no way to protect current scene CA from overriding by merged CA in 2010.
max 2012 checks the CA version and doesn’t allow to override CA by earlier version.
if the version is not specified or the same the CA will be overridden.
BTW… why is your CA has different set of parameters?
I’m basically trying to emulate the DirectX_shader, where it loads different parameters based on files, and we are loading several files per material.
My initial thought was to use custom attributes as i could dynamically create the UI through Formated Strings.
So the problem arises say when you add one extra file to the material…realize thats not what you want to do…reload your old file…and it results in either a crash, or a data overwrite.
So i could do versions, but then you still will probably overwrite loading another file.
Unless i’m using these wrong, or if there’s a better way to do what i’m trying to achieve.
if you use a ‘dynamic’ CA definition you should generate unique ID. max allows as i know to use the same named CA with different IDs. CA with specified ID doesn’t override any CA with same name but different ID.
i was right. it works:
global test_attrib1 = attributes "Test Data" attribID:#(0x1cabed9b, 0x5555de47)
(
parameters main rollout:params
(
param_data type:#string ui:ui_param_data default:"param"
)
rollout params "Parameters"
(
edittext ui_param_data "Param:" labelOnTop:on width:130
)
)
global test_attrib2 = attributes "Test Data" attribID:#(0x1cabed9b, 0x5555de48)
(
parameters main rollout:params
(
param_data type:#float ui:ui_param_data default:0
)
rollout params "Parameters"
(
spinner ui_param_data "Param:" filedwidth:50
)
)
/*
(
delete objects
b = box name:"b1" isselected:on
CustAttributes.add b test_attrib1
savemaxfile (getdir #temp + @" est.max")
delete objects
b = box name:"b2" isselected:on
CustAttributes.add b test_attrib2
mergemaxfile (getdir #temp + @" est.max") quiet:on
)
*/
Ah. I had thought about that. My initial concept was to just redefine the attribute when the user loads a file into it, to keep any current data. But you’re right, having a unique ID appears to keep them from overwriting themselves. It might make the artists complain about losing data, but better then it getting unintentionally overwritten.
Thank you sir, as always.
i think that it makes sense to overwrite any CA data if the source file definition was changed. if name and value of a parameter of old CA the same as of new one, the data has to stay the same. which is correct. if the type was changed it has to be overwritten with default value.
the idea has to work. you can use filename file hash value to generate the attribute ID.
Looks like i was able to go through the parameters and store them into an array before i deleted the definition, and then reapply any with similiar names afterwards.
I’m doing a while loop on the parameters[ i ], until i hit undefined, unless some knows how to get the numParams. I see it in the sdk, but i dont see in exposed to maxscript, unless i’m missing something.