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

Placing snippets CC 2015 Mac

Guide ,
Jul 19, 2017 Jul 19, 2017

Copy link to clipboard

Copied

Hi,

I am placing snippets into my text by finding some text and then using place. The snippet is being placed, but the place is returning a zero length array.

var placedStuff = found[0].insertionPoints[-1].place ( idmsFile );

alert ( placedStuff.constructor.name ); // Array

alert ( placedStuff.length ); // 0

I have seen other threads where similar code is used.

https://forums.adobe.com/message/1999195#1999195

Any insight would be greatly appreciated.

Thanks.

P.

TOPICS
Scripting

Views

870

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Jul 19, 2017 Jul 19, 2017

Hi Pickory,

I think, we have two cases here with placing snippets at insertion points.

Case 1: The snippet contains one single page item at "first level" of objects.

Then that page item will be anchored to the insertion point. It could be anything. A group of objects. One rectangle, oval, polygon, graphic line, text frame, even a guide! In this case the array returned is of length 0.

Then you would retrieve the placed object with:

var pageItemPlaced = found[0].parent.characters[ found[0].insertionPoi

...

Votes

Translate

Translate
Community Expert ,
Jul 19, 2017 Jul 19, 2017

Copy link to clipboard

Copied

Hi Pickory,

I think, we have two cases here with placing snippets at insertion points.

Case 1: The snippet contains one single page item at "first level" of objects.

Then that page item will be anchored to the insertion point. It could be anything. A group of objects. One rectangle, oval, polygon, graphic line, text frame, even a guide! In this case the array returned is of length 0.

Then you would retrieve the placed object with:

var pageItemPlaced = found[0].parent.characters[ found[0].insertionPoints[-1].index ].pageItems[0];

Case 2: The snippet contains several page items at "first level" of objects:

Then InDesign will place the page items on the spread.

In this case the array returned should contain the items.

Just experiment with the following.

Believe me, it's fun 🙂

// EDIT. Used the wrong version of the code. You placed at insertion points. I should do that as well.
// So here the updated code:

/*

   

    Have one text frame with some text on page 1 of the active document.

    In the folder of the document have:

    One snippet with 3 page items: "3Rectangles.idms"

    One snippet with 3 page items grouped: "1Group.idms"

    One snippet with 1 guide: "1Guide.idms"

*/

var textFrame = app.documents[0].textFrames[0];

var found = [];

found[0] = textFrame.characters.itemByRange(5,10).getElements()[0];

var folder = File(app.documents[0].fullName).parent;

var snippetFileName1 = "3Rectangles.idms";

var snippetFile1 = File(folder+"/"+snippetFileName1);

var snippetFileName2 = "1Group.idms";

var snippetFile2 = File(folder+"/"+snippetFileName2);

var snippetFileName3 = "1Guide.idms";

var snippetFile3 = File(folder+"/"+snippetFileName3);

// Will place the 3 rectangles on the spread:

if(snippetFile1.exists)

{

    var returned1 = found[0].insertionPoints[-1].place( snippetFile1 , false );

    $.writeln(returned1.constructor.name);

    $.writeln(returned1.length);

};

// Will place the group at insertion point:

if(snippetFile2.exists)

{

    var returned2 = found[0].insertionPoints[-1].place( snippetFile2 , false );

    $.writeln(returned2.constructor.name);

    $.writeln(returned2.length);

};

// OH WOW!

// Will place the guide at insertion point:

if(snippetFile3.exists)

{

   

    var returned3 = found[0].insertionPoints[-1].place( snippetFile3 , false );

    $.writeln(returned3.constructor.name);

    $.writeln(returned3.length);

};

See here. Before placing snippets of sample code:

BeforePlacingSnippets.png

After placing snippets of sample code:

AfterPlacingSnippets.png

Wow. Never knew that one can place a guide at insertion point!

Placed 3 rectangles on the spread selected:

Placed-3Rectangles-Selected.png

Placed group of 3 rectangles at insertion point selected:

Placed-1Group-Selected.png

Placed guide at insertion point selected:

Placed-1Guide-Selected.png

Regards,
Uwe

Votes

Translate

Translate

Report

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 ,
Jul 19, 2017 Jul 19, 2017

Copy link to clipboard

Copied

The ability to place guides at insertion points is really amazing!

That also means: If you roatate the text frame of the insertion point where the guide is placed, the guide is rotated with the text frame. Cool. And the guide remains functional. Means, you could align page items to the guide easily etc.pp.

Wow. I'm excited…

Regards,
Uwe

( All tests done with InDesign CS6 8.1.0 on Mac OS X 10.6.8 )

Votes

Translate

Translate

Report

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 ,
Jul 19, 2017 Jul 19, 2017

Copy link to clipboard

Copied

Ok. One could do placing guides at insertion points not only by scripting but also in the UI with:

1. Selecting an insertion point and then place the IDMS file that contains a guide.

2. Place an InDesign Library asset that contains a guide to a selected insertion point.

The downside:

Duplicate or copy/paste a text frame with a guide will make it "invisible"or "vanish" ( perhaps a redraw problem).

So all this is of limited use.

Regards,
Uwe

Votes

Translate

Translate

Report

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
Guide ,
Jul 19, 2017 Jul 19, 2017

Copy link to clipboard

Copied

LATEST

Uwe,

Thank you very much. Your expert explanation and extra insight deserve extra points!

Excellent!

P.

Votes

Translate

Translate

Report

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