ansys.dyna.core.lib.card.Card#

class ansys.dyna.core.lib.card.Card(fields: List[ansys.dyna.core.lib.field.Field], active_func: Callable = None, format: ansys.dyna.core.lib.format_type.format_type = format_type.default)#

Bases: ansys.dyna.core.lib.card_interface.CardInterface

A Card represents a single line of data in a keyword.

This implementation separates schema (shared) from values (per-instance) for memory efficiency and faster loading of keywords with many cards.

classmethod from_field_schemas(field_schemas: Tuple[ansys.dyna.core.lib.field_schema.FieldSchema, Ellipsis], values: List[Any] | None = None, active_func=None, format=format_type.default) Card#

Create a Card directly from FieldSchema tuples (no Field objects).

This is the fast path for creating Cards when the schema is already defined at the class level. It avoids creating Field objects entirely.

Parameters:
field_schemasTuple[FieldSchema, …]

Tuple of FieldSchema (should be defined at class level for reuse).

valuesList[Any], optional

Initial values for each field. If None, uses defaults from schema.

active_funccallable(), optional

A function returning bool to determine if card is active.

formatformat_type, optional

The format type (default, standard, or long).

Returns:
Card

A new Card instance.

classmethod from_field_schemas_with_defaults(field_schemas: Tuple[ansys.dyna.core.lib.field_schema.FieldSchema, Ellipsis], active_func=None, format=format_type.default, **kwargs) Card#

Create a Card from FieldSchema tuples with kwargs defaults (lspp_defaults).

This is like from_field_schemas but applies lspp_defaults logic: - If use_lspp_defaults() is True: look up value in kwargs by field name,

falling back to the schema default.

  • If use_lspp_defaults() is False: all fields are None.

Parameters:
field_schemasTuple[FieldSchema, …]

Tuple of FieldSchema (should be defined at class level for reuse).

active_funccallable(), optional

A function returning bool to determine if card is active.

formatformat_type, optional

The format type (default, standard, or long).

**kwargs

Field values by name (lspp_defaults style).

Returns:
Card

A new Card instance.

property format#

Field width format (default, standard, or long).

read(buf: TextIO, parameter_set: ansys.dyna.core.lib.parameters.ParameterSet = None) bool#

Reads the card from the given buffer.

write(format: ansys.dyna.core.lib.format_type.format_type | None = None, buf: TextIO | None = None, comment: bool | None = True, output_format: str | None = None, retain_parameters: bool = False, parameter_set: ansys.dyna.core.lib.parameters.ParameterSet | None = None, uri_prefix: str | None = None) str | None#

Write the card to a buffer or return as string.

Parameters:
formatformat_type, optional

Field width format (default, standard, or long).

bufTextIO, optional

Buffer to write to. If None, returns the output as a string.

commentbool, optional

Whether to include the comment line with field names. Default is True.

output_formatstr, optional

Card serialization format: card_format.fixed or card_format.csv. If None (default), uses fixed unless the card was originally read as csv.

retain_parametersbool, optional

If True, write original parameter references instead of values.

parameter_setParameterSet, optional

The parameter set to use for looking up stored refs.

uri_prefixstr, optional

The URI prefix for this card (e.g., “12345/card0”) for ref lookup.

Returns:
str or None

The card as a string if buf is None, otherwise None.

property active: bool#

Get whether the card is active.

get_value(prop: str) Any#

Get the value of a field by name.

Parameters:
propstr

The field name.

Returns:
Any

The field value.

set_value(prop: str, value: Any) None#

Set the value of a field by name.

Parameters:
propstr

The field name.

valueAny

The value to set.

has_nondefault_values() bool#

Check if any field in this card has been explicitly set.

This method returns True if any field has been set via set_value(), which is typically called by property setters on keyword classes. It is used for cascading card activation, where optional cards become active when any of their fields are explicitly set.

Returns:
bool

True if at least one field has been explicitly set, False otherwise.

__repr__() str#

Returns a console-friendly representation of the card.