Copy link to clipboard
Copied
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;
maCreateButton.invoke();
ret = app.s
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)
if( !maCreateButton.isValid ) return false;
{
app.selection = [obj];
var maCreateButton = app.menuActions.item('$ID/$$$/Dialog/CmdName/CreateButton'),
ret;
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
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!!!!
Copy link to clipboard
Copied
Can you please suggest to handle the same in server instead of selection. Your help should be appreciated.
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
Copy link to clipboard
Copied
Thanks you so much. Can you please suggest me to enable the property of below
Copy link to clipboard
Copied
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