Exemplo n.º 1
0
def main():
    camera = tde4.getCurrentCamera()
    point_group = tde4.getCurrentPGroup()
    if camera is None or point_group is None:
        msg = 'There is no current Point Group or Camera.'
        tde4.postQuestionRequester(TITLE, msg, 'Ok')
        return

    # check if context menu has been used, and retrieve point...
    point = tde4.getContextMenuObject()
    if point is not None:
        # retrieve point's parent pgroup (not necessarily being the current one!)...
        point_group = tde4.getContextMenuParentObject()
        points = tde4.getPointList(point_group, 1)
    else:
        # otherwise use regular selection...
        points = tde4.getPointList(point_group, 1)
    if len(points) == 0:
        msg = 'There are no selected points.'
        tde4.postQuestionRequester(TITLE, msg, 'Ok')
        return

    # Generate file contents
    undistort = True
    start_frame = 1
    # Backwards compatibility with 3DE4 Release 2.
    if uvtrack_format.SUPPORT_CAMERA_FRAME_OFFSET is True:
        start_frame = tde4.getCameraFrameOffset(camera)
    data_str = uvtrack_format.generate(
        point_group, camera, points,
        start_frame=start_frame,
        undistort=undistort
    )

    # Write file.
    file_ext = EXT
    f = tempfile.NamedTemporaryFile(
        mode='w+b',
        bufsize=-1,
        suffix=file_ext,
        delete=False
    )
    if f.closed:
        msg = "Error: Couldn't open file.\n%r"
        msg = msg % f.name
        tde4.postQuestionRequester(TITLE, msg, 'Ok')
        return
    f.write(data_str)
    f.close()

    # Override the user's clipboard with the temporary file path.
    if uvtrack_format.SUPPORT_CLIPBOARD is True:
        tde4.setClipboardString(f.name)
    else:
        # Cannot set the clipboard, so we'll print to the Python Console
        # and the user can copy it. Pretty bad workaround.
        print f.name
    return
Exemplo n.º 2
0
def main():
    camera = tde4.getCurrentCamera()
    point_group = tde4.getCurrentPGroup()
    if camera is None or point_group is None:
        msg = 'There is no current Point Group or Camera.'
        tde4.postQuestionRequester(TITLE, msg, 'Ok')
        return

    # check if context menu has been used, and retrieve point...
    point = tde4.getContextMenuObject()
    if point is not None:
        # retrieve point's parent pgroup (not necessarily being the current
        # one!)...
        point_group = tde4.getContextMenuParentObject()
        points = tde4.getPointList(point_group, 1)
    else:
        # otherwise use regular selection...
        points = tde4.getPointList(point_group, 1)
    if len(points) == 0:
        msg = 'There are no selected points.'
        tde4.postQuestionRequester(TITLE, msg, 'Ok')
        return

    start, end, step = tde4.getCameraSequenceAttr(camera)
    start_frame = start
    # Backwards compatibility with 3DE4 Release 2.
    if SUPPORT_CAMERA_FRAME_OFFSET is True:
        start_frame = tde4.getCameraFrameOffset(camera)

    rs_enabled = False
    rs_distance = None
    # Backwards compatibility with 3DE4 Release 1.
    if SUPPORT_RS_ENABLED is True:
        rs_enabled = bool(tde4.getCameraRollingShutterEnabledFlag(camera))
    if rs_enabled is True:
        rs_distance = get_rs_distance(camera)
        if (SUPPORT_PROJECT_NOTES is True
                and SUPPORT_RS_DISTANCE is False):
            set_rs_distance_into_project_notes(rs_distance)

    # Generate file contents
    data_str = generate(
        point_group, camera, points,
        start_frame=start_frame,
        rs_distance=rs_distance,
        fmt=UV_TRACK_FORMAT_VERSION_PREFERRED
    )

    # Write file.
    file_ext = EXT
    # Prefix with the current time 'YYYY-MM-DD_HH_MM', for example
    # '2020-12-04_14_26'.
    now_str = time.strftime('%Y-%m-%d_%H_%M')
    prefix = 'tmp_{0}_'.format(now_str)
    f = tempfile.NamedTemporaryFile(
        mode='w',
        prefix=prefix,
        suffix=file_ext,
        delete=False
    )
    if f.closed:
        msg = "Error: Couldn't open file.\n%r"
        msg = msg % f.name
        tde4.postQuestionRequester(TITLE, msg, 'Ok')
        return
    f.write(data_str)
    f.close()

    # Override the user's clipboard with the temporary file path.
    if SUPPORT_CLIPBOARD is True:
        tde4.setClipboardString(f.name)
    else:
        # Cannot set the clipboard, so we'll print to the Python Console
        # and the user can copy it. Pretty bad workaround.
        print(f.name)
    return