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

How do I select layers by name in Visual Basic?

New Here ,
Feb 07, 2017 Feb 07, 2017

Copy link to clipboard

Copied

So I'm aware of java's

itemByName(String);

but eh,,,

Unfortunately I started the project with VB in Visual studio

so I feel compelled to end it in VB

Basically I'm asking for a vb function that finds a layer by name

Here's the code if it helps.

(Syntax highlighting isn't a thing for VB in this forum apparently)

Imports Photoshop

Public Class MapGen

    Dim PhotoshopApp As Application

    Dim PhotoshopDoc As Document

    Dim CurrentState As ArtLayer

    Private Sub StartBtn_Click(sender As Object, e As EventArgs) Handles StartBtn.Click

        PhotoshopApp = New ApplicationClass

        Dim X As String = "no val"

        Dim Y As Long = 0

        Dim FileReader = My.Computer.FileSystem.OpenTextFileReader("F:\Processed.txt")

        FileDialog.ShowDialog()

        For Each Line In My.Computer.FileSystem.ReadAllText("F:\Processed.txt")

            X = FileReader.ReadLine()

            If X = Nothing Then

            Else

                MsgBox(X)

            End If

        Next

        PhotoshopDoc = PhotoshopApp.Open(FileDialog.FileName)

        PhotoshopDoc.Layers.Item()

    End Sub

End Class

TOPICS
Actions and scripting

Views

997

Translate

Translate

Report

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

correct answers 1 Correct answer

Enthusiast , Feb 08, 2017 Feb 08, 2017

Did you try script listener plugin? It generates code for almost anything you do in JS na VB. Then you can simply copy part of recorded code.

DIM objApp

SET objApp = CreateObject("Photoshop.Application")

REM Use dialog mode 3 for show no dialogs

DIM dialogMode

dialogMode = 3

DIM idslct

idslct = objApp.CharIDToTypeID( "slct" )

    DIM desc16

    SET desc16 = CreateObject( "Photoshop.ActionDescriptor" )

    DIM idnull

    idnull = objApp.CharIDToTypeID( "null" )

        DIM ref12

        SET ref12 = CreateObje

...

Votes

Translate

Translate
Adobe
Enthusiast ,
Feb 08, 2017 Feb 08, 2017

Copy link to clipboard

Copied

LATEST

Did you try script listener plugin? It generates code for almost anything you do in JS na VB. Then you can simply copy part of recorded code.

DIM objApp

SET objApp = CreateObject("Photoshop.Application")

REM Use dialog mode 3 for show no dialogs

DIM dialogMode

dialogMode = 3

DIM idslct

idslct = objApp.CharIDToTypeID( "slct" )

    DIM desc16

    SET desc16 = CreateObject( "Photoshop.ActionDescriptor" )

    DIM idnull

    idnull = objApp.CharIDToTypeID( "null" )

        DIM ref12

        SET ref12 = CreateObject( "Photoshop.ActionReference" )

        DIM idLyr

        idLyr = objApp.CharIDToTypeID( "Lyr " )

        Call ref12.PutName( idLyr, "Layer 4" )

    Call desc16.PutReference( idnull, ref12 )

    DIM idMkVs

    idMkVs = objApp.CharIDToTypeID( "MkVs" )

    Call desc16.PutBoolean( idMkVs, False )

    DIM idLyrI

    idLyrI = objApp.CharIDToTypeID( "LyrI" )

        DIM list8

        SET list8 = CreateObject( "Photoshop.ActionList" )

        Call list8.PutInteger( 5 )

    Call desc16.PutList( idLyrI, list8 )

Call objApp.ExecuteAction( idslct, desc16, dialogMode )

Row 16 is layer name.

This should select layer by name. Anyway if you will have two layers with same name it may not work as you want.

I also recomend transition to JavaScript in your next projects 🙂

Votes

Translate

Translate

Report

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