0
$\begingroup$

what I need is the change of items in certain points in a room. For example, in the determined x, y, z coordinates in the upper left corner, the closet will be the bed in the next scene. How can I achieve this with python.

Edit: I tried the code and the items take each other's positions, but there is a problem that some objects are buried because they are different in height.

Edit 2 : Based on your comments, I have progressed a lot. There will be 10 objects in my collection and there will be only 5 objects in the room. I want these items to change constantly, the locations will be the same, the items will change.

$\endgroup$
6
  • 2
    $\begingroup$ What have you tried so far? Where the objects come from? Blend, obj, fbx? How do you specify the coords? Can you elaborate? $\endgroup$
    – brockmann
    Sep 13 at 11:57
  • $\begingroup$ I have a room and I have imported my other objects in fbx format. Since one of my objects will be on the wall, I took it into a separate collection and the other objects in a collection, so I have 2 collections. I'm researching right now, I've written a few lines, that's all. $\endgroup$ Sep 13 at 12:00
  • 2
    $\begingroup$ Instead of comments, please use the edit link at the bottom of your question (i.stack.imgur.com/lXFuK.png) to add information to your post. $\endgroup$
    – brockmann
    Sep 13 at 12:08
  • 2
    $\begingroup$ Re last edit. Suggest that having a logical origin to your objects would make sense in this case. See blender.stackexchange.com/questions/73698/… With an origin on the bottom setting a loc'n on the floor places them on floor, not half their height above / below. IMO would add empties or vertex groups to your room, to give some rules to this. akin to feng shui A closet would most likely not be in center of a room. A bed probably doesn't go in the toilet. $\endgroup$
    – batFINGER
    Sep 13 at 14:03
  • 1
    $\begingroup$ ... also posted this as a duplicate blender.stackexchange.com/questions/212266/… of a previous question. The OP there has a number of question and answers related to doing exactly this. $\endgroup$
    – batFINGER
    Sep 13 at 14:23
1
$\begingroup$

As I understand, you want to randomize positions of objects in some collection, like in this script:

import bpy, random

objects = bpy.data.collections['Shuffler'].objects
locations = [o.location.copy() for o in objects]
random.shuffle(locations)
for o, new_location in zip(objects, locations):
    o.location = new_location

$\endgroup$
1
  • $\begingroup$ Yes, that's pretty much what I need. I guess I have to randomize the locations. $\endgroup$ Sep 13 at 13:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.