So, there are 2 ways of proceeding.
1/ Using a Python script to edit the Image/Layer metadata valuepython code
# Get path tracer attrs
pt = ix.get_item("project://scene/path_tracer")
aa = pt.get_attribute("anti_aliasing_sample_count").get_long()
# Get camera attrs
cam = ix.get_item("project://scene/camera")
cam_fov = cam.get_attribute("field_of_view").get_double()
cam_f_stop = cam.get_attribute("f_stop").get_double()
cam_focus_dist = cam.get_attribute("focus_distance").get_double()
cam_gm = cam.get_module().get_global_matrix()
# Build the metadata string
md = 'anti_aliasing_sample_count {}'.format(aa)
md += '\n'
md += 'camera_fov {}'.format(cam_fov)
md += '\n'
md += 'camera_f_stop {}'.format(cam_f_stop)
md += '\n'
md += 'camera_focus_distance {}'.format(cam_focus_dist)
md += '\n'
md += 'camera_global_matrix'
for row in range(4):
for col in range(4):
md += ' {}'.format(cam_gm.get_item(row, col))
md += '\n'
md += 'custom_string "hello world"'
# Set the metadata in the image
ix.get_item("project://scene/image.metadata").set_string(md)
2/ Using an expression in the metadata attributeHowever, there are some limitations:
- we need to use an ugly workaround to add escaped characters like \n or " in a string;
- we can't access an object's Module to call functions like `get_global_matrix`
SeExpr code
# Get attribute values
aa = get_double("project://scene/path_tracer.anti_aliasing_sample_count");
cam_fov = get_double("project://scene/camera.field_of_view");
cam_f_stop = get_double("project://scene/camera.f_stop");
cam_focus_dist = get_double("project://scene/camera.focus_distance");
# Can't retrieve the Camera module needed to compute the global matrix.
# But it's possible to get the Kinematics attributes: translate, rotate, etc.
# Build the metadata string with the values
# NOTE: the eval usage is a temporary workaround to allow escaping characters.
md = "anti_aliasing_sample_count " + to_string(aa);
md += eval("\n");
md += "camera_fov " + to_string(cam_fov);
md += eval("\n");
md += "camera_f_stop " + to_string(cam_f_stop);
md += eval("\n");
md += "camera_focus_distance " + to_string(cam_focus_dist);
md += eval("\n");
md += "custom_string " + eval("\"") + "hello world" + eval("\"");
# return the string
md
Output from solution 1:
- Code: Select all
anti_aliasing_sample_count 9
camera_fov 25.0
camera_f_stop 5.6
camera_focus_distance 5.0
camera_global_matrix 0.707106781187 -0.331290731025 0.624697087825 2.44030930037 0.0 0.883455093977 0.468515844905 1.8302047538 -0.707106781186 -0.331290731026 0.624697087825 2.44030930037 0.0 0.0 0.0 1.0
custom_string "hello world"
Output for the solution 2 is the same, minus the global_matrix.
Cheers,