Dynamic Shelf Loading

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  01 January 2013
Unhappy Dynamic Shelf Loading

Hey guys!

Just had a question that I'm having problems googling/searching on the forum...I'm trying to dynamically load a shelf so that it always appears in its most updated state on the user's computer. Here's what I've figured out so far:
I am using Maya.env and added a line

$MAYA_STARTUP_SCRIPT_PATH = (shared directory where I have a startup.mel file)


The startup.mel file says:
//check to see if shelf exists
string $install_shelfName = "andres";
string $install_shelfPath = "/usr/people/andres-w/andresShelfMaster/shelf_andres.mel";
int $install_shelfExists = `layout -q -ex $install_shelfName`;
if ($install_shelfExists == 1){
  print "Deleting existing Andres shelf\n";
  deleteUI -layout $install_shelfName;
}

//add shelf
print "Adding Andres Shelf\n";
loadNewShelf $install_shelfPath;


So this doesn't quite work to remove the old shelf cleanly...and using the command deleteShelfTab requires hitting OK and doesn't work either. Any help would be most appreciated! Also I'm probably doing this completely wrong so...thanks for pointing me in the right direction ahead of time!

Background: Can't use userSetup.mel since it's getting overridden by our pipeline in some way that I'm not sure of...
__________________
MPC NYC
Andres Weber | CG Generalist
434 Broadway, 9th Floor, New York City, 10013
GChat AndresMWeber
www.moving-picture.com

Last edited by Daemonecles : 01 January 2013 at 09:16 PM.
 
  01 January 2013
So I fixed the issue. Took the command deleteShelfTab from the maya install and removed all confirmDialog mentions and now the shelf deletes properly (I think the other UI command doesn't do it cleanly because it leaves the .deleted file).

New Issue: The loadNewShelf command, if done at startup seems to load a shelf that's blank. When I run the exact same code to delete and repopulate the shelf when maya is already running it works as intended...anyone know a workaround?
__________________
MPC NYC
Andres Weber | CG Generalist
434 Broadway, 9th Floor, New York City, 10013
GChat AndresMWeber
www.moving-picture.com
 
  01 January 2013
For the startup code, try wrapping it in an evalDeferred command.
 
  01 January 2013
Thanks for the reply. Looks like using evalDeferred delays the creation of the shelf but messes up start up code:

// Error: file: /software/maya/2012.4.5/linux.centos5.x86_64/scripts/startup/shelf.mel line 81: Object 'andres' not found. // 


Looks like this mel gets confused because our shelf doesn't exist at startup but for some reason Maya thinks it still was. Line 81 in that code is just trying to determine whether a shelf is unpopulated with buttons and populates it if it isn't.

Edit: Oh! You're the author of Charcoal Editor! I totally bought that awhile back. Thanks!
__________________
MPC NYC
Andres Weber | CG Generalist
434 Broadway, 9th Floor, New York City, 10013
GChat AndresMWeber
www.moving-picture.com

Last edited by Daemonecles : 01 January 2013 at 10:31 PM.
 
  01 January 2013
Hi Daemonecles,

I've been here before and have a few hints.

* if you're looking to update a shelf, don't try and delete the entire shelf. You end up with shelves that won't update properly, and general mysteriousness. Instead, delete all the buttons, but leave the shelf there. Then you can add the updated buttons.

* loading in new shelves from the disk: i use a method where you open up the shelf mel file and replace some stuff and eval it. python code here:

		fReObj = re.search("(shelfButton.*\;[\r\n])", shelfContents, re.DOTALL)
		if fReObj:
			shelfBtnStr = fReObj.group(1)
			n = shelfBtnStr.replace('shelfButton', 'shelfButton\n -parent ' + shelfName)
			mel.eval(n)


that's all i got. it works pretty well once you get it going. best of luck.

cheers,
chrisg
 
  01 January 2013
Thumbs up

Phew! I was looking for some good stuff like this! Thanks man, I'll test it out tomorrow but I'm sure it works.
__________________
MPC NYC
Andres Weber | CG Generalist
434 Broadway, 9th Floor, New York City, 10013
GChat AndresMWeber
www.moving-picture.com
 
  01 January 2013
Here is some abstracted code I use to manage Shelves.
If you can put your Shelves in source control and update Maya's Shelve Directory, then you dont have to worry about the user altering the Shelf and saving a copy in the user folder. Since the shelf is write protected by source control, Maya will be unable to save it when exiting.
This makes updating shelves and ensuring everyone has the latest changes really easy.

Unfortunately, I dont have that luxurty currently, so i made these wrapper functions to manage updating the shelves for me. I used the same trick of leaving the shelf and clearing the buttons.


def createMyShelf():
	shelfName = 'My_Shelf'
	test = cmds.shelfLayout(shelfName, ex=True)
	if test:
		# If the shelf already exists, clear the contents and re-add the buttons.
		newShelf = shelfName
		buttons = cmds.shelfLayout(newShelf, query=True, childArray=True)
		cmds.deleteUI(buttons, control=True)	   
	else:
		newShelf = mel.eval('addNewShelfTab %s' % shelfName)	   
	cmds.setParent(newShelf)
	# add buttons here


def removeShelf():
	shelfName = 'My_Shelf'
	test = cmds.shelfLayout(shelfName, ex=True)
	if test:
		mel.eval('deleteShelfTab %s' % shelfName)
		gShelfTopLevel = mel.eval('$tmpVar=$gShelfTopLevel')
		cmds.saveAllShelves(gShelfTopLevel)
	else:
		return
 
  01 January 2013
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 12:10 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.