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

Intercept TextFrame deletion through a script

New Here ,
Dec 23, 2022 Dec 23, 2022

Copy link to clipboard

Copied

Hi all,
I have an Indesign document made up of various articles divided into several text frames. Through a script is it possible to intercept the deletion of any text frame?
Thanks for your help

TOPICS
How to , Scripting

Views

569

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
Community Expert ,
Dec 23, 2022 Dec 23, 2022

Copy link to clipboard

Copied

Hi @lo22764185qzp2 ,

there is nothing you can do if you make the document available to someone else who is not working on your machine with your version of InDesign.

 

Theoretically one  could install a startup script with an event handling mechanism that can detect the document and a list of text frames identified by their IDs. But a clever user can work around this by exporting the document to IDML and open the IDML file as new document…

 

What you can do is lock items like text frames.

Text is still editable if InDesign's preferences are set to allow the selection of locked items.

But this is not a document specific preference:

 

Preferences > General > Object Editing

[  ] Prevent Selection of Locked Objects

 

Regards,
Uwe Laubender
( Adobe Community Expert )

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
Community Expert ,
Dec 23, 2022 Dec 23, 2022

Copy link to clipboard

Copied

Easier yet, just lock the layer the text frames are on. 

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
New Here ,
Dec 27, 2022 Dec 27, 2022

Copy link to clipboard

Copied

Thanks for the reply,
what I have to do is intercept the deletion of the TextFrame to show a warning message.
Do you think there is a way to do this through a script?
Thanks again

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
Guide ,
Dec 23, 2022 Dec 23, 2022

Copy link to clipboard

Copied

Are you talking about an event - the moment user hits Delete key - or checking during next opening of the file for missing objects ? 

 

ID-Tasker - most powerful tool ever created for InDesign

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
New Here ,
Dec 27, 2022 Dec 27, 2022

Copy link to clipboard

Copied

Thanks for the reply,
what I have to do is intercept the deletion of the TextFrame to show a warning message.
Do you think there is a way to do this through a script?
Thanks again

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
Community Expert ,
Dec 27, 2022 Dec 27, 2022

Copy link to clipboard

Copied

Hi @lo22764185qzp2 ,

should this work on your machine or should it work on the machine from someone else?

As I already said: If its your machine you can do something.

To make it more clear: You cannot provide a document where this warning mechanism is embedded.

 

Regards,
Uwe Laubender
( Adobe Community Expert )

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
Community Expert ,
Dec 27, 2022 Dec 27, 2022

Copy link to clipboard

Copied

Hi @lo22764185qzp2,

Nothing very specific to point the frame deletion is available with JS scripting. In addition to the points mentioned by other members you could look at AFTER_SELECTION_CHANGED event on the application object to identify whether a frame was deleted or not. Something like creating a list of frames and saving it on the document label and then checking if that list still holds true everytime the event is raised.

If you are after prompt notification for frame deletion then you will have to look at C++ SDK.

-Manan

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
Guide ,
Dec 27, 2022 Dec 27, 2022

Copy link to clipboard

Copied

Could be done via scripting - "monitoring" - but ONLY on the PC and VB6. 

 

ID-Tasker - most powerful tool ever created for InDesign

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
Community Expert ,
Dec 27, 2022 Dec 27, 2022

Copy link to clipboard

Copied

@Robert Tkaczyk please elaborate about what you are thinking, seems interesting

-Manan

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
Guide ,
Dec 27, 2022 Dec 27, 2022

Copy link to clipboard

Copied

As I've showed on another thread - synchronised preview of the documents - it's possible to create standalone application - EXE file - that can monitor what is happening in the InDesign and do some cool stuff 😉 

 

When you click in one document - the same object is selected in the other document - and you can switch between documents so there is no master / slave - and the zoom level is also preserved 😉

 

SynchroPreview.gif

 

Right now, it works only on copies of the documents - handy when you have completely translated your document - but can be easily changed to comparing just by page - so would work with ANY document.

 

Could be expanded to choose ANY object that fits the location ...

 

ID-Tasker - most powerful tool ever created for InDesign

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
Community Expert ,
Dec 27, 2022 Dec 27, 2022

Copy link to clipboard

Copied

Hi Robert,

hm… A standalone EXE file?

But that must also be installed and executed by the user, or am I wrong with that assumption?

Does the user need admin rights for this?

 

As opposded to a startup script for InDesign with an event listening mechanism that must only be installed by the user in the user directory. Currently I cannot see the advantage of an EXE file…

 

Regards,
Uwe Laubender
( Adobe Community Expert )

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
Guide ,
Dec 27, 2022 Dec 27, 2022

Copy link to clipboard

Copied

Yes, script - as exe - needs to be run / executed / initiated  by the user - no need for any admin rights, but, unfortunately, user will need to register InDesign - TLB file - in the system manually as CC installer is broken - and has been for many years.

 

Not sure what would be the difference between "my" solution or listening to events - but it was a breeze 😉

 

ID-Tasker - most powerful tool ever created for InDesign

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
Community Expert ,
Dec 27, 2022 Dec 27, 2022

Copy link to clipboard

Copied

But then if we using TLB file which I supposed we would then we are hitting the same interface that the JSX can exploit. Unless we need to do some OS level operations would the exe provide any benefits?

-Manan

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
Guide ,
Dec 28, 2022 Dec 28, 2022

Copy link to clipboard

Copied

I'm not sure if you know what TLB file is? 

 

And I'm not sure what kind of events are available through scripting in the InDesign - never done it - but I have a bit different approach to reacting to what user is doing in the InDesign - not sure if it offers more or less functionality.

 

ID-Tasker - most powerful tool ever created for InDesign

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
Community Expert ,
Dec 28, 2022 Dec 28, 2022

Copy link to clipboard

Copied

Hi @Robert Tkaczyk,

Yes, I do know about TLB, its a file that defines the interface of by a DLL for all the methods and events it exposes. In relation to InDesign that would mean TLB would contain the method declerations that are exposed by InDesign for automations. This TLB can thus be used to interact with InDesign using varied languages like C#, VBScript etc. When we as plugin developers expose new methods via the scripting interface the TLB is updated with the decleration for those newly added methods/events. So as I said TLB does not offer any newer functionality apart from what is available to the JS interface. This is what I know, I may be missing some pieces hence I am keen to learn your experieince. So if you could shed some light on how you plan to trap this event or any other change on the document that would be great.

-Manan

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
Guide ,
Dec 28, 2022 Dec 28, 2022

Copy link to clipboard

Copied

The idea is to monitor current selection - in an infinite loop - and for this particular case - try to set a reference to last selected object - if it fails - then it means that object no longer exists = has been deleted.

Grouping won't affect the object - only reference to the Parent will change and if group is ungrouped - it can also be handled as you can check and save info about the type of the last selected object.

So kind of waiting for an event to happen.

 

And to expand this idea - you could track order of the selected objects - but of course only, when they are selected one-by-one - not when using mouse and area selection or CTRL+A 😉

Or automatically react to what has been selected - e.g. if user selects frame with image then TextFrame - convert it to image with description or Group - or even use placeholder to fill 😉 Which will be part of my latest & greatest tool of all time 😉

 

From my experience - for some strange reason - only Links change when you change a visibility of the Layer inside the linked file - new Link object is created when the old one is destroyed - parent object - e.g. Rectange - remains the same - fortunately.

 

ID-Tasker - most powerful tool ever created for InDesign

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
Community Expert ,
Dec 28, 2022 Dec 28, 2022

Copy link to clipboard

Copied

Fair enough. Just one thing won't the infinite loop make InDesign perpertually busy and unusable for the user or does it remain responsive?

-Manan

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
Guide ,
Dec 29, 2022 Dec 29, 2022

Copy link to clipboard

Copied

And that's the beauty of the exe and external app 😄 - it's not like script run from within of the InDesign - it doesn't "block" InDesign in any way 😄 it just monitors what is happening - and can interfere but you need to be careful what you want to do in the InDesign as user can change anything at any time so you need to work with the user - he needs to be aware of what he can and can't do. 

 

For example - user can't use clipboard - when script will do copy&pasting - or select objects - when script is selecting. 

 

Either user needs to take his hands off the keyboard and mouse - or switch to other app - but still remember not to use copy&paste. 

 

 

ID-Tasker - most powerful tool ever created for InDesign

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
Engaged ,
Jan 16, 2023 Jan 16, 2023

Copy link to clipboard

Copied

How about attaching an event to the menuAction?

#targetengine "session"
if (app.menus.itemByName("Main").submenus.itemByName("$ID/Edit").menuItems.itemByName("$ID/Clear").associatedMenuAction.eventListeners.itemByName("beforeInvokeClear").isValid) {
    app.menus.itemByName("Main").submenus.itemByName("$ID/Edit").menuItems.itemByName("$ID/Clear").associatedMenuAction.eventListeners.itemByName("beforeInvokeClear").remove();
}
app.menus.itemByName("Main").submenus.itemByName("$ID/Edit").menuItems.itemByName("$ID/Clear").associatedMenuAction.addEventListener(
    MenuAction.BEFORE_INVOKE, function(myEvent) {
        for (var i = 0; app.activeDocument.selection.length > i ; i++) {
            if (app.activeDocument.selection[i] instanceof TextFrame) {
                alert("Please do not delete the text frame.");
                myEvent.preventDefault();
                break;
            }
        }
    }).name = "beforeInvokeClear";

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
Community Expert ,
Jan 16, 2023 Jan 16, 2023

Copy link to clipboard

Copied

Hi @琥珀 猫太郎,

Won't that work only when the deletion is triggered by the menu option. What happens when the user uses the delete key. Frankly speaking I never used the Clear menu untill today after looking at your code.

-Manan

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
Engaged ,
Jan 16, 2023 Jan 16, 2023

Copy link to clipboard

Copied

I think that the shortcut of Clear menu is applied to DEL Key.

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
Community Expert ,
Jan 16, 2023 Jan 16, 2023

Copy link to clipboard

Copied

LATEST

Brilliant, it worked for me as well. @lo22764185qzp2 can you verify this should be the solution you are searching for.

-Manan

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