[Closed] Copying object with custom attributes brakes CA functionality
I am making a basic custom attribute and assigning it to an object, everything seems to work fine until i make multiple copies of the object.
- Create object
- Add the custom attribute (custAttributes.add $ MCCA #unique)
- Shift+Move to create several copies
- First and second copied objects, the ca works, all others don’t
Below is the test code for the custom attribute
global MCCA
MCCA = attributes MCCAData attribID:#(0x370df988, 0x6f6f0b01)
(
local buttonWidth = 135fn Check_fn =
(
MessageBox “Test”
)parameters test_params rollout:test_ro
(
get_btn type:#boolean animatable:false ui:get_btn default:false
first_sp type:#integer animatable:false ui:first_sp default:0
last_sp type:#integer animatable:false ui:last_sp default:0on get_btn set val do ( if val == true then ( Check_fn() get_btn = false ) )
)
rollout test_ro “test”
(
spinner first_sp “First: ” type:#integer range:[-1000000,1000000,0] pos:[38,7] fieldWidth:60 width:(buttonWidth – 24)
spinner last_sp “Last : ” type:#integer range:[-1000000,1000000,0] pos:[38,28] fieldWidth:60 width:(buttonWidth – 24)
checkbutton get_btn “Get” width:buttonWidth pos:[14,49]
)
)
Looks like the custom attribute brakes for the copied objects.
When i press the button on the original and the first copy i get
object.get_btn = on
but when i do the same on the other copies i get
undefined.get_btn = on
adding the custom attribute without the unique flag fixes that issue but I don’t want to add the custom attribute it as not unique.
What is the reason for wanting to use the unique flag?
Custom attributes are local unless you give them an attribID in their definition:
https://help.autodesk.com/view/3DSMAX/2018/ENU/?guid=__files_GUID_9F96FB7D_EB51_41FA_976D_C39DEED69CE4_htm
The docs point out that if you provide an attribID and add it with the unique flag, it will make the attribute local.
The unique argument means that the attribute definition is different under the hood for each object it is applied to, which is different to the default behaviour of a local attribute vs a global attribute.
Basically, try either removing the unique flag or removing the attribID as having both is contradictory.
You are right, it should really be one or the other, attribID or unique flag.
This was just a work in progress script i was testing if I should use unique or not. In the end I will go with attribID, otherwise there is a bigger workaround with callback scripts on clone and I don’t want to get into that.
But regardless of my script this is an odd issue, probably something is missing in the shift+drag copy function in max where it doesn’t relink the attribute to the copied objects.