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

Concentrate groupped pageItems by script

Community Beginner ,
Feb 19, 2016 Feb 19, 2016

Hi,
Every day I’m working with grouped elements which consist of 1 Rectangle and several TextFrames – usually 3.
I need to change dimension of Rectangle every time but not to ungroup the Objects. So I’m clicking twice on Rectangle, move it and resize. In this case all the TextFrames in group remain sometimes far … far from the Rectangle but there is a need to bring them together again.

I’m wondering if there is a possibility to write a java script which can concentrate the elements of group by moving TextFrames to the bounds (or origin) of Rectangle.

I will be very grateful for any idea how to do it or better a pace of Code which will do this annoying and tiring work 🙂

Best regards
Marcin

A.pngB.png

C.png

TOPICS
Scripting
2.0K
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
Guide ,
Feb 22, 2016 Feb 22, 2016

Hi Marcin,

Here is a draft code you may work from.

#targetengine magnetGroupRectangle

function follow() 

{   

    const T=0, L=1, B=2, R=3;

    if( !app.properties.activeDocument ) return;

    if( !app.properties.selection ) return;

    if( 1 != app.selection.length ) return;

   

    var a, i, every, b, i, dx, dy

        r = app.selection[0],

        g = r.parent;

    if( !( r instanceof Rectangle ) ) return;

    if( !( g instanceof Group ) ) return;

    if( 3 != g.pageItems.count() ) return;

    a = (every=g.textFrames.everyItem()).getElements();

    if( 2 != a.length ) return;

    b = every.visibleBounds;

    i = +(b[0] > b[1]);

   

    r = r.visibleBounds;

    // Right magnet

    dx = r-b;

    b=r;

    b=r;

    b+=dx;

    b+=dx;

    // Bottom magnet

    i = 1 - i;

    dy = r-b;

    b=r;

    b=r;

    b+=dy;

    b+=dy;

   

    a[0].visibleBounds = b[0];

    a[1].visibleBounds = b[1];

(function(tasks,name,rate,callback) 

    var t = tasks.itemByName(name); 

    if( t.isValid )

    {

        t.eventListeners.everyItem().remove();

        t.remove();

    } 

    tasks.add({name:name, sleep:rate})

       .addEventListener(IdleEvent.ON_IDLE, callback, false); 

})(app.idleTasks,'magnetGroupRectangle',15,follow);

Here is what it does:

Test Group Magnet - YouTube

@+

Marc

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
Mentor ,
Feb 22, 2016 Feb 22, 2016

Marc!

I love those windows could be opened using your "draft codes"

Thanks for that!

Jarek

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 ,
Feb 22, 2016 Feb 22, 2016

Marc, vraiment cool ! 

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 ,
Feb 22, 2016 Feb 22, 2016

Ce n'est pas possible!

Wow. I want to see this when it is complete! Let me know, OK?

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 ,
Feb 22, 2016 Feb 22, 2016

Brilliant. Back to scripting kindergarten for me.

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 ,
Feb 23, 2016 Feb 23, 2016

Nice POC!

FWIW, I would record the old bounds and bail out immediately if it did not change, to prevent resetting the bounds on every idle event.

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 Beginner ,
Feb 23, 2016 Feb 23, 2016

Merci Marc pour ce code. Mais comment l'introduit-on dans Indesign ? Via quelle application ?

La démo est fantastique !

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
Guide ,
Feb 23, 2016 Feb 23, 2016

Thanks all for your feedback.

Graphikorps

Le script s'installe comme à l'ordinaire :

1. Créez un fichier jsx (par exemple : magnetGroup.jsx) et copiez-collez le code donné ci-dessus.

2. Installez le script, cf. Indiscripts :: Indiscripts for Dummies

3. Exécutez le jsx depuis la palette Scripts.

N. B. — Ce script est “session-persistent”, c.-à-d. qu'il reste actif jusqu'à la fermeture d'InDesign. Il inspecte la sélection active et réagit seulement lorsqu'un bloc rectangulaire est sélectionné au sein d'un groupe contenant par ailleurs exactement deux blocs-texte. Il faut donc disposer d'un groupe de 3 objets (un rectangle et deux blocs-textes). Dans les autres cas il ne se produit rien. Ces conditions pourraient bien sûr être ajustées, mais c'était la demande initiale de l'auteur de ce fil de discussion.

romanobstuder

Just create a file, e.g. magnetGroup.jsx, having the code I posted above and install the script as usual—cf. http://www.indiscripts.com/pages/help#hd0sb2

Then run the script from the Scripts panel. It won't do anything as long as you won't select a rectangle within a group that also contains two text frames (as requested by the author of this thread.)

These conditions could be easily adjusted for other purposes though. Note also that the script could be installed as a startup script as well 😉

@+

Marc

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 ,
Feb 23, 2016 Feb 23, 2016

Merci beaucoup Marc!

You are a star.

I think the EventListener is what makes this persistent. Is there a simple explanation on how to implement that style of scripts? I would love to play further with this!

Regards

Romano

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
Guide ,
Feb 23, 2016 Feb 23, 2016

Hi Romano,

1. What makes the script session-persistent is the #targetengine directive.

2. What makes the script responsive is the IdleTask instance (and indeed the underlying event listener.)

romanobstuder wrote:

(...) Is there a simple explanation on how to implement that style of scripts? I would love to play further with this!

We have often discussed InDesign events and listeners in various threads and posts. Here are a few links:

Hope that helps.

@+

Marc

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 Beginner ,
Feb 24, 2016 Feb 24, 2016

Merci beaucoup pour ces explications d'installation ! Je vais le tester avec impatience.

Bien cordialement,

Stéphane [Graphikorps]

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
People's Champ ,
Feb 29, 2016 Feb 29, 2016

After Christopher Colombus discovering America (or close), Pasteur revolutionizing medecin, now comes  Marc Autret exploring new lands of InDesign Scripting.

In one word…Amazing!

Loic

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 Beginner ,
Feb 29, 2016 Feb 29, 2016

Good answer !!!

"A small script for the man, a great script for humanity"

Stephane

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 ,
Feb 29, 2016 Feb 29, 2016

Just wanted to add a big "Merci" for the knowledge that Marc is sharing. Marc you are truly generous!

To all the others in this forum I highly recommend to follow the links by Marc. Lots of really great stuff!

Regards

Romano

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 ,
Feb 23, 2016 Feb 23, 2016

Hi Marc
This is great! So how do you do this?
I placed a file with your code in the script folder... that's no working...

Also I had no idea you can script something that works "all the time". I thought only real extensions can do this. My scripting is always a batch that does something to a file and then stops.

I would love to learn more about this!

Regards

Romano

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 ,
Feb 24, 2016 Feb 24, 2016

Great stuff, Marc!

Peter

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 ,
Mar 16, 2016 Mar 16, 2016
LATEST

That is AWESOME!

Just for the record, I tried it with images in a Data Merge. Unfortunately it doesn't work in that instance (if "fit frames to image" is selected, the script won't move the text accordingly). I think it has something to do with the image changing size without the focus being put onto the image.

Still a hell of a technique though!

If the answer wasn't in my post, perhaps it might be on my blog at colecandoo!
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