PsDotNet - Photoshop C# library

Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General

Moderators: xbytor, Kukurykus, Tom

Posts: 1
Joined: Fri Dec 22, 2017 2:15 pm
Location: VietNam

Re: PsDotNet - Photoshop C# library

Post by polyxgo »

Hi davidwright ,
Nice to meet you here!
I'm use your PsDotNet.dll everything OK with my application but have only one problem with my when call function .Close().
This function working ok with Photoshop CS6... but throw a exception with CC2017, CC2018.
My application need to close all documents and layers after processed done! So, this function is very important for performance!

Your can help check this exception below? Thanks you so much and this library is awesome when interact to Photoshop

************** Exception Text **************
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException: General Photoshop error occurred. This functionality may not be available in this version of Photoshop.
- The object "document 0" is not currently available.
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Photoshop.Document.get_id()
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
at PsDotNet.Base.Extensions.GetHashCodeOrId(Document document)
at PsDotNet.Base.PsDocument.GetHashCode()
at PsDotNet.Base.Collections.PsDocuments.get_NeedsRefresh()
at PsDotNet.Base.PsApplication.get_Documents()
at PsDotNet.Base.PsApplication.Open(String filePath, Boolean asSmartObject, Object asType)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Posts: 4
Joined: Fri Jan 13, 2017 7:56 am

Re: PsDotNet - Photoshop C# library

Post by davidwright »

Hey Polyxgo,
Please try the solution I posted in Slack workspace.

**Information on how to join PsDotNet Slack can be found on the website.

Posts: 1
Joined: Mon Apr 30, 2018 1:28 pm

Re: PsDotNet - Photoshop C# library

Post by sandy154 »

i need to convert .psd file to png using photoshop.dll in .net platform but without opening photoshop image textlayer is not updating.below is the code.
string adobejavascriptfilepath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Scripts\\AdobeScript.jsx");
dynamic app = Activator.CreateInstance(Type.GetTypeFromProgID("Photoshop.Application"));
here photoshop is opening.
is there an way i can perform the task without opening the photoshop.

Posts: 1
Joined: Tue Apr 16, 2019 6:57 am
Location: Loveland

Re: PsDotNet - Photoshop C# library

Post by robertsmith19 »

Thank you so much for your interesting topic - here is a helpful resource that can help everyone- photography & Photo editing tips

Posts: 5
Joined: Thu Jan 24, 2019 8:18 pm

Re: PsDotNet - Photoshop C# library

Post by Geoff »


Photoshop must be opened but it need not be visible, you can use :-
app.Visible = false;

You will still see the splash screen though.
Make sure you close Photoshop on make it Visible again.