Isotropix Forums

Open selected textures with Photoshop

Find useful scripts shared by the community here

Open selected textures with Photoshop

Unread postby bvaldes » Thu Nov 15, 2018 10:41 am

Hi,

A Clarisse user ask for a script to open textures in Photoshop. After looking for a way by using command line, we found a blog post that shows a way to interact with Photoshop: http://techarttiki.blogspot.com/2008/08 ... ython.html

Before using the script you have to install through pip a package called pywin32:
Code: Select all
pip install pywin32

If the command doesn't work, you probably need to upgrade pip:
Code: Select all
pip install --updgrade pip


You can find bellow a script that allow you to open the selected textures from Clarisse in Photoshop

python code

import  os, win32com.client

def checkUDIM(filenames):
udimFiles = []
for filename in filenames:
if "<UDIM>" in filename:
filenameList = os.path.basename(filename).split("<UDIM>")
udimFiles = []

for file in os.listdir(os.path.dirname(filename)):

if file.startswith(filenameList[0]) and file.endswith(filenameList[-1]):
udimFiles.append(os.path.dirname(filename) + "/" + file)
if udimFiles:
return udimFiles
return filenames

def getFilenames():
filenames = []
for i in range(ix.selection.get_count()):
item = ix.selection[i]
if item.is_kindof("Texture"):
filenameAttr = item.attribute_exists("filename")
if filenameAttr:
filename = [filenameAttr.get_string()]
for filename in checkUDIM(filename):
filenames.append(filename)
return filenames



files = getFilenames()
psApp = win32com.client.Dispatch("Photoshop.Application")
for file in files:
psApp.Open(file)


Best regards
Benoit VALDES
Isotropix
Clarisse QA
User avatar
bvaldes
 
Posts: 384
Joined: Mon Sep 26, 2016 10:44 am

Re: Open selected textures with Photoshop

Unread postby purchasemediamonks » Thu Nov 15, 2018 12:29 pm

Fantastic! It works and thank you for your time looking into it. Have a nice day!
purchasemediamonks
 
Posts: 24
Joined: Wed Jan 25, 2017 10:03 am

Re: Open selected textures with Photoshop

Unread postby SamSmith228 » Sun Jan 13, 2019 12:57 pm

There are so much incredible information that I was looking for. Thank you for that. I'll use it in my job for the future.
Have a nice day.
Sam
SamSmith228
 
Posts: 1
Joined: Sun Jan 13, 2019 12:53 pm

Re: Open selected textures with Photoshop

Unread postby purchasemediamonks » Thu Feb 28, 2019 1:02 pm

With the latest python, pip setuptools and pip installation the script won't work any more. Did anybody run into this problem and now how to fix this? Thank you in advance!
purchasemediamonks
 
Posts: 24
Joined: Wed Jan 25, 2017 10:03 am

Re: Open selected textures with Photoshop

Unread postby bvaldes » Thu Feb 28, 2019 2:11 pm

Hi,

Which version of python do you use?
Clarisse is working on 2.7.x and the Python packages are not the same for Python 2.7.x and 3.6.x so that can be related. It works great for me with Python 2.7.14 on Windows 10 Pro.
Benoit VALDES
Isotropix
Clarisse QA
User avatar
bvaldes
 
Posts: 384
Joined: Mon Sep 26, 2016 10:44 am

Re: Open selected textures with Photoshop

Unread postby purchasemediamonks » Fri Mar 01, 2019 10:58 am

Thanks for your response. We use 2.7.15 on windows 10 Pro. We updated the scripts for the survival kit and after running the psd script there is an error. Photoshop is already started so that won't be a problem.

Traceback (most recent call last):
File "<string>", line 1, in <module>
0 File "c:\Python27\lib\site-packages\win32com\__init__.py", line 5, in <module>
import win32api, sys, os
ImportError: DLL load failed: %1 is not a valid Win32 application.
purchasemediamonks
 
Posts: 24
Joined: Wed Jan 25, 2017 10:03 am

Re: Open selected textures with Photoshop

Unread postby purchasemediamonks » Tue Mar 05, 2019 11:16 am

Any change to sort this out? I tried a lot of things but with no luck unfortunately. Many thanks in advanced!
purchasemediamonks
 
Posts: 24
Joined: Wed Jan 25, 2017 10:03 am

Re: Open selected textures with Photoshop

Unread postby sam » Tue Mar 05, 2019 12:00 pm

It seems that you are using a 32 bit version of Python installed, hence the error. Could you launch the python command line and output what's displayed in the header?
Sam Assadian
Isotropix
CEO/Founder
User avatar
sam
 
Posts: 1395
Joined: Fri Jan 25, 2013 11:33 pm

Re: Open selected textures with Photoshop

Unread postby Marcuzzz » Tue Mar 05, 2019 4:51 pm

I've took these steps to fix it, not tested if all steps are necessary but this was the order:
- Uninstalled Python 2.7.15
- Installed Python 2.7.14, 64
- pip list
- pip uninstall pywin32 and every other "pypiwin32" package I could find
- pip install pywin32
- pip install pypiwin32
- cmd as Administrator
- run this script: C:\Python27\Scripts\python pywin32_postinstall.py -install
- Then the script worked but still there was one error...
- I then reinstalled Photoshop
- and ran this script: C:\Python27\Scripts\python pywin32_postinstall.py -install again

I think the last 2 steps might did the trick in the end...
Marcuzzz
 
Posts: 3
Joined: Thu Apr 26, 2018 9:16 am

Re: Open selected textures with Photoshop

Unread postby Marcuzzz » Tue Mar 05, 2019 5:48 pm

Slightly improved script:

Because tx files can't be opened directly with Photoshop. (You could rename them to tif)
but more often there is an other format like psd or tif available at the same location of the tx.
So I added a simple check if other ext exists and open those instead of the tx...

python code

import os
from win32com.client import Dispatch
import win32clipboard

# add more extensions if you like:
exts = ['.psd','.tif','.exr','.jpg']

def checkUDIM(filenames):
udimFiles = []
for filename in filenames:
if "<UDIM>" in filename:
filenameList = os.path.basename(filename).split("<UDIM>")
udimFiles = []

for file in os.listdir(os.path.dirname(filename)):

if file.startswith(filenameList[0]) and file.endswith(filenameList[-1]):
udimFiles.append(os.path.dirname(filename) + "/" + file)
if udimFiles:
return udimFiles
return filenames

def getFilenames():
filenames = []
for i in range(ix.selection.get_count()):
item = ix.selection[i]
if item.is_kindof("Texture"):
filenameAttr = item.attribute_exists("filename")
if filenameAttr:
filename = [filenameAttr.get_string()]
for filename in checkUDIM(filename):

if os.path.splitext(filename)[1].lower() == '.tx':
for ext in exts:
if os.path.isfile(os.path.splitext(filename)[0] + ext):
filenames.append(os.path.splitext(filename)[0] + ext)
else:
filenames.append(filename)
return filenames

files = getFilenames()
print(files)
psApp = Dispatch("Photoshop.Application")
for file in files:
psApp.Open(file)

#Get the pad to the file to the clipboard:

win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardText("/".join(file.split('/')[:-1])+'/')
win32clipboard.CloseClipboard()
Marcuzzz
 
Posts: 3
Joined: Thu Apr 26, 2018 9:16 am


Return to Useful Community Scripts