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.CardInterfaceA 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_schemas
Tuple[FieldSchema, …] Tuple of FieldSchema (should be defined at class level for reuse).
- values
List[Any],optional Initial values for each field. If None, uses defaults from schema.
- active_func
callable(),optional A function returning bool to determine if card is active.
- format
format_type,optional The format type (default, standard, or long).
- field_schemas
- Returns:
CardA 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_schemas
Tuple[FieldSchema, …] Tuple of FieldSchema (should be defined at class level for reuse).
- active_func
callable(),optional A function returning bool to determine if card is active.
- format
format_type,optional The format type (default, standard, or long).
- **kwargs
Field values by name (lspp_defaults style).
- field_schemas
- Returns:
CardA 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:
- format
format_type,optional Field width format (default, standard, or long).
- buf
TextIO,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_format
str,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_set
ParameterSet,optional The parameter set to use for looking up stored refs.
- uri_prefix
str,optional The URI prefix for this card (e.g., “12345/card0”) for ref lookup.
- format
- Returns:
- get_value(prop: str) Any#
Get the value of a field by name.
- Parameters:
- prop
str The field name.
- prop
- Returns:
AnyThe field value.
- set_value(prop: str, value: Any) None#
Set the value of a field by name.
- Parameters:
- prop
str The field name.
- value
Any The value to set.
- prop
- 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.