Skip to content

Diagrams

Generate program diagrams from the model, and place ready diagram images onto presentation sheets. generateProgram runs the model-based Program auto-generation (creating new sheets); place pastes ready-made images onto an existing sheet — it does not generate graphics itself. Adjacency data is read and computed via snaptrude.program.adjacency. Accessed via snaptrude.presentation.diagrams.

Both methods are host API calls that return a Promise and write to the Present canvas. generateProgram creates new layout sheets and returns their ids; place creates one canvas shape per image URL and returns the created shape ids.

At a glance

MethodWhat it doesMutates?
generateProgram()Auto-generate space + department diagrams into new sheets
place(sheetId, urls, options?)Drop diagram image URLs onto a sheet as canvas shapes

Present mode required

Both methods require Present mode (the documentation editor) to be open and throw otherwise.

No generateAdjacency

There is intentionally no generateAdjacency. The host's adjacency generator runs its sheet-creation task fire-and-forget internally, so a single call cannot return the sheets it creates. Use the Present-mode Adjacency menu for those, then place a pre-rendered adjacency image if you need it through the API.

Functions

generateProgram()

Generate the program (space + department) diagrams for the current model, creating new layout sheets. Runs the same auto-generation as the Present-mode Program action: reads the project's spaces and departments, lays them out to scale, and creates one or more new sheets holding the generated diagram graphics.

  • Parameters: none
  • Returns: { sheetIds: string[] } — ids of the sheets created by the generator.
  • Throws: If Present mode is not open, or the model has no spaces/departments to generate from.
ts
const { sheetIds } = await snaptrude.presentation.diagrams.generateProgram();
console.log(`Generated ${sheetIds.length} program sheet(s)`);

place(sheetId, urls, options?)

Place diagram images onto a sheet. Drops the given diagram image URLs onto the sheet and returns the ids of the created canvas shapes.

  • Parameters:
    • sheetId: string — the sheet to place onto
    • urls: string[] — diagram image URLs
    • options.position: { x: number; y: number } | undefined — where to place them, relative to the sheet (optional)
  • Returns: { shapeIds: string[] } — ids of the created canvas shapes.
  • Throws: If Present mode is not open or the sheet id is invalid.
ts
const { sheets } = await snaptrude.presentation.sheets.list();
const { shapeIds } = await snaptrude.presentation.diagrams.place(
  sheets[0].id,
  ["https://example.com/adjacency-diagram.png"],
  { position: { x: 0, y: 0 } }
);
console.log(`Placed ${shapeIds.length} diagram image(s)`);

Errors

Failed calls reject with a typed PluginError — see Error Handling. Conditions specific to this namespace:

CodeThrown byWhendetails
PRECONDITION_FAILEDgenerateProgramPresent mode is not open
PRECONDITION_FAILEDgenerateProgramThe model has no spaces or departments to generate from
OPERATION_FAILEDgenerateProgramThe model has content but no diagram sheets were created
PRECONDITION_FAILEDplacePresent mode is not open
HANDLE_INVALIDplacesheetId is unknown or is not a sheet (frame)
OPERATION_FAILEDplaceA diagram url could not be fetched (network/CORS)url — the unreachable url
OPERATION_FAILEDplaceNo canvas shapes were created — a url does not point to a supported image (svg/png/jpeg)urls