sad Add furniture progamatically !!!

This topic has been viewed 4734 times and has 7 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
josleen
Posts: 10
Joined: Sun Feb 27, 2011 4:11 pm
Country: Luton, Bedfordshire, 222

Add furniture progamatically !!!

Post by josleen »

Hi All,

How can I create furniture programatically on my home? I created walls and rooms but I am unable get the furniture. What classes are involved? Do I need to read from the io resources?

Thanks !!!
User avatar
alied
Posts: 40
Joined: Tue Sep 08, 2009 9:53 pm
Country: Rosario, Santa Fe, Argentina

Re: Add furniture progamatically !!!

Post by alied »

typing from memory:
Home myHome = new Home();
HomePieceofFurniture hpf = new HomePieceofFurniture(somePieceOfFurniture);
myHome.addFurniture(hpf);

The point is, you need a instance of a class implementing PieceOfFurniture e.g. CatalogPieceOFFurniture, which you can get from a FurnitureCatalog. Then, add it to your Home object. easy if you see it.

Good luck.
As I said, I'm typing from memory, so actual names of functions may differ.
User avatar
alied
Posts: 40
Joined: Tue Sep 08, 2009 9:53 pm
Country: Rosario, Santa Fe, Argentina

Re: Add furniture progamatically !!!

Post by alied »

some useful URLs:
HomePieceOfFurniture constructor[1]
Adding a HomePieceOfFurniture to a Home[2], [3]
[1]http://www.sweethome3d.com/javadoc/com/ ... Furniture)
[2]http://www.sweethome3d.com/javadoc/com/ ... Furniture)
[3]http://www.sweethome3d.com/javadoc/com/ ... re,%20int)
josleen
Posts: 10
Joined: Sun Feb 27, 2011 4:11 pm
Country: Luton, Bedfordshire, 222

Re: Add furniture progamatically !!!

Post by josleen »

@alied:

Thanks mate !!!
kleiba
Posts: 5
Joined: Fri Nov 11, 2011 8:40 am

Re: Add furniture progamatically !!!

Post by kleiba »

Hi,

sorry for piggybacking on this thread - I've tried using the steps outlined by alied, but still cannot add new furniture to my room :-(

Here's how I'm doing it right now:

Home home = new HomeFileRecorder().readHome(roomFile.getPath());

Content model = new URLContent(modelUrl);
PieceOfFurniture piece = new CatalogPieceOfFurniture("MyName", null, model, 100, 100, 100, ...);

HomePieceOfFurniture hpof = new HomePieceOfFurniture(piece);
hpof.setX(200);
hpof.setY(300);
hpof.setElevation(0);

home.addFurniture(hpof);

What happens with this code if I construct a HomeComponent3D around the home and display it in a JFrame is that I see the room and a white cube (1m edge length) at coordinates (200,300,0) -- BUT ONLY FOR ABOUT ONE SECOND!

Then it magically disappears from the scene again.

Very strange. If I query home.getFurniture() I can see that my new object is still in there, but as I said, it is only shown for one second and then it is suddenly gone.

Any help would be greatly appreciated.

Thanks,
Thomas
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: Add furniture progamatically !!!

Post by Puybaret »

In which view does it disappear? Plan view? 3D view? Both?
Any stack traces?
Emmanuel Puybaret, Sweet Home 3D creator
kleiba
Posts: 5
Joined: Fri Nov 11, 2011 8:40 am

Re: Add furniture progamatically !!!

Post by kleiba »

Hi Emmanuel,

Thanks for the quick reply! As I pointed out, I'm viewing the room through a HomeComponent3D component. Note that we are talking about a stand-alone application built on top of the SweetHome3D libraries, not a plugin that interacts with the SweetHome3D application itself.

I'd be happy to post the source code of a minimal example - basically it's not much more than the above code inside a main-method, plus the creation of a HomeComponent3D and a JFrame.

There are no stack traces because the program runs without complaints, i.e., no Exceptions are being thrown. It's just that the HomePieceOfFurniture object I add programmatically never gets displayed. Instead, I can see a 1^3m white cube for about one second where the HomePieceOfFurniture is supposed to be which then disappears.

A first guess was that perhaps the model data of the HomePieceOfFurniture was not found correctly, but I made sure that this is not the case, or else the URLContent constructor would complain anyway.

Thanks again for your help.

Cheers,
Thomas
User avatar
Puybaret
Posts: 9440
Joined: Mon Nov 07, 2005 12:00 pm
Country: Paris, France
Contact:

Re: Add furniture progamatically !!!

Post by Puybaret »

I guess you see only the box displayed during the loading of the 3D model. Once the 3D model is loaded, the box is replaced by the loaded model, but maybe it's an empty model. Which 3D model file do you try to use?
Emmanuel Puybaret, Sweet Home 3D creator
Post Reply New Topic

Who is online

Users browsing this forum: No registered users and 1 guest