Last active
December 31, 2015 15:19
-
-
Save cg-cnu/8006248 to your computer and use it in GitHub Desktop.
Bakes the current selected patches for the whole object to image manager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ------------------------------------------------------------------------------ | |
# Patch Bake | |
# ------------------------------------------------------------------------------ | |
# Bakes the selected patches to images manager. | |
# Works the same as patches > extract selected but for the whole channel | |
# and on all the selected patches. | |
# | |
# copy the script to the same location as your log folder in | |
# windows: C:\Users\[user_name]\Documents\Mari\Scripts | |
# linux: /home/[user_name]/Mari/Scripts | |
# Mac: /home/[Username]/Mari/Scripts | |
# | |
# Creates a menu item in Patches > Patch Bake | |
# | |
# @uthor sreenivas alapati (cg-cnu) | |
# ------------------------------------------------------------------------------ | |
import mari | |
import os | |
def patchBake(): | |
'''Bake the selected patches to image manager''' | |
if not mari.projects.current(): | |
mari.utils.message('No project currently open', title = 'Error') | |
return | |
curGeo = mari.geo.current() | |
patchList = list (curGeo.patchList() ) | |
selPatchList = [patch for patch in patchList if patch.isSelected() ] | |
if len(selPatchList) == 0: | |
mari.utils.meesage('Select atleast one patch', title = 'Error') | |
return | |
if mari.app.version().isWindows(): | |
path = str(mari.resources.path("MARI_USER_PATH")).replace("\\", "/") | |
else: | |
path = str( mari.resources.path("MARI_USER_PATH") ) | |
curChan = curGeo.currentChannel() | |
curChanName = str(curChan.name()) | |
layers = curChan.layerList() | |
mari.history.startMacro('Patch Bake') | |
mari.app.setWaitCursor() | |
for layer in layers: | |
layer.setSelected(True) | |
copyAction = mari.actions.find('/Mari/Layers/Copy') | |
copyAction.trigger() | |
pasteAction = mari.actions.find('/Mari/Layers/Paste') | |
pasteAction.trigger() | |
curChan.mergeLayers() | |
curLayer = curChan.currentLayer() | |
curImgSet = curLayer.imageSet() | |
for patch in selPatchList: | |
uv = patch.uvIndex() | |
curPatchIndex = str(patch.udim()) | |
savePath = curGeo.name() + "_" +curChanName + '_' + curPatchIndex + '.tif' | |
patchImg = curImgSet.image(uv, -1) | |
patchImg.saveAs(savePath) | |
mari.images.load(savePath) | |
os.remove(savePath) | |
curChan.removeLayers() | |
mari.history.stopMacro() | |
mari.app.restoreCursor() | |
mari.menus.addAction(mari.actions.create('Patch Bake', 'patchBake()'), "MainWindow/Patches") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment