<FLAME>Photoshop development</FLAME>

python
photoshop

#41

i worte a p4 thing as well, but i just used command line stuff. It only does the add/edit/revert stuff though.

hahaha, i wonder how much of our jobs would evaporate if we were able to share all of our tools


#42

The p4 thing was pasted in as an example, the real python stuff it hooks into is all of our Shotgun/SGTK calls, since they don’t have a working PS/AE integration currently.

I’m pretty sure I can release the groundwork for python communication, it’s something that’s been a headache for a long time- I’m not convinced python-shell is the way to go, I really wanted to get https://zerorpc.dotcloud.com/ working as the bridge but getting it compiled for both languages on windows was a bit of a nightmare.


#43

LOL, for real!


#44

anyone got an event listener for Photoshop to work that responds to active document changed?
I’m trying to print out the name of the active document to my panel as the user switches between images…


#45

This is what i’ve been using


var CS_API = new CSInterface();

var PhotoshopService = function() {
    var self = this;
    self.filename = '';
    self.files = false;

    function query (docs) {
        self.files = JSON.parse(docs);
        if (self.files) {
            getName();
        }
        else {
            self.filename = '';
        }
    }

    function getName() {
        CS_API.evalScript('app.activeDocument.fullName.fsName', function(filename) {
            self.filename = filename;
        });
    }

    // -- Photoshop callbacks
    CS_API.addEventListener("documentAfterActivate" , function(event) {
        CS_API.evalScript("(app.documents.length > 0)", query)
    });
}



#46

so “documentAfterActive” does indeed work in Photoshop? Everything I found online indicated that it only worked for a subset of Creative Cloud apps.
Thanks!


#47

I am not very good with javascript yet, so I am having a but of difficulty understanding your code.

I tried to make a simplified version but I get back “undefined” as the value instead of the document name.




function getActiveDocument(event) {
    var cs = new CSInterface();
    var docName = cs.evalScript("app.activeDocument.name"); // returns "undefined" ?
    window.document.getElementById( "currentDocument" ).innerHTML = docName;

I tried making a script to execute inside the Tool VM, and it gets the name of the doc, but I don’t know how to pass the value back to the Panel VM for display…?


// ps_script.jsx
function ps_getDocumentName() {
    var docName = app.activeDocument.name; // this has the correct name.
    return docName; // I get back "undefined" as the return value... ?
}


// main.js
function getActiveDocument(event) {
    var cs = new CSInterface();
    var docName = cs.evalScript("ps_getDocumentName()"); // returns "undefined" ?
    window.document.getElementById( "currentDocument" ).innerHTML = docName;
}



#48

cs.evalScript is async, so it takes a callback as a second arg to call when it’s finished:



// main.js
function getActiveDocument(event) {
    var cs = new CSInterface();
    var docName = cs.evalScript("ps_getDocumentName()", result);  // result will be called with the result from the jsx call
}

function result(docName) {
    window.document.getElementById( "currentDocument" ).innerHTML = docName;
}


Note that the argemant passed to the callback is always a string. So if you return the document.width, for example, you’d have to cast it to an int.


#49

Is it correct to say that regular js can only communicate with jsx through evalScript?


#50

[QUOTE=TheMaxx;27142]cs.evalScript is async, so it takes a callback as a second arg to call when it’s finished:



// main.js
function getActiveDocument(event) {
    var cs = new CSInterface();
    var docName = cs.evalScript("ps_getDocumentName()", result);  // result will be called with the result from the jsx call
}

function result(docName) {
    window.document.getElementById( "currentDocument" ).innerHTML = docName;
}


Note that the argemant passed to the callback is always a string. So if you return the document.width, for example, you’d have to cast it to an int.[/QUOTE]

awesome! thanks!


#51

i believe so, yes


#52

Awesome! So their UI solution is exactly equivalent to running eval! How… typical…


#53

Have you guys come across a method for adding your own items to the Panel’s drop-down menu (where Close Panel and Close Group are located)?


#54

// -- listen for event
CS_API.addEventListener("com.adobe.csxs.events.flyoutMenuClicked" , function(event) {
    // Check which item was clicked and do something
});


function addFlyoutMenu() {
    var menu = "<Menu><MenuItem Id=\"menuItemId1\" Label=\"TestExample1\" Enabled=\"true\" Checked=\"false\"/></Menu>";
    window.__adobe_cep__.invokeSync("setPanelFlyoutMenu", menu);
}


#55

sweet, thanks!


#56

what resource are you using to discover methods such as “invokeSync” or “com.adobe.csxs.events.flyoutMenuClicked”?


#57

i was looking at this

if you copy that into your extensions folder and open it up, it shows a lot of what can be done


#58

holy crap! that is awesome!
thanks!


#59

I am trying to get the full path to an open PS document in Windows format, but am running into issues getting the path back formatted correctly.

if I try “app.activeDocument.fullName” I get back “/d/temp/myPSD.psd” instead of “d:/temp/myPSD.psd”.

In JavaScript the “fullName” property of a “document” returns a File object (as opposed to the “name” property which just returns a string).

After looking at this documentation

I thought I might be able to just pass the return value from “fullName” into a new File Object and extract the file system-specific name with “.fsName” property, but I get an Illegal Constructor error.


function getFullName() {
    var cs = new CSInterface();
    var doc = cs.evalScript("app.activeDocument.fullName", updateName);
    
    function updateName(doc) { 
        var f = new File([doc.toString()]); // this line fails... can't create the File Object. Also tried new File([doc]).
        window.document.getElementById( "fullName" ).value = f.fsName;
    }
}

As a side note, calling fullName through VB and comTypes returns the path as string

Anyone know how to get the full path to a PSD in Windows File System Format?

SOLUTION:

I re-arranged the code a bit…

ps_scripts.jsx


function ps_getDocumentFullName() {
    doc = app.activeDocument.fullName;
    return doc.fsName; // full path formatted for the current file system.
}

#60

Document.fullName is a File object, so you can just use fsName on it directly