Skip to content

Instantly share code, notes, and snippets.

@cg-cnu
Last active December 31, 2015 15:19

Revisions

  1. cg-cnu revised this gist May 27, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion patchBake.py
    Original file line number Diff line number Diff line change
    @@ -65,7 +65,7 @@ def patchBake():
    uv = patch.uvIndex()

    curPatchIndex = str(patch.udim())
    savePath = path + curChanName + '.' + curPatchIndex + '.tif'
    savePath = curGeo.name() + "_" +curChanName + '_' + curPatchIndex + '.tif'

    patchImg = curImgSet.image(uv, -1)
    patchImg.saveAs(savePath)
  2. cg-cnu revised this gist Jan 12, 2014. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions patchBake.py
    Original file line number Diff line number Diff line change
    @@ -34,11 +34,10 @@ def patchBake():
    return

    if mari.app.version().isWindows():
    path = str("C:\\")
    path = str(mari.resources.path("MARI_USER_PATH")).replace("\\", "/")
    else:
    user = os.popen('whoami').read().split()[0]
    path = str ('/home/'+ user + '/Desktop/' )

    path = str( mari.resources.path("MARI_USER_PATH") )

    curChan = curGeo.currentChannel()
    curChanName = str(curChan.name())

  3. cg-cnu revised this gist Jan 4, 2014. 1 changed file with 6 additions and 5 deletions.
    11 changes: 6 additions & 5 deletions patchBake.py
    Original file line number Diff line number Diff line change
    @@ -30,13 +30,14 @@ def patchBake():
    selPatchList = [patch for patch in patchList if patch.isSelected() ]

    if len(selPatchList) == 0:
    mari.utils.meesage('Select atleast one patch')
    mari.utils.meesage('Select atleast one patch', title = 'Error')
    return

    # get the windows path working

    user = os.popen('whoami').read().split()[0]
    path = str ('/home/'+ user + '/Desktop/' )
    if mari.app.version().isWindows():
    path = str("C:\\")
    else:
    user = os.popen('whoami').read().split()[0]
    path = str ('/home/'+ user + '/Desktop/' )

    curChan = curGeo.currentChannel()
    curChanName = str(curChan.name())
  4. cg-cnu revised this gist Dec 28, 2013. 1 changed file with 21 additions and 13 deletions.
    34 changes: 21 additions & 13 deletions patchBake.py
    Original file line number Diff line number Diff line change
    @@ -2,15 +2,15 @@
    # 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.
    # 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 menue item in Patches > Patch Bake
    # Creates a menu item in Patches > Patch Bake
    #
    # @uthor sreenivas alapati (cg-cnu)
    # ------------------------------------------------------------------------------
    @@ -22,7 +22,7 @@ def patchBake():
    '''Bake the selected patches to image manager'''

    if not mari.projects.current():
    mari.utils.message('No project currently open')
    mari.utils.message('No project currently open', title = 'Error')
    return

    curGeo = mari.geo.current()
    @@ -32,15 +32,19 @@ def patchBake():
    if len(selPatchList) == 0:
    mari.utils.meesage('Select atleast one patch')
    return

    mari.history.startMacro('Patch Bake')
    mari.app.setWaitCursor()

    # get the windows path working

    user = os.popen('whoami').read().split()[0]
    path = str ('/home/'+ user + '/Desktop/tmp_bake_tmp.tga' )
    path = str ('/home/'+ user + '/Desktop/' )

    curChan = curGeo.currentChannel()
    layers = list(curChan.layerList())
    curChanName = str(curChan.name())

    layers = curChan.layerList()

    mari.history.startMacro('Patch Bake')
    mari.app.setWaitCursor()

    for layer in layers:
    layer.setSelected(True)
    @@ -57,17 +61,21 @@ def patchBake():
    curImgSet = curLayer.imageSet()

    for patch in selPatchList:

    uv = patch.uvIndex()

    curPatchIndex = str(patch.udim())
    savePath = path + curChanName + '.' + curPatchIndex + '.tif'

    patchImg = curImgSet.image(uv, -1)
    patchImg.saveAs(path)
    patchImg.saveAs(savePath)

    mari.images.load(path)
    os.remove(path)
    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")
    mari.menus.addAction(mari.actions.create('Patch Bake', 'patchBake()'), "MainWindow/Patches")
  5. cg-cnu revised this gist Dec 28, 2013. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions patchBake.py
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    # ------------------------------------------------------------------------------
    # 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.
    # 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
  6. cg-cnu created this gist Dec 17, 2013.
    73 changes: 73 additions & 0 deletions patchBake.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,73 @@
    # ------------------------------------------------------------------------------
    # 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 menue 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')
    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')
    return

    mari.history.startMacro('Patch Bake')
    mari.app.setWaitCursor()

    user = os.popen('whoami').read().split()[0]
    path = str ('/home/'+ user + '/Desktop/tmp_bake_tmp.tga' )

    curChan = curGeo.currentChannel()
    layers = list(curChan.layerList())

    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()

    patchImg = curImgSet.image(uv, -1)
    patchImg.saveAs(path)

    mari.images.load(path)
    os.remove(path)

    curChan.removeLayers()

    mari.history.stopMacro()
    mari.app.restoreCursor()

    mari.menus.addAction(mari.actions.create('Patch Bake', 'patchBake()'), "MainWindow/Patches")