32 Replies Latest reply on Jun 19, 2009 2:19 PM by paulelvisjones

    (JS) Duplicate a graphics frame?

    Really Randy Level 1
      I'm trying to duplicate a selected tif graphic, and apply the embedded clipping path as well as an object style to the duplicated image while leaving the original alone.

      After reading a lot of help files I git as far as figuring out how to duplicate a selected text frame.

      if (app.selection[0].constructor.name == "TextFrame"){
      myFrame = app.selection[0];
      myDupeFrame = myFrame.duplicate();
      }

      If I change the "TextFrame" to "Objectframe" or "GraphicFrame" or "ImageFrame" it doesn't work. Is there a place where I can find out what things are called?

      Thanks,
      Randy
        • 1. Re: (JS) Duplicate a graphics frame?
          Martin Fischer Level 2
          Hi Randy,

          > is there a place where I can find out what things are called?

          The easiest way to find out what things that can be selected are called is to let ESTK ask for it:

          1. output console: $.writeln( app.selection[0].constructor.name )
          2. output dialog: alert( app.selection[0].constructor.name )

          Now, how is the thing called, a graphic is in?

          Martin
          • 2. Re: (JS) Duplicate a graphics frame?
            Really Randy Level 1
            I don't understand. Both of these commands return an error.
            • 3. Re: (JS) Duplicate a graphics frame?
              Larry G. Schneider Adobe Community Professional & MVP
              Randy,

              Are you using just the parts behind the colon?
              • 4. Re: (JS) Duplicate a graphics frame?
                Level 1
                Hi Randy,

                I have to disagree with Martin (a little--thanks for helping, Martin!): The easiest way to find out what things are called is to use the object model viewer in the ExtendScript Toolkit, or to look at another view of the same data, such as the excellent HTML version provided by jongware (search the forum for details).

                You haven't said which version of the ExtendScript Toolkit (and/or InDesign) you're using, and the way you do these things depends on which version you have. Let us know a bit more, and we'll be able to help.

                Thanks,

                Ole
                • 5. Re: (JS) Duplicate a graphics frame?
                  Martin Fischer Level 2
                  Hi Ole,

                  I agree with you (a little). ;-)

                  But if you have an object and you don't know it's name ( e.g. a graphic frame) how do you know whereupon you should look for in the object model?

                  If you know the name of an object the object model viewer in the ESTK can lead you on. But if you don't know an objects name, you might have to scroll thru every object and check it's name whether the name will match the object.

                  This has been why I have recommend to ask the console for the objects name before climbing thru the object model.

                  Thanks
                  Martin
                  • 6. Re: (JS) Duplicate a graphics frame?
                    Really Randy Level 1
                    OK, I got the item name figured out. I just ran "app.selection[ 0]" with the object selected and it returned "Rectangle", Doh!

                    Now the dupe part of it works:

                    if (app.selection[0].constructor.name == "Rectangle"){
                    myFrame = app.selection[0];
                    myDupeFrame = myFrame.duplicate();
                    }

                    So now I need to make sure that the original graphic is set to the "VehicleMultiply" object style and the new duplicated graphic is et to "vehicleClipPath" object style with the clipping path named "Clip Path w/shadow" selected in the clipping path dialog.

                    So now the duped frame is already named "myDupeFrame" right?
                    So I just need to learn how to apply the object style and clipping path.

                    Randy
                    • 7. Re: (JS) Duplicate a graphics frame?
                      Really Randy Level 1
                      I find out that I need to first define a variable for the contents (image) of my selected frame. Can't figure out how select the contents of myFrame if it's an image.
                      • 8. Re: (JS) Duplicate a graphics frame?
                        Martin Fischer Level 2
                        Hi Randy,

                        if you want to do something with an image of a rectangle (e.g. read it's properties), you need to address the first image of it like this:

                        var myImage = myFrame.images[0];


                        Martin
                        • 9. Re: (JS) Duplicate a graphics frame?
                          Harbs. Level 6
                          Martin Fischer wrote:
                          > But if you have an object and you don't know it's name ( e.g. a graphic frame) how do you know whereupon you should look for in the object model?
                          >
                          Well, if you look under PageItem, you'll see that your choices are:
                          rectangles, ellipses, graphic lines, polygons, groups, text frames, and
                          buttons...

                          So, a graphics frame would have to be either a rectangle, ellipses,
                          polygon, or button.

                          --
                          Harbs
                          http://www.in-tools.com
                          • 10. Re: (JS) Duplicate a graphics frame?
                            Martin Fischer Level 2
                            Hi Harps,

                            > Well, if you look under PageItem, you'll see that your choices are:

                            Well, if you know, that a selected rectangle is called a page item, you can figure out that.
                            So you are right.

                            But if you are a beginner and you see one tree after the other and cannot see the forest because of so many trees... maybe you even don't know that there are things called page item that are rectangles, ovals, graphic lines and so on.

                            Goud luck if you know the names of things.
                            But what if you don't know them?
                            How to find out?
                            I just can remember the time that I have spent stumbeling thru the DOM.

                            You may call me a nitpicker now.
                            And you may be right in this case too.

                            But sometimes things go faster asking a selected thing tru the console.

                            Martin
                            • 11. Re: (JS) Duplicate a graphics frame?
                              [Jongware] Most Valuable Participant
                              Try the latest incarnation of my HTML conversion of the JS help file (for CS3 only -- for now!).

                              By carefully examining the descriptions of object properties, I am able to display object hierarchies in an easy-to-follow block diagram. A tad experimental, because the descriptions are all I got to work with, but it seems reliable for at least the most important objects.

                              The latest version can be downloaded from my very own website.
                              • 12. Re: (JS) Duplicate a graphics frame?
                                Really Randy Level 1
                                Ok, I've gotten a lot further with it but now there's one line I'm really stuck on. Line 3 below:

                                > if (app.selection[0].constructor.name == "Rectangle"){

                                > myFrame = app.selection[0];

                                > myFrame.ContentTransparencySetting.blendingSettings.BlendMode = 2020625762;

                                > var myImage = myFrame.images[0];

                                > myImage.clippingPath.appliedPathName = ("Clip Path w/shadow")

                                > myDupeFrame = myFrame.duplicate();

                                > }

                                I'm trying to set the blend mode of the image to multiply and I keep getting a "Object does not support the property or method "ContentTransparencySetting"
                                Is there an easy way to do this?
                                • 13. Re: (JS) Duplicate a graphics frame?
                                  Level 1
                                  Which version of InDesign are you using? Transparency changed dramatically from CS2 to CS3. Looks like CS3.

                                  The first problem I see with that line is that property names never start with a capital letter. You've done it twice in that one line.

                                  It's also better to use the named version of the enumeration because then you can read what it means.

                                  myFrame.contentTransparencySettings.blendingSettings.blendMode = BlendMode.multiply;

                                  Dave
                                  • 14. Re: (JS) Duplicate a graphics frame?
                                    Larry G. Schneider Adobe Community Professional & MVP
                                    Did you try using contentTransparencySetting as is shown in jongware's excellent reference?

                                    Looks like Dave beat me too it.
                                    • 15. Re: (JS) Duplicate a graphics frame?
                                      Level 1
                                      Read it like this: blendMode is the property name of the BlendingSetting object which is referenced by the blendingSettings property of the ContentTransparencySetting object which is referenced by the contentTransparencySettings property of the rectangle myFrame.

                                      In two cases there, the property name is plural while the object name is singular, in addition to the capitalization differences.

                                      Then, the BlendMode object (which, in this case is an enumeration object) has a bunch of named properties. The OMV uses the all-caps versions of the names, but I prefer the lowercase. The rule is, where the all-caps version has an internal "_", lose the underline and retain the next letter as uppercase; otherwise convert all the letters to lowercase. In this instance, we are using a single word property, "multiply" so there are no uppercase letters.

                                      Dave
                                      • 16. Re: (JS) Duplicate a graphics frame?
                                        Really Randy Level 1
                                        Thank you again, Dave.

                                        That helps me understand it a bit better.
                                        I think I'm still doing a little something wrong here though. When I use the following, nothing happens but when I comment out line 4 the clipping path is applied correctly. It seems that line 4 stops the script so line 5 never happens.

                                        > if (app.selection[0].constructor.name == "Rectangle"){

                                        > var myFrame = app.selection[0];

                                        > var myImage = myFrame.images[0];

                                        > myFrame.contentTransparencySettings.blendingSettings.blendMode = BlendMode.multiply;

                                        > myImage.clippingPath.appliedPathName = ("Clip Path w/shadow");

                                        > // myDupeFrame = myFrame.duplicate(); //duplicate selected frame

                                        > }
                                        • 17. Re: (JS) Duplicate a graphics frame?
                                          Level 1
                                          Does the blend mode change to multiply?

                                          When I'm not sure what's happening in a script, I'll insert:

                                          alert("Got here")

                                          in a few places.

                                          Does what you're trying to do work properly if you do it manually in the UI?

                                          Dave
                                          • 18. Re: (JS) Duplicate a graphics frame?
                                            Really Randy Level 1
                                            Here's what I'm using now:

                                            > if (app.selection[0].constructor.name == "Rectangle"){

                                            > myFrame = app.selection[0];//selected image frame

                                            > var myImage = myFrame.images[0]; //set variable for image within selected frame

                                            > myFrame.contentTransparencySettings.blendingSettings.blendMode =
                                            BlendMode.multiply;

                                            > myImage.clippingPath.appliedPathName = ("Clip Path w/shadow"); // apply clipping path

                                            > }

                                            the clip path is applied but the mode is not set to "multiply" so it makes it past line 4. I can set the mode to multiply in the UI. Maybe I need to set the blending mode for "myImage" instead of "myFrame". I never officially set a variable for "myImage" on line 2. Is that a problem?
                                            • 19. Re: (JS) Duplicate a graphics frame?
                                              Really Randy Level 1
                                              Got it!

                                              myImage.transparencySettings.blendingSettings.blendMode = BlendMode.multiply;

                                              Thank you Dave for pointing me in the right direction.

                                              Randy
                                              • 20. Re: (JS) Duplicate a graphics frame?
                                                Level 1
                                                What you need is:

                                                myFrame.transparencySettings.blendingSettings.blendMode = BlendMode.multiply;

                                                The image inherits this setting. Although you could also use:

                                                myImage.transparencySettings.blendingSettings.blendMode = BlendMode.multiply;

                                                I'm not sure where the content variant of the transparency settings apply. Perhaps they work on items pasted into a rectangle. The fill and stroke variants are obvious.

                                                Dave

                                                PS: I've not done much of this stuff myself, so I always have to noodle it out the hard way.
                                                • 21. Re: (JS) Duplicate a graphics frame?
                                                  Level 1
                                                  Ah you beat me to it.

                                                  Well done.

                                                  Dave
                                                  • 22. Re: (JS) Duplicate a graphics frame?
                                                    paulelvisjones

                                                    Hello

                                                     

                                                    I am brand new to scripting and therefore I am scripting muppet!

                                                     

                                                    I want to do something similar to this but my pathetic attempts at hacking away at the code here are going nowhere.

                                                     

                                                    I basically want to:

                                                    1. apply a photoshop path to a selected image (there would only ever be one path but the name could be anything)

                                                    2. Duplicate the image (I can do this bit)

                                                    3. "convert clipping path to frame" on the selected frame

                                                    4. remove the image but retain the frame

                                                    5. put a 2mm text wrap on the object shape

                                                    • 23. Re: (JS) Duplicate a graphics frame?
                                                      paulelvisjones Level 1

                                                      Sent it before I finished typing! Scripting, I can't even use the bloody internet today!

                                                       

                                                      If anyone can help on any of these steps I'd really appreciate it

                                                       

                                                      cheers

                                                       

                                                      Paul "scripting muppet"

                                                      • 24. Re: (JS) Duplicate a graphics frame?
                                                        Kasyan Servetsky Level 5

                                                        if (app.selection.length != 1 || app.selection[0].images.length != 1) {
                                                            alert("One frame with an image should be selected");
                                                            exit();
                                                        }
                                                        var mySel = app.selection[0];
                                                        var myImage = mySel.images[0];
                                                        var myClippingPathSettings = myImage.clippingPath;
                                                        myClippingPathSettings.clippingType = ClippingPathType.PHOTOSHOP_PATH;
                                                        var myDuplicate = mySel.duplicate();
                                                        var myNewFrame = myDuplicate.images[0].clippingPath.convertToFrame();
                                                        myNewFrame.images[0].remove();
                                                        var myTextWrapPreferences = myNewFrame.textWrapPreferences;
                                                        myTextWrapPreferences.textWrapType = TextWrapTypes.CONTOUR;
                                                        myTextWrapPreferences.textWrapOffset = "2 mm";
                                                        myNewFrame.select();
                                                        alert("Done");

                                                        • 25. Re: (JS) Duplicate a graphics frame?
                                                          paulelvisjones Level 1

                                                          Thanks very much Kasyan that's great, it doesn't seem to selecting the photoshop clipping path though.

                                                           

                                                          If I select the path manually, comment out //myClippingPathSettings.clippingType = ClippingPathType.PHOTOSHOP_PATH; and then run the script it does all the other bits brilliantly

                                                           

                                                          Any ideas?

                                                           

                                                          Thanks again

                                                           

                                                          Paul

                                                          • 26. Re: (JS) Duplicate a graphics frame?
                                                            Kasyan Servetsky Level 5

                                                            I made this script for CS3 -- you didn't mention that you need it for CS2 at first. I'll try to check it in CS2, if I have time, but don't promise.

                                                            • 27. Re: (JS) Duplicate a graphics frame?
                                                              paulelvisjones Level 1

                                                              No problem, thanks for your time, its much appreciated

                                                              • 28. Re: (JS) Duplicate a graphics frame?
                                                                paulelvisjones Level 1

                                                                Just looking at this some more and it seems that it has chosen the path, but not actually applied it (very strange), so if you go into clipping paths and click the preview button off and then on again it will work.

                                                                • 29. Re: (JS) Duplicate a graphics frame?
                                                                  Kasyan Servetsky Level 5

                                                                  I now remember that InDesign CS2's scripting is broken with respect to clipping paths. I found a workaround back in CS2 days, but it was so long ago that I can't recollect how I did it. Another problem is that the only copy of CS2 I have in my disposal is broken: I can't debug scripts in ESTK, I am able only to run them.

                                                                  • 30. Re: (JS) Duplicate a graphics frame?
                                                                    paulelvisjones Level 1

                                                                    I wonder if a tiny inset frame measurement (0.01mm) would force it to apply?

                                                                    • 31. Re: (JS) Duplicate a graphics frame?
                                                                      Kasyan Servetsky Level 5

                                                                      No, I tried and it didn't help. Time to upgrade!

                                                                      • 32. Re: (JS) Duplicate a graphics frame?
                                                                        paulelvisjones Level 1

                                                                        Can't do that unfortunately.

                                                                         

                                                                        Thanks very much for you help on this, maybe I'll find some bodge to make it work.

                                                                         

                                                                        cheers