py3dframe.Frame.to_json#

Frame.to_json(filename)[source]#

Save the Frame object to a JSON file.

See also

  • method to_dict() to save the Frame object to a dictionary.

Warning

  • parent frame is not saved (only local frame is saved), so the loaded frame must be reattached to the parent frame if needed. (See also FrameTree to save/load a system of frames).

Parameters:

filename (str) – The name of the JSON file.

Return type:

None

Examples

Create a Frame object and save it to a JSON file using the default method (quaternion, rotation_vector, rotation_matrix):

from py3dframe import Frame
frame = Frame.from_axes(origin=[1, 2, 3], x_axis=[1, 0, 0], y_axis=[0, 1, 0], z_axis=[0, 0, 1], convention=0)
frame.to_json("frame.json")

# Reload the Frame object from the JSON file:

loaded_frame = Frame.from_json("frame.json")

Warning, the method no longer saves the parent frame. To save/load a system of frames, consider using the FrameTree class.

from py3dframe import Frame

parent = Frame.from_axes(origin=[0, 0, 0], x_axis=[1, 0, 0], y_axis=[0, 1, 0], z_axis=[0, 0, 1], convention=0)
child = Frame.from_axes(origin=[1, 0, 0], x_axis=[1, 0, 0], y_axis=[0, 1, 0], z_axis=[0, 0, 1], convention=0, parent=parent)

child.to_json("child_frame.json")
parent.to_json("parent_frame.json")

# Reload the frames from the JSON files

loaded_parent = Frame.from_json("parent_frame.json")
loaded_child = Frame.from_json("child_frame.json")
loaded_child.parent = loaded_parent # IMPORTANT