Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Photoshop : Programatically import datasets from csv file (adobe script, python ...)

New Here ,
Aug 08, 2019 Aug 08, 2019

Hello,

 

Does anybody know how to import a dataset to a psd file programmatically (adobe scripting, python ...) ?

 

I have tried multiple ways but i didn't found a way do make it work:

  • with python use win32com to open the psd file and try to navigate to Image > Variables > Data Sets and choose the .csv file i want  => not found a way to do it
  • create an action to import the dataset => the action doesn't record the importation

 

Thanks for your help

 

Cheers

Guillaume

 

[Here is the list of all Adobe forums... Adobe Support Community]

[Moved from generic Cloud/Setup forum to the specific Program forum... Mod]

TOPICS
Actions and scripting
3.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Aug 08, 2019 Aug 08, 2019

Photoshop scripting is implemented in a Photoshop plug_in ScriptingSupport.8li and supports JavaScript, AppleScript and VBS only Photoshop JavaScript work cross platform. Adobe JavaScript DOM does not cover all of Photoshop feathers often Action Manager code needs to be used in Photoshop scripts to automats some features. Most here use JavaScript..

I also do not use Photoshop Data Driven Graphics so I do not  know if the CVS file is in the PSD file or if there is a link or a reference to the location of any external CVS File  in the Data Driven Graphics Template PSD file. Photoshop variables may be all that is defined in a template PSD file. Creating data-driven graphics in Photoshop

If you save the PSD template before importing a data set I do not know if you have to save the PSD after importing a CVS file.  You just want to export the generated  populated output image files.

I do not know if there are  third party  Photoshop Scripting Plug-in that supports python scripting or what Photoshop features python can support. Using a web search the first interesting thing I see  is this GitHub - lohriialo/photoshop-scripting-python: Scripting in Photoshop is used to automate a wide var...

there may be other information on the  web for automating Photoshop via Python scripting.

Scripting in Photoshop is used to automate repetitive tasks and are often used as a creative tool to streamline tasks that might be too time consuming to do manually. For example, you could write a script to generate a number of localized versions of a particular image or to gather information about the various color profiles used by a collection of images.

https://github.com/lohriialo/photoshop-scripting-python#photoshop-com--domPhotoshop COM & DOM

Photoshop can be scripted through COM(Component Object Model). Its DOM(Document Object Model) is the same when accessing it through either its own JavaScript engine or Python or any other scripting language it supports. The Photoshop DOM consists of a hierarchical representation of the Photoshop application, the documents used in it, and the components of the documents. The DOM allows you to programmatically access and manipulate the document and its components. For example, through the DOM, you can create a new document, add a layer to an existing document, or change the background color of a layer. Most of the functionality available through the Photoshop user interface is available through the DOM.

https://github.com/lohriialo/photoshop-scripting-python#but-why-pythonBut why Python?

Photoshop scripting officially supports JavaScript, AppleScript & VBScript. However, Scripting in Python is also fairly easy if not easier if you're already comfortable with Python. You may have already heard that Python is gaining in popularity, but did you know it’s now the most popular introductory programming language in U.S. universities? Python is also cross platform just like JavaScript is and lately becoming one of the fastest growing programming language according to StackOverflow as of September 2017

Python is easy to use, powerful, and versatile, making it a great choice for beginners and experts alike. Python’s readability makes it a great first programming language - it allows you to think like a programmer and not waste time understanding the mysterious syntax that other programming languages can require.

Getting Started

Python allows you to access COM and it's DOM with the help of a Python extensions like "pypiwin32" or "comtypes". Install these modules and you're ready to start scripting Photoshop in Python

  • pip install pypiwin32 or pip install comtypes
JJMack
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 14, 2019 Aug 14, 2019
LATEST

Thanks for your answers.

I couldn't do it with python library because all librairies doesn't support this feature so I managed to resolve my problem using:

- javascript file which import datasets (pass one parameter which is the csv file you want to use)

- a vbscript which open Photoshop and call the javascript file with parameter (path of your csv file)

- my python call the vbscript

 

It is not the best way to do it but it works

Hope it will help others

Guillaume

 

 

 

my .vbs file :

Set vbsArguments = WScript.Arguments

Set myPhotoshop = CreateObject("Photoshop.Application") 

javaScriptFile = "importDatasets.jsx" 

 

Call myPhotoshop.DoJavaScriptFile( javaScriptFile, Array(path), 1)

End If

 

here  the javascript file (importDatasets.jsx):

fileImportDataSets = function( file ) { 
    var desc = new ActionDescriptor(); 
        var ref = new ActionReference(); 
        ref.putClass( stringIDToTypeID( "dataSetClass" ) ); 
    desc.putReference( charIDToTypeID( "null" ), ref ); 
    desc.putPath( charIDToTypeID( "Usng" ), new File( file ) ); 
    desc.putEnumerated( charIDToTypeID( "Encd" ), stringIDToTypeID( "dataSetEncoding" ), stringIDToTypeID( "dataSetEncodingAuto" ) ); 
    desc.putBoolean( stringIDToTypeID( "eraseAll" ), true ); 
    desc.putBoolean( stringIDToTypeID( "useFirstColumn" ), true ); 
executeAction( stringIDToTypeID( "importDataSets" ), desc, DialogModes.NO ); 
}; 
function applyDataSet(setName){ 
    var desc = new ActionDescriptor(); 
        var setRef = new ActionReference(); 
        setRef.putName( stringIDToTypeID( "dataSetClass" ), setName ); 
    desc.putReference( charIDToTypeID( "null" ), setRef ); 
executeAction( charIDToTypeID( "Apply" ), desc, DialogModes.NO ); 
}; 
function getDataSetNames(csvFileRef) {  
    _ftn = function(string){  
    var csvItems = string.split(",");  
    datasetName = csvItems[0]        
    return datasetName;  
}; 
csvFileRef.open();  
var datasetArray = new Array();  
var i = 0;// assumes the dataSet name is the first field 
while (csvString = csvFileRef.readln()) {  
   if (csvString.length < 2) continue; // Skip empty lines  
  datasetArray[i] = _ftn(csvString);  
  i++;  
}  
csvFileRef.close();  
return datasetArray;  
}  
 
fileImportDataSets(arguments[0]);
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines