Adding RIG space

43 views
Skip to first unread message

SquashnStretch net

unread,
May 8, 2023, 4:56:17 PM5/8/23
to Python Programming for Autodesk Maya
In my previous post, I asked for help understanding how to connect different nodes from different elements all at once. I managed to work around the problem by connecting the attributes one by one, which seemed to work.

Now, I have another, easier problem for experienced Python users. Let me try to explain.

I am trying to write a code that adds a new space attribute to the arm of a rig, connecting to the Head, Hips, and Body if they don't have this option. If I add one space option to the right arm at a time, the script works well. However, if I add a space to the other arm and then go back to the first arm to add another space, the script fails.

I think it may be a matter of some global variable, but even when I try to update it, I end up breaking the script. If you have the time, I would appreciate it if you could take a look at my code. If you want to test it, you can probably use any Maya rig.

Thanks in advance
Filippo


Justin Israel

unread,
May 8, 2023, 5:35:17 PM5/8/23
to python_in...@googlegroups.com
This pastebin is reporting that it's either private or pending moderation. Make sure you set the pastebin to public.
 


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/c92c073f-47d5-4d5a-93c6-06171bf81c5cn%40googlegroups.com.

SquashnStretch net

unread,
May 8, 2023, 5:45:21 PM5/8/23
to python_in...@googlegroups.com
oh damn, sorry....
can you retry please ?

thanks
F

Justin Israel

unread,
May 10, 2023, 3:22:57 AM5/10/23
to python_in...@googlegroups.com


On Tue, 9 May 2023, 9:45 am SquashnStretch net, <squashn...@gmail.com> wrote:
oh damn, sorry....
can you retry please ?

Oops forgot to reply. Yes it's accessible now. 

SquashnStretch net

unread,
May 10, 2023, 4:40:02 AM5/10/23
to Python Programming for Autodesk Maya
great, let me know if you can take a look at it.

Thanks in advance
Filippo



Justin Israel

unread,
May 10, 2023, 5:36:29 AM5/10/23
to python_in...@googlegroups.com


On Wed, 10 May 2023, 8:40 pm SquashnStretch net, <squashn...@gmail.com> wrote:
great, let me know if you can take a look at it.


I only took a quick look. It seems like you don't even need globals (unless I missed something). If you get rid of the extra printing code, what is left is the first two button callbacks that app and they get their own selection list each time. 
Mutable globals as state are a good way to end up with bugs. It is better to try and pass data between functions as args. Or to use a class so that each instance can store state. But maybe just getting rid of globals in the first place is enough here. There is even one of those functions where the selection list isn't declared global so it's a local list in that scope. 
There may be actual bugs in the Maya commands code but I didn't look closely enough. 


SquashnStretch net

unread,
May 10, 2023, 1:18:07 PM5/10/23
to Python Programming for Autodesk Maya
Thanks Justin for your time. 
Good to know about globals can cause issue.... 
Anyways I tried not to use those, but I keep getting errors....I'll try to understand better how to do, maybe I'll create also a global class.
THanks again

F

Justin Israel

unread,
May 10, 2023, 4:11:52 PM5/10/23
to python_in...@googlegroups.com
Try working with a more simplified version of your script that specifically isolates the problem you are seeing. That also helps others when you are asking for help.
Here is a smaller version of your script, with the globals removes, some excess functions and buttons removed, and a few corrections: 
  • on_make_selection_button_clicked: I noticed that you aren't limiting the addAttr() to a specific selected_object when you are looping, so if you had more than 1 selection, it would always try to add to all. I've set it to add to the current object in the loop
  • on_new_selection_button_clicked: When you are looking up the existing_groups, you are grabbing every transform in the scene that ends with "_spaceGrp". But the rest of the code in that function seems to want to operate only on the selection. So I have updated the ls() to only find transforms in the current selection
Other than that, if you want more help, please describe a specific list of steps to perform, what you expect to happen, and what you actually see happening as an error instead.

Justin


sns

unread,
May 11, 2023, 4:23:16 AM5/11/23
to python_in...@googlegroups.com
Thanks very much Justin 
And sorry, yes in my first post I said it was complicate even to explain but I tried my best to do it…..I’l try to be more clear next time.

Anyways, thanks a lot for you time, I love the way to simplify the code, but I tried and it doesnt  work because when I press Connect to, it fail because it doesnt find the spaceGroup just created. I remember I had this same issue, that’s why I ddnt put into a loop and instead looking for that unique name I gave to the group.
I’ll try maybe to switch the if else condition to see if works.

Thanks again
F




Reply all
Reply to author
Forward
0 new messages