Trying to Lock all The Tables in the Document Using Invoke Command

Enthusiast ,
Dec 13, 2021 Dec 13, 2021

Copy link to clipboard

Copied

Hi Experts..

in this script im trying to lock only all the tables in the document but nothing happened and no error!

can you please tell if this possible and correct my script and thanks in advance :

 

//lock All Tables in the Document using invoke
function LockAllTables() {
    var doc = app.activeDocument;
    var allDoctables = doc.stories.everyItem().tables.everyItem().getElements();
    for (i=0; i<allDoctables.length; i++){
        //Object >> Lock Invoke
        var LockMyTable = app.menuActions.itemByID(11304);
        while (allDoctables[i]-->0) {
        LockMyTable.invoke()
            }
        }
    }

LockAllTables();

 

Best
M.Hasanain
TOPICS
Scripting

Views

152

Likes

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

Adobe Community Professional , Dec 13, 2021 Dec 13, 2021
In order to run the lock command, the table character (<0016>) on the story or the parent frame of the table is required as a selection. Selecting the table (all cells) will not work. It worked with the following modifications. function LockAllTables() { var doc = app.activeDocument; var allDoctables = doc.stories.everyItem().tables.everyItem().getElements(); for (i=0; i<allDoctables.length; i++){ //Object >> Lock Invoke var LockMyTable = app.menuActions.itemByID(1130...

Likes

Translate

Translate
Adobe Community Professional ,
Dec 13, 2021 Dec 13, 2021

Copy link to clipboard

Copied

Correct me if I'm wrong, but I don't think you can lock a table? Only its containing frame(s)? Also I have no idea what Table > 0 evaluates to. Why are you using while since you're just iterating through the tables?

Likes

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
Enthusiast ,
Dec 13, 2021 Dec 13, 2021

Copy link to clipboard

Copied

Thanks, i thought i will not be possible also, its ok, for while it was originally if condition but i use while because i thouht i can make unusual trickey condition to trick the system but its clear that engine will not tricked with fake condition! 😅

Best
M.Hasanain

Likes

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
Adobe Community Professional ,
Dec 13, 2021 Dec 13, 2021

Copy link to clipboard

Copied

I have no idea what the while line means.
Does the command to invoke work even if the table is not selected?

Likes

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
Enthusiast ,
Dec 13, 2021 Dec 13, 2021

Copy link to clipboard

Copied

Actually i thought i will trick the engine with fake while! but the trick didnt work and the script not working , also i tried try and catch with select and didnt work, the invoke command didnt work , in first attempt one table was selected and it works only in one table, in try and catch i tried to select the tables itself but also didnt work :

 

  app.select(allTables[aTable]);
   try {
  //Lock
  app.menuActions.itemByID(11304).invoke();
  } catch (e) {

 

 

Best
M.Hasanain

Likes

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
Adobe Community Professional ,
Dec 13, 2021 Dec 13, 2021

Copy link to clipboard

Copied

I still don't know what command you are trying to invoke. There is no lock command for a table in the UI. You can only lock a Page Item or Layer, as far as I know. A table is not a Page Item. 

Likes

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
Adobe Community Professional ,
Dec 13, 2021 Dec 13, 2021

Copy link to clipboard

Copied

In order to run the lock command, the table character (<0016>) on the story or the parent frame of the table is required as a selection. Selecting the table (all cells) will not work.

It worked with the following modifications.

function LockAllTables() {
    var doc = app.activeDocument;
    var allDoctables = doc.stories.everyItem().tables.everyItem().getElements();
    for (i=0; i<allDoctables.length; i++){
        //Object >> Lock Invoke
        var LockMyTable = app.menuActions.itemByID(11304);
        /*while (allDoctables[i]-->0) {
        LockMyTable.invoke()
            }*/
        allDoctables[i].parent.select();
        LockMyTable.invoke();
        }
    }

LockAllTables();

 

Likes

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
Enthusiast ,
Dec 14, 2021 Dec 14, 2021

Copy link to clipboard

Copied

Wow, thats Awesome Trick! , Thanks a lot @ajabon grinsmith 

Best
M.Hasanain

Likes

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
Adobe Community Professional ,
Dec 14, 2021 Dec 14, 2021

Copy link to clipboard

Copied

"in this script im trying to lock only all the tables in the document"

 

Hi M.Hasanain,

as you already can see, one cannot lock tables.

One can only try to lock a text frame that contains a table.

 

The code that uses a menu command to lock an item always requires the selection of that item.

Also keep in mind that the parent of a table in your array returns a single text frame if you are lucky.

parent.select() would return an error if the table is entirely in overset.

 

What's more: A table could also run through several text frames. So locking the first frame may not be enough.

Editing contents in ALL parts of a table where only the first frame of several frames is locked is still possible.

 

And finally: A user could still select and edit a locked object if the InDesign preferences allow this. Controlled by ExtendScript with:

 

app.generalPreferences.preventSelectingLockedItems

 

 

So the question in the end is:

How much can you shield a table from editing?

If you have a versed InDesign user, you cannot do much by locking frames.

 

Regards,
Uwe Laubender

( ACP )

Likes

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
Enthusiast ,
Dec 15, 2021 Dec 15, 2021

Copy link to clipboard

Copied

LATEST

Thanks a lot @Laubender  for valuable informations, i just want to prevent users from accedintally moving the tables!, but thanks you for your deep investagating, best for you and have a great day.

 

Best
M.Hasanain

Likes

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