SimplyMaya Forums

Welcome to the forum, feel free to ask questions here.


SM Forums / Maya Questions / Programming / Script request for sets management

Programming MEL Scripts, Expressions & Programming Related Topics

Join the conversation. Reply to post
 
Thread Tools
26-07-2012, 10:18 AM   #1
yoruneko
Registered User
 
Join Date: Jan 2012
Posts: 43
Script request for sets management
Hello guys!
I was wondering how hard it would be to write two commands:

one would be "add current object(s) to set XX"
and the other "remove current object(s) from set XX"

thing is, I don't want to have to select the set I want to add/remove the object!
I would just like a variable set name inside the script that I could change manually to suit my needs.
That's because we have a number of Sets with pre defined names all over the place and we have to add/remove stuff all the time.
I know I can use the relationship editor or drag and drop blablablah, the key here is to GO FAST and don't interrupt workflow...
I'd make a marking menu with those commands with add/rem for all sets..

If a kind soul has the time to do this, I'd be ever so gratefull!
  Reply with quote
26-07-2012, 02:50 PM   #2
yoruneko
Registered User
 
Join Date: Jan 2012
Posts: 43
Ok I couldn't wait so I teached myself some python, that was super simple actually!


def add2Set():
selection = cmds.ls(sl=True)
myObject =selection[0]
cmds.sets( (myObject), add='SET01' )

but I couldn't get it to work inside a marking menu because it's python..
I tryed the python import command but then I get this error : # Error: NameError: global name 'cmds' is not defined #

What the eff?? script is working fine from a shelf...

Any ideas??
  Reply with quote
26-07-2012, 02:53 PM   #3
ctbram
Moderator
 
ctbram's Avatar
 
Join Date: Jan 2004
Location: Michigan, USA
Posts: 2,997
This capability is already built in to maya (I am currently using maya 2012. Not sure how far back it goes). To access the set manager gui select...

windows > relationship editors > sets

This brings up a gui that will show you all your sets, what is in them, and has a + / - button to add and remove elements to and from selected sets.
__________________
"If I have seen further it is by standing on the shoulders of giants." Sir Isaac Newton, 1675
  Reply with quote
26-07-2012, 03:00 PM   #4
yoruneko
Registered User
 
Join Date: Jan 2012
Posts: 43
Ho man you didn't read my first post
  Reply with quote
26-07-2012, 03:05 PM   #5
ctbram
Moderator
 
ctbram's Avatar
 
Join Date: Jan 2004
Location: Michigan, USA
Posts: 2,997
Seriously? It takes to much time to simply put the set editor on the shelf and then

1. click the shelf button
2. click the + or - key

Really?

Oh well if you must have a script. Why not just echo all commands in the script editor and then using the set editor add a selection to a set and then open the script editor and using the code generated you can create your generalized script add. Then do the same thing for the - key.
__________________
"If I have seen further it is by standing on the shoulders of giants." Sir Isaac Newton, 1675
  Reply with quote
26-07-2012, 03:24 PM   #6
yoruneko
Registered User
 
Join Date: Jan 2012
Posts: 43
This is the first thing I tried, doesn't work. There's no clear command coming out of history like addtoSet and so forth..
But thanks for your kinda weirdly aggressive advice!

actually I have no idea what I'm doing, the script can be much simpler:

selection = cmds.ls(sl=True)
cmds.sets( (selection), add='SET01' )

Last edited by yoruneko; 26-07-2012 at 03:53 PM.
  Reply with quote
26-07-2012, 05:13 PM   #7
yoruneko
Registered User
 
Join Date: Jan 2012
Posts: 43
allright I got it.

the most tricky part was loading python from the marking menus. It wouldn't work because I didn't load maya.cmds in my .py now it's working, oh the glory...

Well, I pat myself on the back I guess!

Last edited by yoruneko; 26-07-2012 at 05:25 PM.
  Reply with quote
25-02-2017, 06:30 PM   #8
blastframe
Registered User
 
Join Date: Oct 2016
Posts: 2
This script could be of use to you:
Set List
  Reply with quote
26-02-2017, 11:29 PM   #9
Jay
Lead Modeler - Framestore
 
Jay's Avatar
 
Join Date: Feb 2003
Location: UK
Posts: 6,277
You kids!! Nothing changes when 'speed' is of the essence

Yeah I agree with CTBram, call me old school but the reason the set editor is there is for that exact reason, having a script is a bit pretentious and is not always going to be an advantage when you need to do this type of work at a component level.

With a python command you will always need to have 'import maya cmds'

The set editor has been around since jesus, and its not going anywhere soon, I can tell you that

Jay
  Reply with quote
04-04-2017, 08:39 AM   #10
yummip
Registered User
 
Join Date: Apr 2017
Posts: 1
Quote:
You kids!! Nothing changes when 'speed' is of the essence

Yeah I agree with CTBram, call me old school but the reason the set editor is there is for that exact reason, having a script is a bit pretentious and is not always going to be an advantage when you need to do this type of work at a component level.

With a python command you will always need to have 'import maya cmds'

The set editor has been around since jesus, and its not going anywhere soon, I can tell you that

Jay
Yes, all very well until you need to make 1000 relationship edits and then code becomes quite useful...
  Reply with quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Script Request, assistance please :) rayman101 Programming 4 26-01-2016 04:47 AM
New Script REquest G-Man Programming 12 06-03-2014 03:41 AM
Script Request G-Man Programming 14 29-04-2012 06:49 PM
changing the "Quick help" window size in the maya 2012 script editor. Jouri Programming 3 27-11-2011 06:15 AM
load pre-made script rejh2 Maya Basics & Newbie Lounge 3 28-02-2010 12:33 AM