How to convert textframe to button

Community Beginner ,
Apr 30, 2010 Apr 30, 2010

Copy link to clipboard

Copied

How to convert textframe to button?

TOPICS
Scripting

Views

2.2K

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

Guide , Apr 30, 2010 Apr 30, 2010
I didn't find a 'clean' way to do this through the DOM. As a workaround you can emulate a "Convert to button" action, provided your script is allowed to select the textframe target:// convertToButton for ID CS4 function convertToButton(/*PageItem*/obj, /*str*/bName, /*str*/bDesc) {      app.selection = [obj];      var maCreateButton = app.menuActions.item('$ID/$$$/Dialog/CmdName/CreateButton'),           ret;     if( !maCreateButton.isValid ) return false;      maCreateButton.invoke();      ret ...

Likes

Translate

Translate
Guide ,
Apr 30, 2010 Apr 30, 2010

Copy link to clipboard

Copied

I didn't find a 'clean' way to do this through the DOM. As a workaround you can emulate a "Convert to button" action, provided your script is allowed to select the textframe target:

// convertToButton for ID CS4


function convertToButton(/*PageItem*/obj, /*str*/bName, /*str*/bDesc)
{
     app.selection = [obj];
     var maCreateButton = app.menuActions.item('$ID/$$$/Dialog/CmdName/CreateButton'),
          ret;

     if( !maCreateButton.isValid ) return false;


     maCreateButton.invoke();
     ret = app.selection[0];
          
     ret.name = bName||ret.name;
     ret.description = bDesc||ret.description;
          
     return ret;
};

// sample code

var myTextFrame = app.activeDocument.textFrames[0];

var myButton = convertToButton(myTextFrame);

Note: this approach is used in FlyingButtons:

http://www.indiscripts.com/post/2010/03/flyingbuttons-a-script-to-automate-pdf-portfolios

@+

Marc

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 Beginner ,
Apr 30, 2010 Apr 30, 2010

Copy link to clipboard

Copied

Thanks mark,

It's working. I've also tried to do it from DOM. But failed to find appropriate method. 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
Explorer ,
Aug 20, 2019 Aug 20, 2019

Copy link to clipboard

Copied

Can you please suggest to handle the same in server instead of selection. Your help should be appreciated.

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 ,
Aug 20, 2019 Aug 20, 2019

Copy link to clipboard

Copied

Hi mrinmoy1984 ,

you can do the following without using a menu action:

1. Add a button to the document using buttons.add()

2. Access the first state of the button and use method addItemsToState()

The only argument of that method is an array that contains the item or the items you like to convert to a button.

3. Get rid of a rectangle that was automatically added to the first state when doing buttons.add().

With one element on spread one of a document, the text frame you want to convert to a button, run this script snippet:

var doc = app.documents[0];

var itemYouLikeToConvert = doc.spreads[0].textFrames[0];

var myButton = doc.spreads[0].buttons.add();

var tempRect = myButton.states[0].groups[0].rectangles[0];

myButton.states[0].addItemsToState([itemYouLikeToConvert]);

tempRect.remove();

Regards,
Uwe

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
Explorer ,
Aug 21, 2019 Aug 21, 2019

Copy link to clipboard

Copied

Thanks you so much. Can you please suggest me to enable the property of below

Capture.PNG

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 ,
Aug 21, 2019 Aug 21, 2019

Copy link to clipboard

Copied

LATEST

Hi sreekarthikeyank ,

look into DOM documentation for the Button object:

Adobe InDesign CS6 (8.0) Object Model JS: Button

There you'll find all properties you'll need.

Especiall look into the various behaviors that are offered.

Especially this one:

Adobe InDesign CS6 (8.0) Object Model JS: ShowHideFieldsBehavior

myButton.showHideFieldsBehaviors.add

(

    {

        behaviorEvent : BehaviorEvents.MOUSE_DOWN

    }

);

Properties fieldsToHide and fieldsToShow are of interest as well.

Regards,
Uwe

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