Notifications
Clear all

[Closed] Custom attribute function issue

Hi,

I try to create a custom attribute in the hands of a character, in order to get a paste opposite function for the arms and legs, etc…
So my process is to create a function that add a custom attribute to acontroller, with max object tabs.
Let say that I have 1 object tab for the hand where the CA is added and other tab for the other hand.
after adding the CA, i put the arrays of left hand objetcs in his max tab, and the right hand in is max tab.
but, when I evaluate it, it appears that the other side objects aren’t in their list… and I dont understand why…
here I put a part of the script as it’s a huge code from my autorig:


-------------------------  My lists of Arrays -----------------------------------------
   L_ikNodesLS=#(),
   L_fkNodesLS=#(),
   L_Roots=#(),
   R_ikNodesLS=#(),
   R_fkNodesLS=#(),
   R_Roots=#(),
   L_Hands=#(),
   R_Hands=#(),
clIKWirst = the control where the CA is added
---------------------------------------------------------------------------------------------   
fn addCAarm theNode =
   (   
      b= theNode
      NewAttr = EmptyModifier()
      NewAttr.name="IK_Blend"
      addmodifier b NewAttr
      IKFK_CA = attributes ik_switch
      (
         parameters  PRM_IKFK_CA  rollout:IKSwitch
               
         (
            swtch_Ik_fk type:#float ui: (sp_IKFK)  default: 1
            stretchP type:#float ui: (stretchSp,stretchSl)  default: 1
            softP type:#float ui: (softSp,softSl)  default: 0
            pinP type:#float ui: (pinSp,pinSl)  default: 0
            fkBtn type:#boolean ui: (ui_FKIK)  default: false
            ikBtn type:#boolean ui: (ui_IKFK)  default: false
            freeOt type:#boolean ui: (freeOrient) default: false
            freeElbo type:#boolean ui: (freeElbow) default: false
         )
         parameters nodesP /*rollout:nodesR*/
         (
            refNodesIK_Side type:#maxObjectTab tabSize:0 tabSizeVariable:true
            refNodesFK_Side type:#maxObjectTab tabSize:0 tabSizeVariable:true
            refNodesRoots_Side type:#maxObjectTab tabSize:0 tabSizeVariable:true
            refNodesIK_OSide type:#maxObjectTab tabSize:0 tabSizeVariable:true ------ Oside is for other side
            refNodesFK_OSide type:#maxObjectTab tabSize:0 tabSizeVariable:true
            refNodesRoots_OSide type:#maxObjectTab tabSize:0 tabSizeVariable:true
            refNodesHand_Side type:#maxObjectTab tabSize:0 tabSizeVariable:true
            refNodesHand_OSide type:#maxObjectTab tabSize:0 tabSizeVariable:true
         )
         rollout IKSwitch "FK <---> IK"
         (
         )
               
         rollout CopyArms "Paste Pose to other side"
         (
            
            button CopyPaste "Paste Arms Pose" width:180 height:30 
            button CopyPasteHands "Paste Hand Pose" width:180 height:30 
            
            local btW=135, btW2=65
            
            group "Tests:"
            (
               button printHandsL "Print L" width:btW
               button printHandsR "Print R" width:btW
            )
            
            on printHandsL pressed do
            (
               for n = 1 to refNodesHand_Side.count do
               (
                  print refNodesHand_Side[n].node
               )
            )
            on printHandsR pressed do
            (
               for n = 1 to refNodesHand_OSide.count do
               (
                  print refNodesHand_OSide[n].node
               )
            )
            
            
            
            on CopyPaste pressed do
            (
               refNodesFK_OSide[1].node.rotation.controller[2][1].value = -refNodesFK_Side[1].node.rotation.controller[2][1].value
               refNodesFK_OSide[1].node.rotation.controller[2][2].value = refNodesFK_Side[1].node.rotation.controller[2][2].value
               refNodesFK_OSide[1].node.rotation.controller[2][3].value = -refNodesFK_Side[1].node.rotation.controller[2][3].value
                  
               refNodesIK_OSide[2].node.pos = [-refNodesIK_Side[2].node.pos.x,refNodesIK_Side[2].node.pos.y,refNodesIK_Side[2].node.pos.z ]
               refNodesIK_OSide[2].node.rotation.controller[2][1].value = refNodesIK_Side[2].node.rotation.controller[2][1].value
               refNodesIK_OSide[2].node.rotation.controller[2][2].value = -refNodesIK_Side[2].node.rotation.controller[2][2].value
               refNodesIK_OSide[2].node.rotation.controller[2][3].value = -refNodesIK_Side[2].node.rotation.controller[2][3].value
               refNodesIK_OSide[2].node.ik_Blend.swtch_Ik_fk = refNodesIK_Side[2].node.ik_Blend.swtch_Ik_fk
               refNodesIK_OSide[2].node.ik_Blend.stretchP = refNodesIK_Side[2].node.ik_Blend.stretchP
               refNodesIK_OSide[2].node.ik_Blend.softP  = refNodesIK_Side[2].node.ik_Blend.softP
               refNodesIK_OSide[2].node.ik_Blend.pinP = refNodesIK_Side[2].node.ik_Blend.pinP
               refNodesIK_OSide[2].node.ik_Blend.freeOt = refNodesIK_Side[2].node.ik_Blend.freeOt
               refNodesIK_OSide[2].node.ik_Blend.freeElbo = refNodesIK_Side[2].node.ik_Blend.freeElbo
                     
               refNodesRoots_OSide[2].node.pos.controller.Position_Constraint.controller.weight[1] = refNodesRoots_Side[2].node.pos.controller.Position_Constraint.controller.weight[1]
               refNodesRoots_OSide[2].node.pos.controller.Position_Constraint.controller.weight[2] = refNodesRoots_Side[2].node.pos.controller.Position_Constraint.controller.weight[2]
                     
               refNodesIK_OSide[1].node.pos.controller[2][1].value = -refNodesIK_Side[1].node.pos.controller[2][1].value
               refNodesIK_OSide[1].node.pos.controller[2][2].value = refNodesIK_Side[1].node.pos.controller[2][2].value
               refNodesIK_OSide[1].node.pos.controller[2][3].value = refNodesIK_Side[1].node.pos.controller[2][3].value
                     
               refNodesFK_OSide[2].node.rotation.controller[2][1].value = -refNodesFK_Side[2].node.rotation.controller[2][1].value
               refNodesFK_OSide[2].node.rotation.controller[2][2].value = refNodesFK_Side[2].node.rotation.controller[2][2].value
               refNodesFK_OSide[2].node.rotation.controller[2][3].value = -refNodesFK_Side[2].node.rotation.controller[2][3].value
                     
               refNodesFK_OSide[3].node.rotation.controller[2][1].value = -refNodesFK_Side[3].node.rotation.controller[2][1].value
               refNodesFK_OSide[3].node.rotation.controller[2][2].value = refNodesFK_Side[3].node.rotation.controller[2][2].value
               refNodesFK_OSide[3].node.rotation.controller[2][3].value = -refNodesFK_Side[3].node.rotation.controller[2][3].value
                     
               refNodesFK_OSide[4].node.rotation.controller[2][1].value = -refNodesFK_Side[4].node.rotation.controller[2][1].value
               refNodesFK_OSide[4].node.rotation.controller[2][2].value = refNodesFK_Side[4].node.rotation.controller[2][2].value
               refNodesFK_OSide[4].node.rotation.controller[2][3].value = -refNodesFK_Side[4].node.rotation.controller[2][3].value
               
            )
            on CopyPasteHands pressed do
            (
               for n = 1 to refNodesHand_Side.count do
               (
                  refNodesHand_OSide[n].node.rotation.controller[2][1].value = -refNodesHand_Side[n].node.rotation.controller[2][1].value
                  refNodesHand_OSide[n].node.rotation.controller[2][2].value = refNodesHand_Side[n].node.rotation.controller[2][2].value
                  refNodesHand_OSide[n].node.rotation.controller[2][3].value = -refNodesHand_Side[n].node.rotation.controller[2][3].value
               )
               
            )
         )
         
            
      )
      custattributes.add  b.modifiers[#IK_Blend] IKFK_CA baseobject:false
      
   )   
---------------- Here I add my objects to the nodetransformMonitor ------------------------------------------
   
for i in SideIkList do
(
   obj=nodeTransformMonitor node:i  forwardTransformChangeMsgs:false
   append clIKWirst.modifiers[1].refNodesIK_Side obj
)
for i in SideFkList do
(
   obj=nodeTransformMonitor node:i  forwardTransformChangeMsgs:false
   append clIKWirst.modifiers[1].refNodesFK_Side obj
)
for i in OSIdeIkList do
(
   obj=nodeTransformMonitor node:i  forwardTransformChangeMsgs:false
   append clIKWirst.modifiers[1].refNodesIK_OSide obj
)
for i in OSIdeFkList do
(
   obj=nodeTransformMonitor node:i  forwardTransformChangeMsgs:false
   append clIKWirst.modifiers[1].refNodesFK_OSide obj
)
for i in SideRootLS do
(
   obj=nodeTransformMonitor node:i  forwardTransformChangeMsgs:false
   append clIKWirst.modifiers[1].refNodesRoots_Side obj
)
for i in OSideRootLS do
(
   obj=nodeTransformMonitor node:i  forwardTransformChangeMsgs:false
   append clIKWirst.modifiers[1].refNodesRoots_OSide obj
)
      
for i in HandList_Side do
(
   obj=nodeTransformMonitor node:i  forwardTransformChangeMsgs:false
   append clIKWirst.modifiers[1].refNodesHand_Side obj
)
         
for i in HandList_OSide do
(
   obj=nodeTransformMonitor node:i  forwardTransformChangeMsgs:false
   append clIKWirst.modifiers[1].refNodesHand_OSide obj
)

All objects contained in Oside lists, aren’t added.

Somebody can explain me what I am missing?

Thanks you.

7 Replies

first of all (AGAIN) i want your to add unique attribute id to your custom attribute…

because i don’t want to meet one day any scene with your current setup

Why?

every time you define(in your case also create) a new custom attribute without attribute id, the system gives a random id to the attribute definition.
if you want to make any changes to your attribute source in the future you have to have them with the same id. otherwise ALL once created attributes are unique!

The only thing that makes them similar is the name.

i’ve seen a scene with 5,000 identical CAs. applied to one max node. Of course the developer of this attribute was much “advanced”, hi “knew” not just how to create CA but also how to duplicate it.

after you add the unique ID to the attribute definition every new created or currently loaded CA will be automatically updated every time you change the attribute

Ok so if I understand I should add an attribute ID, with different number for each hand?
Looking like this?:

IKFK_CA = attributes ik_switch attribID: #(0x7f7438e8, 0x4515b94a) for on hand and
IKFK_CA = attributes ik_switch attribID: #(0x7f7438e9, 0x4515b94b) for the other?

the numbers are random, i mean can I put the numbers i want?

Thanks.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

i think that both left and right attribute are the same… it can be different by left/right flag. so they have to have the same id. and of course you can give an id you want. for example i use the same first part of id for all my attributes and plugins, and only randomly change the second part.

Ok, so you think had to rename the attribute in something like that:??

IKFK_CA_R = attributes ik_switchR attribID: #(0x7f7438e8, 0x4515b94a)
IKFK_CA_L = attributes ik_switchL attribID: #(0x7f7438e9, 0x4515b94b)

the point is that for creating my arms, I use the same fonction I made but I change the object I put in the arrays, in order to match the good right and left, so I use the fonction twice, and the strange thing is that the first arm created works perfectly, it’ always the last one which have the “Oside” lists empty.

ok… before we will fix the bug (if it exists), there is another question…

why do you use an empty modifier as an owner of the attribute? probably the only reason is that you saw this technique sometime somewhere…

what’s wrong with it? the only one… it can be collapsed and lost.

i would add the attribute to the baseobject of node. the only way to wipe it is to replace the instance … which is not trivial for an average user

ok sherlock !
you are right, i saw it and I repeat it… ah ah !
But for my defense, I don’t want to have all my custom attribute in the baseobject as it will mix with the other object rollouts, and it will be a little bit messy for the animators ( I am animator and I prefer get all attributes their own modifier)

I don’t think it’s a bug, I think i am the bug, sure i made something that make it not working…

Are you there Denis?