Work with diagrams#

Warning

Functionalities for downloading diagrams are available only for projects of type SAM.

This page explains how to download diagrams from your SysML v2 project using the SAM API.

Download diagrams#

Before downloading diagrams, create a SamApiConnector:

Create a SAM API connector#
sam_api_connector = SamApiConnector(
    server_url="<SAM Server URL>",  # Your SAM server base URL
    token="<Token>",  # Your authorization token
    use_ssl=False,  # If the server hasn't a valid SSL
)

Then instantiate a SamDiagramDownloader object:

Create a SAM diagram downloader#
downloader = SamDiagramDownloader(connector=sam_api_connector, project_id=project._id)

Download all diagrams#

Download all diagrams and save them into a ZIP archive:

Download all diagrams with custom parameters#
path = downloader.download_all_diagrams(
    path=SAVE_IMAGE_PATH,
    file_format="jpeg",
    filename="download_all_diagrams_with_args.zip",
)
print(f"ZIP saved at: {path}\n")

Default parameters

If you do not specify parameters, these defaults are used to format and name your download archive:

  • file_format: "SVG"

  • filename: "<PackageName>_<FileFormat>_diagrams.zip"

Get and download a single diagram#

List the available diagrams with get_diagrams_info, pick one, and download it in a given format:

Get a single diagram identifier#
first_diagram = diagrams_info[0]
first_diagram_id = first_diagram["diagramId"]
Download this single diagram#
path = downloader.download_diagram(
    diagram_id=first_diagram_id,
    path=SAVE_IMAGE_PATH,
    file_format="svg",
)
print(f"Diagram saved at: {path}")

Download diagrams in a loop#

Retrieve the diagram information for the project:

Get the diagrams information#
diagrams_info = sam_api_connector.get_diagrams_info(project._id)

Then iterate through the diagrams and download each one:

Download diagrams in a loop#
for i, diagram in enumerate(diagrams_info, 1):
    downloader.download_diagram(
        diagram_id=diagram["diagramId"], file_format="png", path=SAVE_IMAGE_PATH + "/all"
    )
    print(f"> Saved diagram #{i}: {diagram['name']}")
Previous step

Write data to your model

Write data to your model
Next step

Find information

Find information