Data panel

Export Viewpoints

Every saved viewpoint to a CSV: name, folder, type and camera position.

On the ribbonButton, Data panel
NeedsSaved viewpoints in the document

What it does#

Writes every saved viewpoint in the document to a CSV file with the columns Name, Folder, Type, CameraX, CameraY and CameraZ. For an audit of what a model's saved views actually are, or to diff two issues of the same model.

How to use it#

  1. Click Export Viewpoints.
  2. Choose where to save. The name offered is the document's title plus _viewpoints.csv.

Limitations#

  • Animations and cuts have no camera of their own, so those rows are written with the three position columns blank rather than dropped.
  • Camera position only. Direction, section planes and hidden items are not exported; use Copy State to carry those.

Other uses#

  • Compare two exports in a spreadsheet to see which views were added, renamed or moved between issues.

Source#

The tool's own files, word for word as shipped in Data.panel/Export_Viewpoints_CSV.pushbutton. Every pyNavis tool is an ordinary bundle: copy these into your own extension and change what you like.

script.py Runs on a click. View on GitHub
"""Exports every saved viewpoint (name, folder, camera position) to a CSV file."""

import csvexport

from pynavis import doc, forms, toast


def row_for(folders, item):
    # the saved-viewpoints tree also holds animations/cuts, which
    # have no camera - export them with empty position columns
    viewpoint = getattr(item, 'Viewpoint', None)
    position = getattr(viewpoint, 'Position', None)
    return [
        item.DisplayName,
        '/'.join(folders),
        item.GetType().Name,
        '%.6f' % position.X if position is not None else '',
        '%.6f' % position.Y if position is not None else '',
        '%.6f' % position.Z if position is not None else '',
    ]


items = list(doc.walk_saved_viewpoints())
if not items:
    forms.alert('This document has no saved viewpoints.')
else:
    default_name = (doc.get_title() or 'viewpoints') + '_viewpoints.csv'
    path = forms.save_file(default_name=default_name, title='Export viewpoints CSV')
    if path is not None:
        rows = csvexport.write_rows(
            path, ['Name', 'Folder', 'Type', 'CameraX', 'CameraY', 'CameraZ'],
            (row_for(folders, item) for folders, item in items))
        toast.success('Exported %d saved item(s)' % rows, path)
bundle.yaml The bundle contract: the keys pyNavis reads for this tool. View on GitHub
title: Export\nViewpoints