SysMLTools#

class ansys.sam.sysml2.tools.sysmltools.SysMLTools#

Provides tools operating on SysML elements.

Overview#

isinstance

Check the type of an element.

serialize_expression

Render a value element to its text form.

get_element_visibility

Return the visibility of an element, read from its owning membership.

set_element_visibility

Set the visibility of an element on its owning membership.

parse_and_set_value

Parse an expression and set it as the feature’s value.

resolve_feature_chaining

Resolve a connection end within the connection’s own context.

get_connector_ends

Resolve both ends of a connector at once.

Import detail#

from ansys.sam.sysml2.tools.sysmltools import SysMLTools

Method detail#

static SysMLTools.isinstance(element, element_type: str) → bool#

Check the type of an element.

Parameters:
elementElement

Element to check.

element_typestr

SysML class name.

Returns:
bool

True if yes, False otherwise.

static SysMLTools.serialize_expression(value)#

Render a value element to its text form.

Parameters:
valueElement

Value element returned by get_value (a literal or an operator expression).

Returns:
str or None

The rendered text (for example "1 + 1" or "5 [kg]"), or None when value is None.

static SysMLTools.get_element_visibility(element)#

Return the visibility of an element, read from its owning membership.

Visibility lives on the membership that owns the element. That membership is an OwningMembership for most elements and a FeatureMembership for features, so this helper falls back to the owning feature membership when the generic owning membership is not set.

Parameters:
elementElement

Element whose visibility is read.

Returns:
VisibilityKind or None

The owning membership’s visibility, or None when the element has no owning membership.

static SysMLTools.set_element_visibility(element, visibility)#

Set the visibility of an element on its owning membership.

Visibility lives on the membership that owns the element (an OwningMembership for most elements, a FeatureMembership for features). This helper writes the value on that membership. Use get_element_visibility() to read it back.

Parameters:
elementElement

Element whose visibility is set.

visibilityVisibilityKind

New visibility value.

Raises:
AttributeError

If the element has no owning membership to store the value on.

static SysMLTools.parse_and_set_value(feature, expression: str)#

Parse an expression and set it as the feature’s value.

The text is sent as-is to the server, which builds the corresponding SysML v2 expression (for example a unit expression, an arithmetic expression, or a reference expression). Use serialize_expression() to render the resulting value element back to text.

Parameters:
featureElement

Feature whose value is set or updated.

expressionstr

Expression text to parse (for example "10 [m]" or "5 + 5").

static SysMLTools.resolve_feature_chaining(connection, end: str = 'source')#

Resolve a connection end within the connection’s own context.

Parameters:
connectionElement

Connection (or relationship) whose end is resolved.

endstr

Which end to resolve: "source" (default) or "target".

Returns:
Element or None

The resolved representative element, or None when the end or context is missing.

static SysMLTools.get_connector_ends(connection)#

Resolve both ends of a connector at once.

Parameters:
connectionElement

Connection (or relationship) whose ends are resolved.

Returns:
tuple

The resolved (source, target) representatives.