Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Layer Naming & Add Layer with box script wish

Return to Member Forum

  • Author
    Posts
    • #88239
      suzerp
      Member

      If anyone has the skill and the time, I have a wish list script to take a routine task and make it automatic –

      I’d like to be able to create any size InDesign document, and have a script to run that would:

      1. Change the Layer 1’s name to “art”
      2. Add a layer above the default layer and name it “die line” Bonus points if that layer color could be red in the panel window
      3. Draw a 1 pt. Box the size of the document and color it a spot color called “die line” which already exists in my swatch panel (or you can make it be your any color of green as long as it’s a spot color and not process)

    • #88240
      Peter Kahrel
      Participant

      Here you go:

      try {
        app.documents[0].layers.item('Layer 1').name = 'art';
      
        app.documents[0].layers.add ({name: 'die line', layerColor: UIColors.RED}).move(LocationOptions.AT_BEGINNING);
      
        app.documents[0].pages[0].rectangles.add (
          app.documents[0].layers.item('die line'), {
            name: 'die line', // More bonus points! (The box is easy to identify in the layers panel)
            geometricBounds: app.documents[0].pages[0].bounds, 
            strokeWeight: '1 pt',
            fillColor: 'die line'
          }
        );
      } catch (e) {
        alert (e);
      }

      Now, what would all those bonus points give me. . .

      Peter

    • #88245
      suzerp
      Member

      Well, all those bonus points get you …

      Another request! Because I forgot to ask for it in the first place.

      I need it stroke weight to be 1 pt. die line. (which you got). But I need the fill to be Paper. The die line just shows the edges of the sheet and the artwork is on that art layer and it needs to show through.

      And I really did try to fix it on my own, but if I touch that line, I can get nothing but an error. If I take that line out, and make sure my default colors are set up as no stroke and no fill, then the script works, but if it isn’t hard, can you show me how to resolve this?

    • #88250
      Peter Kahrel
      Participant

      I didn’t have many illusions about those bonus points :)

      try {
        app.documents[0].layers.item('Layer 1').name = 'art';
      
        app.documents[0].layers.add ({name: 'die line', layerColor: UIColors.RED}).move(LocationOptions.AT_BEGINNING);
      
        app.documents[0].pages[0].rectangles.add (
          app.documents[0].layers.item('die line'), {
            name: 'die line',
            geometricBounds: app.documents[0].pages[0].bounds, 
            strokeWeight: '1 pt',
            strokeColor: 'die line',
            fillColor: 'Paper'
          }
        );
      } catch (e) {
        alert (e);
      }

      P.

    • #88311
      suzerp
      Member

      Thank you so much!

      I had tried to make it work but I think my spacing was off in that fillColor line which was causing the error. Among the many skills I am missing regarding script generation is a big one – patience.

      Sorry I didn’t have any good prizes to share :)

    • #88336
      suzerp
      Member

      Oh boy are you going to be proud of me!

      So it turns out when I said I wanted the fill to be “Paper” I meant “None”.

      But I didn’t have to bug you to fix it this time.

      I had tried to make this change last time, but when I did it, I got an error. What you sent me looked exactly like what I had done, but since yours worked I just took it, shrugged my shoulders and moved on.

      But this time when I got the error, I found it! When I was typing the color name, the single quote mark in front of the color was changing in my text editor to a smart quote. And that was throwing the whole thing off.

      But now that I know the secret, I can make this script fill the box with any color I want.

      Thanks again.

    • #14323191

      I’m very new to scripting and have spent half the day teaching myself and trying to find the parts to build a simple script.
      This is the closest I’ve found to a solution, but it’s not quite what I need.

      I’m attempting to write a script that will change the color of my InDesign layers based on the layer name. “Art” = Red, etc.
      This and similar scripts makes it very easy to do this with new layers.

      I’ve also found a script that will search for particular layers, and if they do not exist in the document, will add them, and set them to a particular color. If the specified layers already exist in the document, it will ignore it and go on to the next layer.

      So I need to find an existing layer and change its color. Seems like it should be easy. Is it?

      What I’ve been trying to do is take this line:

      app.documents[0].layers.add ({name: ‘die line’, layerColor: UIColors.RED}).move(LocationOptions.AT_BEGINNING);

      and use the relevant bits of code on an existing layer. Can I replace the “.add” with something else to achieve this?

    • #14323190
      Jeremy Howard
      Participant

      Hey Nathan,

      Good on you for being so diligent that you found your way all the way back to a post from 2016!

      Here is the string you are looking for:
      app.activeDocument.layers.item(“Art”).layerColor = [255,0,0];

      Notice the [255,0,0] instead of “RED”. This is because the layer colors need to be specified in RGB values when changing them on an existing layer.

      Hope this helps!

Viewing 7 reply threads
  • You must be logged in to reply to this topic.
Forum Ads