Skip to main content
Known Participant
February 26, 2010
Question

move page item into a rectangle

  • February 26, 2010
  • 5 replies
  • 1515 views

Hello guys,

the indesign client allows it to move a page item into a rectangle by copy it and pase with the option "paste into selection". How this behavior can be achieved by scripting on the indesign server?

Thanks for the answers!

5 replies

PeterPowAuthor
Known Participant
February 26, 2010

what is the best way to copy all relevant properties from one page item to another without losing information?

Peter Kahrel
Community Expert
Community Expert
February 26, 2010

Copy the frame's properties:

from = app.documents[0].textFrames[0];
to = app.documents[0].textFrames[1];
to.texts[0].properties = from.texts[0].properties;
to.properties = from.properties;

properties include the frame's contents but not the contents' formatting, so you need to do that separately (as above). Maybe this goes for other properties as well.

Peter

PeterPowAuthor
Known Participant
February 26, 2010

I know the solution with the "properties"-property, but thanks for the information about formattings!

PeterPowAuthor
Known Participant
February 26, 2010

I tried the following approach:

var rect = doc.rectangles[0];

var text1 = doc.textFrames[0];

var text2 = doc.textFrames[1];

rect.groups.add([text1, text2]);

but the server throws an error about a "wrong parameter", do you know why?

Peter Kahrel
Community Expert
Community Expert
February 26, 2010

You add groups to pages:

var rect = doc.rectangles[0];
var text1 = doc.textFrames[0];
var text2 = doc.textFrames[1];
doc.pages[0].groups.add([rect, text1, text2]);

PeterPowAuthor
Known Participant
February 26, 2010

well, the rectangle object also contains the "groups"-property, so I quess it should be possible to add groups to other objects than pages, too. Maybe the problem here is that the items I am trying to group inside the rectangle are not contained by it.

Peter Kahrel
Community Expert
Community Expert
February 26, 2010

You can store the page item in a library, then place that asset) at the target rectangle's first insertion point.

Peter

PeterPowAuthor
Known Participant
February 26, 2010

A rectangle does not have insertion points, but thanks for the suggestion!

Jongware
Community Expert
Community Expert
February 26, 2010

That turned out to be a bit harder than I thought as first ...

It seems you cannot simply do

  rectangles[0].add (someOtherObject);

or

  someOtherObject.move (rectangles[0]);

With the regular version of CS4, you can easily copy the manual approach:

app.cut();
app.documents[0].rectangles[0].select();
app.pasteInto();

-- but does that even work on ID Server? (I would guess not.)

The hard way is to add an instance of your original object to the correct type of the rectangle's properties array, copy all properties of the original object into the new one, then delete the original object.

For instance, if you want to 'move' a text frame into a rectangle, do something like

origTf = textFrames[0];

myTf = rectangles[0].textFrames.add();

myTf.geometricBounds = orgTf.geometricBounds;

myTf.strokeWidth = orgTf.strokeWidth;

myTf.fillColor = orgTf.fillColor;

... for all possible properties of a text frame. For an image, do the same but with Image properties. For a graphic line, do the same but with GraphicLine properties ... (It sounds like a totally insane way of working, but remember that internally InDesign itself can access all lists of properties 'immediately'.)

You cannot use a PageItem this way ... because you can't "add" a page item!

Dave Saunders shows how it works with a very basic text frame: Easily Add Captions to Graphic Frames

PeterPowAuthor
Known Participant
February 26, 2010

Thank you guys for your quick answers, as usual

@Harbs.

I already tried your sugestion with the snippet but this doesn't work. The snippet is imported into the parent page not the rectangle itself

@[Jongware]

I hoped there is a better solution but thank you for your detailed explanation!

Harbs.
Legend
February 26, 2010

You can try to export as a snippet, and import that...

Harbs