Element Class API Referenceο
Note
βοΈ New to this topic? Start with Visual Styling and Junction Types to understand element styling and junction semantics before diving into the API details.
The Element class represents ArchiMate elements with support for element hierarchy (parent-child relationships), visual styling, and junction type semantics.
Visual Styling Methodsο
Color Propertiesο
- set_fill_color(color: str | None) Noneο
Set the fill/background color of this element.
- Parameters:
color (Optional[str]) β Hex color (#RRGGBB), named color (e.g., βredβ, βblueβ), or None to use default
- Raises:
ValueError β If color format is invalid
Supported Named Colors: red, green, blue, yellow, orange, purple, pink, brown, gray, white, black
Example:
elem = model.add(ArchiType.BusinessProcess, 'Process') elem.set_fill_color('#ff0000') # Hex color elem.set_fill_color('red') # Named color elem.set_fill_color(None) # Reset to default
- get_fill_color() str | Noneο
Get the fill color of this element.
- Returns:
Hex color (#rrggbb) or None if not set
- Return type:
Optional[str]
- set_line_color(color: str | None) Noneο
Set the border/line color of this element.
- Parameters:
color (Optional[str]) β Hex color (#RRGGBB), named color, or None to use default
- Raises:
ValueError β If color format is invalid
Example:
elem.set_line_color('#0066cc') elem.set_line_color('blue')
- get_line_color() str | Noneο
Get the line color of this element.
- Returns:
Hex color (#rrggbb) or None if not set
- Return type:
Optional[str]
Line Width Propertyο
- set_line_width(width: float | None) Noneο
Set the border/line width of this element in pixels.
- Parameters:
width (Optional[float]) β Width in pixels (β₯ 0), or None to use default
- Raises:
ValueError β If width is negative
TypeError β If width is not numeric
Example:
elem.set_line_width(2.0) # 2 pixel border elem.set_line_width(0.5) # 0.5 pixel border elem.set_line_width(None) # Reset to default
- get_line_width() float | Noneο
Get the line width of this element.
- Returns:
Width in pixels or None if not set
- Return type:
Optional[float]
Transparency Propertyο
- set_transparency(alpha: float | None) Noneο
Set the opacity/transparency of this element.
- Parameters:
alpha (Optional[float]) β Opacity 0.0 (fully transparent) to 1.0 (fully opaque), or None to use default
- Raises:
ValueError β If alpha is out of range
TypeError β If alpha is not numeric
Example:
elem.set_transparency(1.0) # Fully opaque elem.set_transparency(0.5) # 50% transparent elem.set_transparency(0.0) # Fully transparent elem.set_transparency(None) # Reset to default
- get_transparency() float | Noneο
Get the transparency/opacity of this element.
- Returns:
Opacity 0.0-1.0 or None if not set
- Return type:
Optional[float]
Bulk Style Operationsο
- set_visual_style(fill_color: str | None = None, line_color: str | None = None, line_width: float | None = None, transparency: float | None = None) Noneο
Set multiple visual style properties at once.
- Parameters:
fill_color β Fill color (hex or named)
line_color β Line color (hex or named)
line_width β Line width in pixels (β₯ 0)
transparency β Opacity 0.0-1.0
- Raises:
ValueError β If any property is invalid
Example:
elem.set_visual_style( fill_color='#ffeb3b', line_color='#ff6f00', line_width=2.0, transparency=0.9 )
- get_visual_style() dict[str, Any]ο
Get all visual style properties as a dictionary.
- Returns:
Dictionary with fillColor, lineColor, lineWidth, transparency (only set values)
- Return type:
dict[str, Any]
Example:
style = elem.get_visual_style() # Returns: {'fillColor': '#ffeb3b', 'lineColor': '#ff6f00', 'lineWidth': 2.0, 'transparency': 0.9}
- reset_visual_style() Noneο
Reset all custom visual styles to defaults.
Example:
elem.reset_visual_style() # Clear all custom styles
Junction Type Methodsο
- set_junction_type(junction_type: str | None) Noneο
Set the junction type for a Junction element.
- Parameters:
junction_type (Optional[str]) β Junction type (βandβ, βorβ, βxorβ) or None
- Raises:
ValueError β If junction_type is not valid
Valid Junction Types: - βandβ: All inputs must be satisfied - βorβ: At least one input must be satisfied - βxorβ: Exactly one input must be satisfied
Example:
junction = model.add(ArchiType.Junction, 'Decision Point') junction.set_junction_type('and') junction.set_junction_type('xor') junction.set_junction_type(None) # Clear junction type
- get_junction_type() str | Noneο
Get the junction type for a Junction element.
- Returns:
Junction type (βandβ, βorβ, βxorβ) or None if not set
- Return type:
Optional[str]
Example:
jtype = junction.get_junction_type() if jtype == 'and': print("AND junction - all inputs required")
Hierarchy Methodsο
Parent-Child Relationshipsο
The Element class stores its parent UUID reference. Use Model methods for full hierarchy management:
element._parent_uuid: Internal reference to parent element UUID (read-only)
Use Model.add_child() to create relationships and Model.get_parent() to query.
See Element Hierarchies for hierarchy usage guide.
Round-Trip Preservationο
All visual properties and junction types are automatically preserved during XML export/import cycles.
Note
The examples below are validated by review (not make doctest) because they interact with
the file system in ways that vary by environment. The getting-started.rst and
api/model.rst round-trip examples are validated by Sphinx doctest (make doctest).
# Create and style element
elem = model.add(ArchiType.BusinessProcess, 'Process')
elem.set_fill_color('#ff0000')
elem.set_transparency(0.8)
# Export to XML
model.write('model.archimate')
# Import from XML
m2 = Model('reloaded')
m2.read('model.archimate')
# Properties are preserved exactly
elem2 = m2.elems_dict[elem.uuid]
assert elem2.get_fill_color() == '#ff0000'
assert elem2.get_transparency() == 0.8
See Alsoο
Visual Styling: Complete guide for visual customization
Junction Types: Junction type semantics and usage
Visual Styling Code Examples: Code examples for visual styling