1
$\begingroup$

Let's say that you have a table with randomly generated legs, and that you want to check if the table is stable enough to stand with a weights placed, one at a time, in four different spots on the board.

enter image description here

Question 1: How do you get the coordinates for these 4 different spots?

The best way would to be able to refer to each position as positions on the board rather than numbers , so that future scaling of the board doesn't affect the weights positions in relation to the board.

So let's say that you are able to identify the 4 locations. You create 4 cubes based on those postions:

bpy.ops.mesh.primitive_cube_add(radius=0.1, location=(location1)) bpy.ops.mesh.primitive_cube_add(radius=0.1, location=(location2)) bpy.ops.mesh.primitive_cube_add(radius=0.1, location=(location3)) bpy.ops.mesh.primitive_cube_add(radius=0.1, location=(location3))

However, you want to test if the table stands one cube at the time. You want to be able to unlink all cubes, then link back cube 1 to check, unlink and link back cube 2 and so on, till all four cubes are tested. How do you unlink and link back the cubes?

$\endgroup$
0
$\begingroup$

Ok, so I think I found a solution

def create_cubes():
#board=table without the legs
h=board_height
d=board.dimensions
l=board.location
r=0.3
#First cube
bpy.ops.mesh.primitive_cube_add(radius=r, location=(l.x-d.x/2+3*r, l.y+d.y/2-3*r, h+d.z+r))
add_rigidbody()
cube1=bpy.context.active_object
cube1.name = "Cube" + str(1)
validation_cubes.append(cube1)
bpy.data.scenes['Scene'].objects.unlink(bpy.data.objects["Cube" + str(1)])
#Second cube
bpy.ops.mesh.primitive_cube_add(radius=r, location=(l.x, l.y+d.y/2-2*r, h+d.z+r))
add_rigidbody()
cube2=bpy.context.active_object
cube2.name = "Cube" + str(2)
validation_cubes.append(cube2)
bpy.data.scenes['Scene'].objects.unlink(bpy.data.objects["Cube" + str(2)])    
#Third cube
bpy.ops.mesh.primitive_cube_add(radius=r, location=(l.x+d.x/4, l.y-d.y/2+3*r, h+d.z+r))
add_rigidbody()
cube3=bpy.context.active_object
cube3.name = "Cube" + str(3)
validation_cubes.append(cube3)
bpy.data.scenes['Scene'].objects.unlink(bpy.data.objects["Cube" + str(3)])   

Now you have defined the locations for three cubes. These locations will be the same, no matter how you scale the board or the radius of the cube.The cubes are named and placed in the list validation_cubes, unliked from the mesh

Then you simply need to create a loop that links back each cube, one at a time, so that the cubes don't affect eachother

def validate_table():
create_cubes()
for x in range(0,3):
    bpy.data.scenes['Scene'].objects.link(bpy.data.objects[validation_cubes[x].name])
    append_physics()
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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