You can group objects together to make a composite object that can be moved and rotated as though it were a single object. Create a frame object, and associate objects with that frame:
cylinder(frame=f, pos=(0,0,0), radius=0.1, length=1, color=color.cyan)
sphere(frame=f, pos=(1,0,0), radius=0.2, color=color.red)
f.axis = (0,1,0)
f.pos = (-1,0,0)
By default, frame() has a position of (0,0,0) and axis in the x direction (1,0,0). The cylinder and sphere are created within the frame. When any of the frame attributes are changed (pos, x, y, z, axis, or up), the composite object is reoriented and repositioned.
Another frame attribute is objects, which is a list of currently visible objects contained in the frame (the list does not include objects that are currently invisible). If you want to make all the objects in a frame be red, do the following (assume the frame is named f):
If you use this method to make all the objects invisible, the f.objects list will be empty. If you need a list containing all the objects, both visible and invisible, you need to maintain your own list of objects.
If ball is an object in a frame, ball.pos is the position local to the frame, not the actual position in "world space". Here is a routine that will calculate the position of a vector such as ball.pos in world space: