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

[IDCS6 JS] Cannot delete rectangle from a button

Participant ,
Jan 09, 2013 Jan 09, 2013

I'm creating a button with:

     var myRevealButton = myPage.buttons.add();

This creates an "empty" button consisting of a small rectangle.

Then I add some artwork (a group of InDesign objects) to the first state:

     myRevealButton.states[0].addItemsToState(myRevealButtonArt);

But when I try to remove the small rectangle automatically created by myPage.buttons.add(), I'm unable to do so (Object is invalid).

     myRevealButton.states[0].rectangles[0].remove();

Am I doing something wrong, or is this a bug? The rectangle shows up clearly in the Layers panel, and is visible on-screen, and I can delete it normally, but not via scripting.

On closer inspection,

     myRevealButton.states[0].rectangles.length = 0?

Any ideas?

TOPICS
Scripting
1.4K
Translate
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

LEGEND , Jan 09, 2013 Jan 09, 2013

All items in a button state are grouped. When you add an object to a state of a button, it's added to the group inside the button.

So myRevealButton.states.item(0).addItemsToState(myRevealButtonArt);

give you an object: myRevealButton.states.item(0).groups.item(0).pageItems.item(1); (or myRevealButton.states.item(0).groups.item(0).groups.item(0) if you know it was a group)

To remove the default rectangle do the following:

myRevealButton.states.item(0).groups.item(0).rectangles.item(0).remove();

Translate
Community Expert ,
Jan 09, 2013 Jan 09, 2013

@Keith – strange, indeed.

And it's not limited to InDesign CS6.

Same thing in InDesign CS5. Just tested…

The length on rectangles in the first state after adding the button seems to be 0, but the length of the pageItems is: 1.
So I grabbed the ID of the pageItem, stored it in a variable and removed the pageItem after adding the group.

That worked.

The pageItem was removed.

But with it the whole button as well…

Very strange…

Uwe

Translate
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
LEGEND ,
Jan 09, 2013 Jan 09, 2013

All items in a button state are grouped. When you add an object to a state of a button, it's added to the group inside the button.

So myRevealButton.states.item(0).addItemsToState(myRevealButtonArt);

give you an object: myRevealButton.states.item(0).groups.item(0).pageItems.item(1); (or myRevealButton.states.item(0).groups.item(0).groups.item(0) if you know it was a group)

To remove the default rectangle do the following:

myRevealButton.states.item(0).groups.item(0).rectangles.item(0).remove();

Translate
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 10, 2013 Jan 10, 2013

@Harbs – that is working. Thank you…

I was mislead by the layers panel in the UI that is showing one object, the [Normal] object, that obviously represents a state, where in the DOM we have two objects, that resemble that object:

the "State" Object plus its inherit "Group" object.

In removing pageItems[0] of states[0] I removed  one component that composes a state representation in the UI. In fact the whole state was removed. And a button without a state cannot exist.

So in effect the whole button was removed.

Does that make sense?

Uwe

Translate
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
LEGEND ,
Jan 10, 2013 Jan 10, 2013

Does that make sense?

I think so.

Translate
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
Participant ,
Jan 10, 2013 Jan 10, 2013
LATEST

Thanks to both of you for looking into this! Indeed, the rectangle is part of the group, as Harbs solution works. I was mislead by the lack of a visible group in the Layers panel.

Translate
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