[Python] Save art3dPaintCtx image file externally

Become a member of the CGSociety

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

Thread Tools Search this Thread Display Modes
  09 September 2013
[Python] Save art3dPaintCtx image file externally

Currently I'm using Maya's 3D Paint Tool to draw textures on geometry. It works really nice, but I'm unable to save the outcoming painted image to a custom directory of choice.

Maya seems to force it to "sourceimages/3dPaintTextures/.."

This location is defined in the project settings, but I want to save it to a custom directory with Python.

mc.art3dPaintCtx() has a 'saveTexture' flag, but that takes no arguments and just saves to the 'disc' a.k.a. the folder described earlier.


Does anybody know a way to save the texture to a custom location, with Python, without adjusting the project settings?
  09 September 2013
I'm not too sure about a specific flag that does this but you can always just move the file to a new location after it's been created.

from shutil import move
import maya.cmds as mc

sImages = mc.workspace(dir=1, q=1).replace("scenes", "sourceimages/3dPaintTextures")
move(sImages, "/Path/to/new/dir")

Last edited by Argiri : 09 September 2013 at 05:12 PM.
  09 September 2013
Hi Guys!!

here another solution. The problem is: Maya is always going to save the 3dtextures that youŽre painting with the art3dPaint in the folder defined as "3d paint textures" folder. So, you can use the system that youŽre using now, Maya is going to save the file in 3dPaintTextures, and here a code to make a backup/copy of your texture that are currently painting. So, you have the one that you're working all the time, and when you want, execute this, and youŽll update your backup/copy:

import maya.cmds as cmds
import maya.mel as mel
import shutil as sh

def saveMy3DTexture( outputFolder ):
        # get the name of the shader that contains the texture you're painting now
        shaderName = cmds.art3dPaintCtx  ( mel.eval("currentCtx" ), q=True,  shadernames=True )
        # get the attribute that you're painting  (color, transparency, ....)
        attrName = cmds.art3dPaintCtx  ( mel.eval("currentCtx" ), q=True,  painttxtattrname=True )
        # the comlete name  node-attribute
        textureNodeName = cmds.listConnections( shaderName + "." + attrName )[0]
        # get the name of the texture that the art3dPaintCtx has connected in the shader
        textureName = cmds.getAttr( textureNodeName + ".fileTextureName" )
        # get the extension of the image
        extension = "." + mel.eval( 'fileExtension( "' + textureName + '")' )
        # get the name of the file
        fileName = mel.eval( 'basenameEx "' + textureName + '"' )
        # set the name of the file
        outputName = outputFolder + fileName + extension
        # copy the image
        print "Copying image from  \n>>" + textureName + "<<  \nto   \n>>" + outputName + "<<"
        sh.copy( textureName, outputName )

saveMy3DTexture( "c:/tmp/" )

With that function, you only have to set the folder where you want to write the image, and automatically will copy the image that you're painting in that moment. Important: first you have to save with the art3dPaint tool, and then execute this. And remember to keep active your art3dPaint tool, otherwise you canŽt access to the artisan functions.

I think is useful, because you can paint different textures in your scene, but you only want to copy some of them. And you always have two versions, the one in 3dPaintTextures folder and the one that you copy in the other folder. I tried and it works fine!

Well, let me know if it works for you.


Last edited by JoseCuenca : 09 September 2013 at 01:09 AM.
  09 September 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
Society of Digital Artists

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

All times are GMT. The time now is 01:49 PM.

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