0

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.

  • 2
    What have you tried so far? Where the objects come from? Blend, obj, fbx? How do you specify the coords? Can you elaborate? – brockmann Sep 13 '21 at 11:57
  • 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. – fighterpilot Sep 13 '21 at 12:00
  • I sampled the codes from here: https://blender.stackexchange.com/questions/152961/how-to-randomly-pick-an-object-from-a-collection – fighterpilot Sep 13 '21 at 12:02
  • 2
    Instead of comments, please use the [edit] link at the bottom of your question (https://i.stack.imgur.com/lXFuK.png) to add information to your post. – brockmann Sep 13 '21 at 12:08
  • 2
    Re last edit. Suggest that having a logical origin to your objects would make sense in this case. See https://blender.stackexchange.com/questions/73698/translate-object-using-lowest-z-value-python/73702 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. – batFINGER Sep 13 '21 at 14:03
  • 1
    ... also posted this as a duplicate https://blender.stackexchange.com/questions/212266/randomly-distribute-objects-over-a-plane of a previous question. The OP there has a number of question and answers related to doing exactly this. – batFINGER Sep 13 '21 at 14:23

1 Answers1

1

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

Markus von Broady
  • 36,563
  • 3
  • 30
  • 99