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

(JS) Duplicate a graphics frame?

New Here ,
Oct 24, 2008 Oct 24, 2008
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
TOPICS
Scripting
4.3K
Translate
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
Contributor ,
Oct 24, 2008 Oct 24, 2008
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
Translate
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
New Here ,
Oct 24, 2008 Oct 24, 2008
I don't understand. Both of these commands return an error.
Translate
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
Community Expert ,
Oct 24, 2008 Oct 24, 2008
Randy,

Are you using just the parts behind the colon?
Translate
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
Explorer ,
Oct 24, 2008 Oct 24, 2008
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
Translate
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
Contributor ,
Oct 24, 2008 Oct 24, 2008
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
Translate
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
LEGEND ,
Oct 25, 2008 Oct 25, 2008
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
Translate
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
New Here ,
Oct 24, 2008 Oct 24, 2008
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
Translate
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
New Here ,
Oct 24, 2008 Oct 24, 2008
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.
Translate
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
Contributor ,
Oct 25, 2008 Oct 25, 2008
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
Translate
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
Contributor ,
Oct 26, 2008 Oct 26, 2008
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
Translate
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
Community Expert ,
Oct 26, 2008 Oct 26, 2008
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.
Translate
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
New Here ,
Nov 03, 2008 Nov 03, 2008
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?
Translate
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
Participant ,
Nov 03, 2008 Nov 03, 2008
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
Translate
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
Community Expert ,
Nov 03, 2008 Nov 03, 2008
Did you try using contentTransparencySetting as is shown in jongware's excellent reference?

Looks like Dave beat me too it.
Translate
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
Participant ,
Nov 03, 2008 Nov 03, 2008
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
Translate
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
New Here ,
Nov 03, 2008 Nov 03, 2008
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

> }
Translate
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
Participant ,
Nov 03, 2008 Nov 03, 2008
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
Translate
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
New Here ,
Nov 03, 2008 Nov 03, 2008
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?
Translate
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
New Here ,
Nov 03, 2008 Nov 03, 2008
Got it!

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

Thank you Dave for pointing me in the right direction.

Randy
Translate
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
Participant ,
Nov 03, 2008 Nov 03, 2008
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.
Translate
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
Participant ,
Nov 03, 2008 Nov 03, 2008
Ah you beat me to it.

Well done.

Dave
Translate
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
New Here ,
Jun 19, 2009 Jun 19, 2009

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

Translate
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
New Here ,
Jun 19, 2009 Jun 19, 2009

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"

Translate
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
Guru ,
Jun 19, 2009 Jun 19, 2009

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");

Translate
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