Copy link to clipboard
Copied
Hello!
I open Photoshop in my C# coded software as:
dynamic app = Activator.CreateInstance(Type.GetTypeFromProgID("Photoshop.Application"));
app.open(file);
.
...
app.ActiveDocument.Close(2);
As you can see I am able to close active documents/images in C#
But...
How to close/shutdown Photoshop application instance (I mean from C# code)?
Regards
Marcin
app.quit();
Copy link to clipboard
Copied
app.quit();
Copy link to clipboard
Copied
Yes, it has worked but after quiting Photoshop I got error message:
System.Runtime.InteropServices.COMException (0x800706BE): Utworzenie wystąpienia składnika modelu COM o identyfikatorze CLSID {...........................................} z elementu IClassFactory nie powiodło się z powodu następującego błędu: 800706be Zdalne wywołanie procedury nie powiodło się. (Wyjątek od HRESULT: 0x800706BE).
so it means (I translated it by myself):
.....(0x800706BE). Creating element of COM model with ID CLSID {.....} with IClassFactory failed because of the error: 800706be. Remote procedure call failed (Exception HRESULT 0x800706BE)
Can you advice something how to avoid error on quitting Photoshop?
Copy link to clipboard
Copied
I know what happened.
I tried to open Photoshop after just closed Photoshop.
I added only one closing/quit of Photoshop in my code and the error didn`t occur anymore while app.quit().
So it works.
Copy link to clipboard
Copied
What is "Activator"? 🙂
Copy link to clipboard
Copied
It's the method used to get information about Photoshop in "Late Binding" (Uses the newest version of Photoshop installed)
I.E.
dynamic app = Activator.CreateInstance(Type.GetTypeFromProgID("Photoshop.Application"));
dynamic ad = Activator.CreateInstance(Type.GetTypeFromProgID("Photoshop.ActionDescriptor"));
dynamic ar = Activator.CreateInstance(Type.GetTypeFromProgID("Photoshop.ActionReference"));
dynamic list9 = Activator.CreateInstance(Type.GetTypeFromProgID("Photoshop.ActionList"));
dynamic black = Activator.CreateInstance(Type.GetTypeFromProgID("Photoshop.SolidColor"));
dynamic jpgOpts = Activator.CreateInstance(Type.GetTypeFromProgID("Photoshop.JPEGSaveOptions"));
etc.
Copy link to clipboard
Copied
Does this have some documentation? (from Adobe not Microsoft)
Does this work on MacOS?
Copy link to clipboard
Copied
I haven't found any documentation at all. The only info I found was via Google for "Late Binding". That and just experimenting.
I am Windows only here so not sure if there is the same methods for a Mac using C#
Copy link to clipboard
Copied
Can you call things not available in ExtendScript with this?
Copy link to clipboard
Copied
Yes you can use action manager, here is one example.
var layerInfo = getNamesPlusIDs(app);
for (int x = 0; x < layerInfo.Count; x++)
{
Console.WriteLine(
"Layer name = " + layerInfo
.Item1 + " Index = " + layerInfo
.Item2 + " Layer ID = " + layerInfo
.Item3 + " Is Layerset = " + layerInfo
.Item4 );
}
Console.ReadLine();
/////////////////////////////////////////////////////
/// <summary>
/// Returns a Tuple:- LayerName,Index,Layer ID,is LayerSet
/// </summary>
/// <param name="app"></param>
/// <returns></returns>
static List<Tuple<string, int, int, bool>> getNamesPlusIDs(dynamic app)
{
int z = 0;
List<Tuple<string, int, int, bool>> Dat = new List<Tuple<string, int, int, bool>>();
dynamic ref1 = Activator.CreateInstance(Type.GetTypeFromProgID("Photoshop.ActionReference"));
ref1.PutProperty(app.CharIDToTypeID("Prpr"), app.CharIDToTypeID("NmbL"));
ref1.PutEnumerated(app.CharIDToTypeID("Dcmn"), app.CharIDToTypeID("Ordn"), app.CharIDToTypeID("Trgt"));
int count = app.ExecuteActionGet(ref1).getInteger(app.CharIDToTypeID("NmbL")) + 1;
if (app.ActiveDocument.Layers[app.ActiveDocument.Layers.Count].isBackgroundLayer)
{
z = 0;
}
else {
z = 1;
}
for (int i = z; i < count; i++)
{
if (i == 0) continue;
dynamic ref2 = Activator.CreateInstance(Type.GetTypeFromProgID("Photoshop.ActionReference"));
ref2.PutIndex(app.CharIDToTypeID("Lyr "), i);
var desc = app.ExecuteActionGet(ref2);
string layerName = desc.getString(app.CharIDToTypeID("Nm "));
int ID = desc.getInteger(app.StringIDToTypeID("layerID"));
Match m = Regex.Match(layerName, "Layer group");
if (m.Success) continue;
string layerType = app.TypeIDToStringID(desc.GetEnumerationValue(app.StringIDToTypeID("layerSection")));
bool isLayerSet = (layerType == "layerSectionContent") ? false : true;
Dat.Add(new Tuple<string, int, int, bool>(layerName, i, ID, isLayerSet));
}
return Dat;
}
Copy link to clipboard
Copied
I know, but I am interested in things which you can't do with action manager, DOM or scripting.
Copy link to clipboard
Copied
Not with Photoshop, but you can comunicate with other applications within the same program.