(JS) Duplicate a graphics frame?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
> 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
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Are you using just the parts behind the colon?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
> 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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
> 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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
> 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?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Looks like Dave beat me too it.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
> }
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
> 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?
Copy link to clipboard
Copied
myImage.transparencySettings.blendingSettings.blendMode = BlendMode.multiply;
Thank you Dave for pointing me in the right direction.
Randy
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Well done.
Dave
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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"
Copy link to clipboard
Copied
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");


-
- 1
- 2