recursive_copy#
- ansys.acp.core.recursive_copy(*, source_objects, parent_mapping, linked_object_handling='keep')#
Recursively copy a tree of ACP objects.
This function copies a tree of ACP objects, starting from the given source objects. The copied tree includes all child objects. Linked objects (such as a Fabric linked to by a Modeling Ply) can optionally be included, controlled by the
linked_object_handling
argument.To specify where the new objects should be stored, you must provide a dictionary in the
parent_mapping
argument. The keys of the dictionary are the original parent objects, and the values are the new parent objects. Note that this mapping may need to contain parent objects that are not direct parents of the source objects, if another branch of the tree is included via linked objects.The
parent_mapping
argument can also include objects which are part of thesource_objects
list. In this case, the function will not create a new object for the parent, but will use the existing object instead.The function returns a
dict
mapping the original objects to the newly created objects.Note
Only attributes supported by PyACP are copied to the new objects.
- Parameters:
source_objects (Iterable[CreatableTreeObject]) – The starting point of the tree to copy.
parent_mapping (dict[TreeObject, TreeObject]) – A list of tuples defining where the new objects are stored. Each tuple contains the original parent object as the first element and the new parent object as the second element.
linked_object_handling (LinkedObjectHandling | str) –
Defines how linked objects are handled. An example of a linked object is a Fabric linked to by a Modeling Ply.
The following options are available:
"keep"
: Keep linking to the original objects, and do not copy them (unless they are otherwise included in the tree)."copy"
: Copy the linked objects, and replace the links."discard"
: Discard object links.
Note that when copying objects between two models, only the
"copy"
and"discard"
options are valid. If you wish to use links to existing objects, the"copy"
option can be used, specifying how links should be replaced in theparent_mapping
argument.
- Returns:
A mapping of the newly created objects. The keys are the original objects, and the values are the new objects.
- Return type:
Examples
To copy all Modeling Groups and associated definitions from one model to another, you can use the following code:
import ansys.acp.core as pyacp model1 = ... # loaded in some way model2 = ... # loaded in some way pyacp.recursive_copy( source_objects=model1.modeling_groups.values(), parent_mapping={model1: model2}, linked_object_handling="copy", )
To copy all definitions from one model to another, you can use the following code:
import ansys.acp.core as pyacp model1 = ... # loaded in some way model2 = ... # loaded in some way pyacp.recursive_copy( source_objects=[model1], parent_mapping={model1: model2}, linked_object_handling="copy", )