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:
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:
downloader = SamDiagramDownloader(connector=sam_api_connector, project_id=project._id)
Download all diagrams#
Download all diagrams and save them into a ZIP archive:
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:
first_diagram = diagrams_info[0]
first_diagram_id = first_diagram["diagramId"]
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:
diagrams_info = sam_api_connector.get_diagrams_info(project._id)
Then iterate through the diagrams and download each one:
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']}")
Write data to your model
Find information