Skip to main content
angadarora
Participant
January 14, 2019
Answered

C# Simple Select/Get Layer by Name

  • January 14, 2019
  • 1 reply
  • 2834 views

Hi i just want to select a layer using its name, it is possible using JS, VBA but i am unable to find a similar solution for Visual basic C#.

Also if possible where can i find a full list of Methods and functions available in C# object library like this com.adobe.photoshop.ArtLayer

using System;

using System.Runtime.InteropServices;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using MintCorePS;

using ps = Photoshop;

using K = PhotoshopTypeLibrary.PSConstants;

namespace Core

{

    class Program

    {

        static void Main(string[] args)

        {

            //Initiate Photoshop

            ps.ApplicationClass App = new ps.ApplicationClass();

            ps.ActionDescriptorClass AppAction = new ps.ActionDescriptorClass();

            var Layer = App.ActiveDocument.ArtLayers.getLayerByName("Core");

        }

    }

}

Thank you in advance.

This topic has been closed for replies.
Correct answer SuperMerlin

using System;

namespace PhotoshopTest

{

    class Program

    {

        static void Main(string[] args)

        {

            dynamic app = Activator.CreateInstance(Type.GetTypeFromProgID("Photoshop.Application"));

            app.Visible = true;

            app.ActiveDocument.ActiveLayer = app.ActiveDocument.ArtLayers.GetByName("Core");

        }

    }

}

1 reply

SuperMerlin
SuperMerlinCorrect answer
Inspiring
January 14, 2019

using System;

namespace PhotoshopTest

{

    class Program

    {

        static void Main(string[] args)

        {

            dynamic app = Activator.CreateInstance(Type.GetTypeFromProgID("Photoshop.Application"));

            app.Visible = true;

            app.ActiveDocument.ActiveLayer = app.ActiveDocument.ArtLayers.GetByName("Core");

        }

    }

}

angadarora
Participant
January 14, 2019

Thank you. It seems to work your way, but if possible can you tell me the difference in our approaches i mean why isnt GetByName available the way i am doing it?

SuperMerlin
Inspiring
January 14, 2019

You were using "getLayerByName" this does not exist.

My version is using "Late Binding" so in this form uses the newest version of Photoshop installed and no need for interop. Commands in this form are near enough the same as used in ExtendScript (Except for the uppercase)

Kukurykus​ This is just C# language using Late Binding.