[Closed] CustomAttribute with new ID from function
HI
I’m having a problem where I wanted call a function that everytime you call it, it returned a custom attribute with a new ID. I thought the following code would have done this. but as you can see if you run it, each of those four times I call it at the bottom, it returns a custom attribute with the same id. How do i get the function to return a new custom attribute with a new id?
I also tried passing the ID to the function, but I get a system exception if i do that.
if anyone has any ideas that would be greatly appreciated.
Thanks
Phil
fn createNewCA =
(
newCa = attributes robotTreePartIDCA attribID:(genClassID returnValue:true)
(
parameters main
(
part type:#string default:"no part"
type type:#string default:"no type"
)
)
return newCa
)
(createNewCA()).attribID
(createNewCA()).attribID
(createNewCA()).attribID
(createNewCA()).attribID
I have a solution, its a bit naf.
The main idea for the ca is to be able to apply it to all the parts of the rig, but if you create another rig then it should create it with a new ID. So my solution is to apply the ca to one part of the rig, use customAttributes.makeunique and then get that def and apply it to the rest of the rig.
So hopefully each rig should have a unique definition.
Still any other ideas would be great!
Thanks for the reply
I understand I shouldn’t need to use the “attribID:” to set a random id as it should be doing this anyway.
I’m probably missing the glaringly obvious but how do i re-evaluate it? I thought by simply by calling the function each time that, that would be re-evaluating it?
I don’t know of another way to re-evaluate it, other than re-evaluating the whole script again. How do I re-evaluate it within the script?
you can evaluate a source of ‘template’ ca… here is a sample:
templateAttrDef = attributes templateAttrDef
(
parameters main
(
)
rollout main "Parameters"
(
)
)
fn makeAttributeDef attrDef name: = if iskindof attrDef AttributeDef do
(
source = custattributes.getdefsource attrDef
if name != unsupplied do source = replace source (findstring source "attributes" + 11) (attrDef.name as string).count name
execute source
)
/*
a = makeAttributeDef templateAttrDef name:#LegAttribute
*/
Thank you, I wouldn’t have thought of that.
I had tried writing the custom attribute as a string and executing it(which worked), but that’s not great if your custom attribute contains a lot of information. This way is still using the execute but at least the code is more readable as you don’t have to write it as a string, and you have control over what you call it.
Still feels a bit hacky, but hey its fine for what I need. Thanks