I have a function for a driver that expects 2 objects as arguments, and I can't find a way to set the variable as the Object ID, only a single property of that object. Is that possible?
Using the depsgraph
Since the upgrade to 2.8 the depsgraph is a member of the locals of a driver, as are the variables. See answer to
re setting up a test driver.
As an example, driver is on "Cube". The object "Lamp" is in scene, and passed as an evaluated object to the driver via the depsgraph. The depsgraph can also be used.
def test(*args, depsgraph=None, **kwargs): for arg in args: print(arg) print(depsgraph) return -1 # a simple val to indicate working <bpy_struct, Object("Cube") at 0x7f62fcbefa08, evaluated> <bpy_struct, Object("Lamp") at 0x7f62fcbf0008, evaluated> <bpy_struct, Depsgraph at 0x7f62faba6c08>
An example to return minimum global z of all other objects in the depsgraph. The method of @lemon can be used for the object names. Other options could be tagging them via custom property or name prefix suffix.
def test(self, *args, depsgraph=None, **kwargs): z = min(o.matrix_world.translation.z for o in depsgraph.objects if o != self) return z
IMO the best way to associate an object(s) with another is via a pointer property
bpy.types.Object.driver_obj1 = bpy.props.PointerProperty(type=bpy.types.Object)
which can be assigned via script or UI.
context.object.driver_object1 = context.scene.objects.get("Lamp")