How to convert textframe to button?
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)if( !maCreateButton.isValid ) return false;
app.selection = [obj];
var maCreateButton = app.menuActions.item('$ID/$$$/Dialog/CmdName/CreateButton'),
ret = app.selection;
ret.name = bName||ret.name;
ret.description = bDesc||ret.description;
// sample code
var myTextFrame = app.activeDocument.textFrames;
var myButton = convertToButton(myTextFrame);
Note: this approach is used in FlyingButtons:
It's working. I've also tried to do it from DOM. But failed to find appropriate method. Thanks again!!!!
Can you please suggest to handle the same in server instead of selection. Your help should be appreciated.
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;
var itemYouLikeToConvert = doc.spreads.textFrames;
var myButton = doc.spreads.buttons.add();
var tempRect = myButton.states.groups.rectangles;
Thanks you so much. Can you please suggest me to enable the property of below
Hi sreekarthikeyank ,
look into DOM documentation for the Button object:
There you'll find all properties you'll need.
Especiall look into the various behaviors that are offered.
Especially this one:
behaviorEvent : BehaviorEvents.MOUSE_DOWN
Properties fieldsToHide and fieldsToShow are of interest as well.