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

reverse table cells inset script

Explorer ,
Mar 29, 2016 Mar 29, 2016

Hi all,

please i need help badly to create a script to reverse table cells inset on all tables for a document

for ex:

i need to change Left cell inset value with Right cell inset on all tables with all cells

3.png

Thanks in Advance

TOPICS
Scripting
1.7K
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

correct answers 1 Correct answer

Advisor , Mar 29, 2016 Mar 29, 2016

sorry, mistyped a bracket there:

(function() {

        try {

            var cells = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();

            for (var i = 0; i < cells.length; i++) {

                var l = cells.leftInset;

                cells.leftInset = cells.rightInset;

                cells.rightInset = l;

            }

        } catch (e) {

        }

}())

Translate
Advisor ,
Mar 29, 2016 Mar 29, 2016

Show your code. What have you tried so far?

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

hey Vamitul,

i tried this code

app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().rightInset = "3mm"

app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().leftInset = "4mm"

but in case i have many tables with different values then i can't unify same values to all tables, i need to read left inset and reverse it to right inset

Thanks

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

This ought to get you up and running:

http://indesignsecrets.com/tackling-tables-through-scripting.php

As you may already know, these properties are called 'leftInset' and 'rightInset'; exchanging them should be easy (but take care to use a temporary variable in between).

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

Thanks

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
Advisor ,
Mar 29, 2016 Mar 29, 2016

(function(){

  try {

  var cells=app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();

  for (var i=0; i<cells.length;i++){

  var l=cells.leftInset;

  cells.leftInset=cells.rightInset;

  cells.rightInset=l;

  }catch(e){

  }

  }

}())

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

Dear Vamitul,

Thanks a lot for your help but i got this error

1.png

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
Advisor ,
Mar 29, 2016 Mar 29, 2016

sorry, mistyped a bracket there:

(function() {

        try {

            var cells = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();

            for (var i = 0; i < cells.length; i++) {

                var l = cells.leftInset;

                cells.leftInset = cells.rightInset;

                cells.rightInset = l;

            }

        } catch (e) {

        }

}())

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

OMG

Thanks a lot you are really made my day Vam

your help is highly appreciated

one more question

can i use this code to reverse text wrap insets too??

Best Reagrds

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

Fine! Thanks Vamitul! 

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

Vamitul,

I've 2 questions:

• Why do you place the "function" between two parenthesis?

• Is the "try … catch …" truly useful here?

Thanks in advance! 

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
Advisor ,
Mar 29, 2016 Mar 29, 2016

Obi-wan Kenobi

the (function(){}())  pattern is called and self-executing anonymous function. Because javascript has function-based scope, it is used to isolate the variables in the script as not to pollute the global namespace. While in this, and many other simple scripts is not really needed, since the engine in which the script runs is not persistent, it does not hurt and it's a good habit to get into for when you start to write much larger scripts. There are quite a few resources about this online, for example: http://stackoverflow.com/questions/14322708/what-is-self-executing-anonymous-function-or-what-is-thi...

The try-catch here is very useful here:

consider what happens if a document has no tables:

app.activeDocument.stories.everyItem().tables.everyItem() returns and empty specifier, that has no "cells" object, so you would get an error. Or, taking things to a bit more extreme, what if there is no document opened? I agree it's not the nicest, most elegant or expressive way of doing it, but it works in a pinch (to be read as: don't do as i do).

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

Thanks a lot for these explanations! 

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