ansys.dyna.core.lib.keyword_base.KeywordBase#

class ansys.dyna.core.lib.keyword_base.KeywordBase(**kwargs)#

Bases: ansys.dyna.core.lib.cards.Cards, ansys.dyna.core.lib.option_card.OptionsInterface

Base class for all keywords.

KeywordBase is the sole owner of option activation state (_active_options). Card-set items that inherit from Cards delegate option queries back to the keyword through _keyword.

Derived class must provide::
  • _cards

  • keyword

  • subkeyword

property user_comment: str#

Get or set the “user comment” for this keyword.

property deck: ansys.dyna.core.lib.deck.Deck | None#

Get the deck that this keyword is associated to.

property format: ansys.dyna.core.lib.format_type.format_type#

Get or set the format for this keyword.

is_option_active(option: str) bool#

Returns True if the given option is active.

activate_option(option: str) None#

Activate the given option.

deactivate_option(option: str) None#

Deactivate the given option.

get_option_spec(name: str) ansys.dyna.core.lib.option_card.OptionSpec#

Gets the option spec for the given name.

property option_specs: Iterable[ansys.dyna.core.lib.option_card.OptionSpec]#

Gets all option specs by scanning the card list.

get_title(format_symbol: str = '') str#

Get the title of this keyword.

property cards: List[ansys.dyna.core.lib.card_interface.CardInterface]#

Gets the cards of the keyword

property included_from: str#

Get the filename this was included from.

If the keyword was not read from a file, return None.

__repr__() str#

Returns a console-friendly representation of the keyword data as it would appear in the .k file

write(buf: TextIO | None = None, format: ansys.dyna.core.lib.format_type.format_type | None = None, deck_format: ansys.dyna.core.lib.format_type.format_type = format_type.default, retain_parameters: bool = False) str#

Renders the keyword in the dyna keyword format.

Parameters:
buf: IO

Optional - buffer to write to.

format: format_type, optional

Format to use for writing.

deck_format: format_type, optional

The deck’s format (used to determine if format symbol needed).

retain_parameters: bool, optional

If True, write original parameter references (e.g., &myvar) instead of substituted values for fields that were read from parameters. Default is False.

Returns:
_______
If buf is None, the output is returned as a str
dumps() str#

Return the string representation of the keyword.

before_read(buf: TextIO) None#

Run any pre-processing before reading the keyword.

read(buf: TextIO, parameters: ansys.dyna.core.lib.parameters.ParameterSet = None, import_context: ansys.dyna.core.lib.import_handler.ImportContext | None = None) None#

Read the keyword from a buffer.

Parameters:
buftyping.TextIO

Buffer to read from.

parametersParameterSet, optional

Parameter set for substitution.

import_contextImportContext, optional

Import context with file path and line number for warnings/errors.

loads(value: str, parameters: ansys.dyna.core.lib.parameters.ParameterSet = None, import_context: ansys.dyna.core.lib.import_handler.ImportContext | None = None) Any#

Load the keyword from string.

Return self to support chaining

Get all keywords referenced by this keyword.

Traverses the fields of this keyword that reference other keywords and returns the linked keyword objects from the parent deck.

Parameters:
link_typeLinkType, optional

Filter results by link type. If None or LinkType.ALL, returns all linked keywords. Otherwise, returns only keywords matching the specified link type.

levelint, default=1

Traversal depth. 1 returns only direct links (default), -1 traverses recursively without limit, 0 returns empty list, and any positive integer n traverses up to n levels deep.

_seenset, optional

Internal parameter for cycle prevention. Do not pass explicitly.

Returns:
List[KeywordBase]

List of referenced keyword objects. Returns an empty list if the keyword is not associated with a deck or if no links are found.

Examples

>>> mat = deck.keywords[0]  # A material keyword with curve references
>>> curves = mat.get_links(LinkType.DEFINE_CURVE)
>>> all_links = mat.get_links()  # Get all referenced keywords
>>> # Get full dependency tree
>>> all_deps = mat.get_links(level=-1)