Skip navigation
Currently Being Moderated

Object layer options script to improve...

Apr 13, 2012 12:08 PM

Hi guys, object layer options is a great idea, but some things drive me crazy

 

The process is very repetitive and I have to close and open at all times to repeat the process in another box image.

Is there a script that makes the object layer options more friendly?

 

Ex:

 

 

01 - Keep the 'Object layer options' always open

02 - Select a box image, change the layer, apply the "ok" without closing the 'Object layer options', do the same process in another box image,and so on like a palette.

 

 

Thank you guys,

 

 

JNS

 
Replies
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Apr 14, 2012 12:21 AM   in reply to JNSaraiva

    Scripts can't interact with dialog boxes.

    But they can perform the functions that you would use the dialog box to perform.

    So if your goal is to change object layer visiblity on a large number of images at once, then yes you can do that with a script.

     

    Please give a specific example of what you want to do.

     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Apr 15, 2012 10:55 AM   in reply to JNSaraiva

    That is not what I mean by a specific example. I want to hear something like: "I want to disable the Tree layer in all placed images on pages seven through twenty-one whose horizontal dimension is greater than 3 inches and less than 7 inches."

     

    As I said, scripts cannot interact with dialog boxes. They can control object attributes.

    You cannot force the dialog box to stay open while you edit. But you can do other things.

     

    Please give a specific example of your end goals. You can't accomplish them through the path you suggested, but you can probably accomplish them through another. But you'd need to tell us what they are.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 15, 2012 12:00 PM   in reply to JNSaraiva

    You could try to recreate the Layes Dialog with SciptUI and add the

    functions you want to that dialog. Not a trivial challenge, though.

     

    Ariel

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 25, 2013 12:30 AM   in reply to [Ariel]

    John, Im just looking for a script to help solve exactly what you gave as example!

    I have a lot of images that I have to place and all of them have exactly the same layers 1., 2., 3., 4. and the layer drawings. I want to place all of them but I want to disable all layers except the last one (drawings).

     

    Do you know how I can do it?

     

    Thanks in advance =)!

     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Sep 25, 2013 1:55 AM   in reply to MeurHen

    I seem to be running into some perverse problems in what should be a simple script. What ID version are you using?

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 25, 2013 2:05 AM   in reply to John Hawkinson

    Im using ID CS 5.5. I think that what you said before is really similar. I have a lot of images (all of them have the same layers name). I want to place them all with just the last layer turned on.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 25, 2013 2:35 AM   in reply to JNSaraiva
     
    |
    Mark as:
  • John Hawkinson
    5,572 posts
    Jun 25, 2009
    Currently Being Moderated
    Sep 25, 2013 3:06 AM   in reply to MeurHen

    MeurHen: I have a solution for you.

    (I did not have a prior script that solved this problem; I merely was indicating what was possible.)

     

    This turns out to be far more complicated than it should be, because InDesign has a rather severe bug with the handling of object layers in scripting. Specifically, if you either change the visibility of an object layer, or if you test the validity of an object layer (with .isValid), or maybe other things, InDesign gets confused about the current set of object layers and you can no longer safely refer to the object layers for any object you may have stored in a variable. In fact, when it gets confusd, it confuses layers with inks, like Process Magenta, etc. It appears this is a known bug for some time, though I don't know if anyone has reported it -- Jongware, do you know?

     

    The result is that the script that deals with this has to try up to N factorial times to set the layers on an object (that is, for a 5-layer object, it has to try up to 5*4*3*2*1 => 120 times) to handle the layer visibility. Though actually it probably only has to try 5 times, but it cannot know exaclty which 5.

     

    I tried to write this script in a way that was clear, but I am not sure that I succeeded.

     

    Here it is, tested against CS5.5:

     

     

    var i,
        doc=app.activeDocument; 
        
    for (i=0; i<doc.allGraphics.length; i++) {
      setLayers(i);
    }
     
    function setLayers(graphicIndex) {
        var success,
            tries, maxTries;
        // Every time we change the value of a layer's visibility,
        // the entire set of layer state for that object is reset.
        // Therefore, we have to try to set all N layers
        // up to N times, depending on their prior state.
        // This is a very annoying bug.
        maxTries = doc.allGraphics[graphicIndex].
          graphicLayerOptions.graphicLayers.count();
        for (tries = 0; tries <=maxTries ; tries++) {
            success = tryToSetLayers(doc.allGraphics[graphicIndex]);
            if (success) {
                    // Succeeded. All object layers are properly
                    // set. We are done.
                    return true;
            }
        }  
        // FAILURE! We tried N times and did not set all layers properly.
        // the bugs have defeated us.
        alert("Fatal error; inconsistent layer state");
        return false;
    }
     
     
    function tryToSetLayers(graphic) {
        var 
          j, layer, vizWanted,
          o=graphic.graphicLayerOptions,
          layers = o.graphicLayers.everyItem().getElements();
         for (j  = 0; j < layers.length; j++) {
            layer = layers[j];
            if (layer.name==="Drawings") {
                vizWanted = true;
            }
            else {
                vizWanted = false;
            } 
            if (layer.currentVisibility !== vizWanted) {
                    layer.currentVisibility=vizWanted;
                    // made a change,  All bets are off.
                    return false;       
            }
        }
        return true; // Success!
    }
    

     

    You may need to edit the portion of the script on line 40, if (layer.name==="Drawings") {, which tests the layer name.

    If you're having trouble figuring out what layer name to use, you can print out the layer names beforehand by adding a

    $.writeln(layer.name) on the previous line. Or something like that.


    This script operates on all graphic objects in the document. I guess it might fail if you have graphic objects that don't contain layers. Let me know if that's the case. I didn't test for that but should have.

     

    (Again, does anyone know if this bug has been reported?)

    Attachments:
     
    |
    Mark as:
  • Currently Being Moderated
    Sep 25, 2013 4:52 AM   in reply to John Hawkinson

    John, it worked perfectly =D!

    Thank you very much, man!

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points