Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Python: Save image with a path

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Anonymous
1476 Views, 6 Replies

Python: Save image with a path

Hi guys,

 

I want to make an script to store all the texture images in the same folder. This are the variables in my script:

 

ext_Path = String with the path to the folder (C:\Users\me\Desktop\TextuFolder\)

filename_ext = Texture name and format (Texture1.jpg)

full_Path = The complete path wehere I'm storing the image (C:\Users\me\Desktop\TextuFolder\Texture1.jpg)

 

I just need the command to store the images in the selected path. Something like file() or saveImage(). But I'm really newbie in Python programing.

 

Thanks in advance.

Tags (1)
6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: Anonymous

No one? 😕

Message 3 of 7
osidedan
in reply to: Anonymous

Hello! what you probably need to do is import the shutil python module, and then use the copyfile function from that module.

 

here's an example:

 

import shutil
shutil.copyfile('c:/source/test_image.png', 'c:/destination/test_image_copy.png')

 

 

of note, the following things have to exist for the copy to work:

1. the source FILE must exist.

2. the destination FOLDER PATH must exist.

 

 

Let me know if you need more info on any of that!

 

Edit: to clarify, shutil is a native python module, meaning it is just part of python, it's not something maya related. Python has a TON of native modules that you can import and use to do all kinds of things. 

Message 4 of 7
Anonymous
in reply to: osidedan

Hi!

 

First of all, thanks for your answer. I tried using your solution but I had an unexpected error: 

 

Maya.PNG

And both things exists: destination folder (I get the path with a cmds.fileDialog2(...)) and the source image (cmds.ls(type="file")). I also tried doing it with the shutil.copy(src, dst) operation but the same error appears.

 

Thanks!

Message 5 of 7
osidedan
in reply to: Anonymous

hmm, interesting. To narrow things down, I would recommend trying to doing a simple copy first. Not one that is part of your script, just a simple one liner of shutil.copy(), and just use strings for your source and destination. If that works, then we know that we need to make adjustments to your script. if that DOESN'T work, then there may be something corrupt with your Maya preferences, or the python install. 

 

Try that super simple copy, and let me know your results!

Message 6 of 7
Anonymous
in reply to: osidedan

Good morning!

 

After reinstalling Python, shutil works perfectly! 

 

Thanks!!

Message 7 of 7
osidedan
in reply to: Anonymous

You’re welcome!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report