Check if item is selected.

This topic has been viewed 4762 times and has 5 replies
Thread status: Active
Questions about extending features and developing plug-ins [img]http://www.sweethome3d.com/images/flags/en_small.gif[/img]
Post Reply New Topic
jrmobile
Posts: 11
Joined: Sat May 16, 2020 9:20 pm
Country: Россия

Check if item is selected.

Post by jrmobile »

Good day everyone.
Spent hours in developers guide, trying to find out, how do check in plugin if PieceOfFurniture is selected.

Found only getSelectedItems() method, but maybe there is easier way to check it, intead of checking, if my items are in group?

If there is no easier way, would you be so kind to show me the exact code to check if items are in selected group. I'm not expert in java, so would really appreciate it.

Anyway thanks in advance.
jrmobile
Posts: 11
Joined: Sat May 16, 2020 9:20 pm
Country: Россия

Re: Check if item is selected.

Post by jrmobile »

I'm trying this way
List<selectableItem> selectedItems = home.getSelectedItems();

List<HomePieceOfFurniture> furniture = selectedItems.getFurniture();

But it fires an error selectableItem cannot be resolved to a type. Same with type "Selectable".
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: Check if item is selected.

Post by Puybaret »

There’s no easier way, because there’s no [font=courier new]getParent[/font] method in [font=courier new]HomePieceOfFurniture[/font] class. You’ll have to find the group of each selected item when it doesn’t belong to the list returned by [font=courier new]home.getFurniture()[/font].
Emmanuel Puybaret, Sweet Home 3D creator
jrmobile
Posts: 11
Joined: Sat May 16, 2020 9:20 pm
Country: Россия

Re: Check if item is selected.

Post by jrmobile »

Emmanuel, Thank you very much for your reply.
I know that it is very brazenly, but i ask you to help in making a code piece to obtain a list за selected furniture, by the algorithm you've described?
jrmobile
Posts: 11
Joined: Sat May 16, 2020 9:20 pm
Country: Россия

Re: Check if item is selected.

Post by jrmobile »

I'm trying this one, but it still fires an error selectable
cannot be resolved to a type


List<Selectable> selectedItems = home.getSelectedItems();
List<HomePieceOfFurniture> furniture = selectedItems.getFurniture();

for (HomePieceOfFurniture homePiece : furniture) {
if (selectedItems.contains(homepiece)) {
continue;
}
}
}
jrmobile
Posts: 11
Joined: Sat May 16, 2020 9:20 pm
Country: Россия

Re: Check if item is selected.

Post by jrmobile »

I've made it. Thanks for your help.
Post Reply New Topic

Who is online

Users browsing this forum: No registered users and 1 guest