View, Node & Connection

This module contains the visual-representation layer of pyArchimate:

  • View – a named diagram that belongs to a Model.

  • Node – the visual representation of an Element inside a View.

  • Connection – the visual representation of a Relationship inside a View.

  • Profile, Point, Position – supporting geometry types.

Module contents

Modern implementations of View, Node, Connection, Profile, Point, and Position.

All classes are self-contained and carry no dependency on the legacy module.

class pyArchimate.view.Connection(ref=None, source=None, target=None, uuid=None, parent=None)[source]

Bases: object

A visual connection between two Nodes, backed by a Relationship.

Parameters:
  • ref – Relationship identifier or Relationship-like object (duck-typed)

  • source – source Node identifier or Node object

  • target – target Node identifier or Node object

  • uuid – connection identifier

  • parent – parent View

property access_type: str | None

Access type (for Access relationships).

add_bendpoint(*bendpoints: Point) None[source]

Add one or more bendpoints to this connection.

property concept

Referenced Relationship object.

del_bendpoint(index: int) None[source]

Delete bendpoint at specified index.

delete() None[source]

Remove this connection from view and model.

get_all_bendpoints() list[Point][source]

Get all bendpoints.

get_bendpoint(index: int) Point | None[source]

Get bendpoint at specified index.

property influence_strength: str | None

Influence strength (for Influence relationships).

property is_directed: bool

Whether relationship is directed.

l_shape(direction=0, weight_x=0.5, weight_y=0.5)[source]

Shape the connection as an L (one bendpoint).

property name: str | None

Relationship name.

property ref: str

Relationship reference identifier.

remove_all_bendpoints() None[source]

Remove all bendpoints.

s_shape(direction=0, weight_x=0.5, weight_y=0.5, weight2=0.5)[source]

Shape the connection as an S (two bendpoints).

set_bendpoint(bp: Point, index: int) None[source]

Replace bendpoint at specified index.

property source: Node | None

Source node (None if deleted).

property target: Node | None

Target node (None if deleted).

property type: str

ArchiMate relationship type.

property uuid: str

Unique identifier for this connection.

class pyArchimate.view.Node(ref=None, x=0, y=0, w=120, h=55, uuid=None, node_type='Element', label=None, parent=None)[source]

Bases: object

A visual node in a View, representing an Element concept.

Parameters:
  • ref – Element identifier or Element object

  • x – top-left x coordinate

  • y – top-left y coordinate

  • w – width

  • h – height

  • uuid – node identifier

  • node_type – one of β€˜Element’, β€˜Label’, β€˜Container’

  • label – label text (for Label/Container nodes)

  • parent – parent View or parent Node

add(ref=None, x=0, y=0, w=120, h=55, uuid=None, node_type='Element', label=None, nested_rel_type=None)[source]

Create and return a child node embedded in this node.

property concept: Element | None

Referenced Element object.

conns(rel_type=None)[source]

Return connections to/from this node, optionally filtered by type.

property cx: float

Center x coordinate.

property cy: float

Center y coordinate.

delete(recurse=True, delete_from_model=False)[source]

Delete this node and its related connections.

property desc: str | None

Description of referenced element.

distribute_connections()[source]

Redistribute all connections evenly along each edge of this node.

property fill_color: str | None

Fill color in hex format.

get_obj_pos(other_node: Node) Position[source]

Return a Position describing this node’s relationship to another.

get_or_create_node(elem=None, elem_type=None, x=0, y=0, w=120, h=55, create_elem=False, create_node=False, nested_rel_type=None)[source]

Return an existing child node or create one if requested.

get_point_pos(point: Point) Position[source]

Return positional relationship between this node and a point.

getnodes(elem_type: str | None = None) list[Node][source]

Get child nodes filtered by element type.

property h: int

Height.

in_conns(rel_type: str | None = None) list[Connection][source]

Incoming connections (this node as target), optionally filtered by type.

is_inside(x: float = 0, y: float = 0, point: Point | None = None) bool[source]

Return True if the (x,y) point lies within this node’s bounding box.

property model: Model

Associated Model.

move(new_parent)[source]

Reparent this node to a different Node or View within the same diagram.

property name: str | None

Name of referenced element (if Element node).

property nodes: list[Node]

Child nodes.

out_conns(rel_type: str | None = None) list[Connection][source]

Outgoing connections (this node as source), optionally filtered by type.

property ref: str | None

Element reference identifier.

resize(max_in_row=3, keep_kids_size=True, w=120, h=55, gap_x=20, gap_y=20, justify='left', recurse=False, sort='asc')[source]

Resize this node to fit all embedded children.

property rx: float

Relative x coordinate (relative to parent).

property ry: float

Relative y coordinate (relative to parent).

property type: str | None

ArchiMate type of referenced element.

property uuid: str

Unique identifier for this node.

property view: View

Parent View.

property w: int

Width.

property x: int

Top-left x coordinate.

property y: int

Top-left y coordinate.

class pyArchimate.view.Point(x: float = 0, y: float = 0, start_x: int | None = None, start_y: int | None = None, end_x: int | None = None, end_y: int | None = None)[source]

Bases: object

A simple (x, y) coordinate pair stored as floats for lossless round-trips.

Archi’s native format encodes bendpoints as integer offsets from element centres; those centres can be half-integers (e.g. element height 55 β†’ cy = y + 27.5). Storing the resolved absolute coordinate as a float preserves the value so that round(bp.x - cx) reproduces the original integer offset exactly during export.

property x: float

X coordinate.

property y: float

Y coordinate.

class pyArchimate.view.Position[source]

Bases: object

Positional relationship between two nodes (distance, angle, orientation).

property dist: float | None

Euclidean distance between nodes.

class pyArchimate.view.Profile(name=None, uuid=None, concept=None, model=None)[source]

Bases: object

An Archimate stereotype / specialisation profile for elements or relationships.

delete()[source]

Remove this profile and clear all references to it from elements and relationships.

property uuid: str

Unique identifier for this profile.

class pyArchimate.view.View(name=None, uuid=None, desc=None, folder=None, parent=None)[source]

Bases: object

A diagram (view) in an Archimate model containing Nodes and Connections.

Parameters:
  • name – view name

  • uuid – view identifier

  • desc – description

  • folder – folder path for organisation hierarchy

  • parent – parent Model object (duck-typed: must have views_dict)

add(ref: object = None, x: int = 0, y: int = 0, w: int = 120, h: int = 55, uuid: str | None = None, node_type: str = 'Element', label: str | None = None) Node[source]

Add and return a Node in this view.

add_connection(ref: object = None, source: object = None, target: object = None, uuid: str | None = None) Connection[source]

Add and return a Connection between two Nodes.

property conns: list[Connection]

All connections in this view.

delete() None[source]

Remove this view and all its nodes and connections.

duplicate(name: str | None = None) View[source]

Create independent deep copy of this view registered in same model.

Parameters:

name – Name for duplicated view. If None, appends β€œ (copy)” to original name.

Returns:

New View object with deep-copied nodes and connections.

Raises:

ValueError – If view has no parent model (cannot register duplicate).

get_or_create_connection(rel: object = None, source: Node | None = None, target: Node | None = None, rel_type: str | None = None, name: str | None = None, create_conn: bool = False) Connection | None[source]

Return an existing connection or create one if requested.

get_or_create_node(elem: object = None, elem_type: str | None = None, x: int = 0, y: int = 0, w: int = 120, h: int = 55, create_elem: bool = False, create_node: bool = False) Node | None[source]

Return an existing node for the element, or create one if requested.

property nodes: list[Node]

All nodes in this view.

property primary_viewpoint: str | None

Return the primary viewpoint slug for this view.

Returns:

canonical viewpoint slug or None

Return type:

str | None

prop(key: str, value: object = None) object[source]

Get or set a custom property.

property props: dict[str, object]

Custom properties dictionary.

remove_folder() None[source]

Clear the folder path.

remove_prop(key: str) None[source]

Remove a custom property.

set_primary_viewpoint(viewpoint_id: str) None[source]

Set the primary viewpoint slug for this view.

Parameters:

viewpoint_id (str) – canonical viewpoint slug (e.g. β€˜technology’)

Raises:

ValueError – if viewpoint_id is not a recognised slug

to_svg(filepath: str | None = None) str[source]

Export view to SVG string and optionally write to file.

Parameters:

filepath – Optional path to write SVG file to. If provided, SVG is written to this file path. If None, only the SVG string is returned.

Returns:

SVG string (valid XML with <svg> root element)

property type: str

Type identifier (always β€˜Diagram’).

property uuid: str

Unique identifier for this view.

property view: View

Reference to self (for API compatibility).

pyArchimate.view.default_color(elem_type: str, theme: str | dict[str, str] | None = 'archi') str[source]

Return the default fill colour for a node, keyed by Archimate element type.