Model.feature_replace#

Model.feature_replace(source_collection, target_collection, double_array, tolerance, keep_source)#

Geometrically replaces a selection of surfaces with a second selection of surfaces, reconnecting the new surfaces to the rest of the original surfaces according to the original connections.

In this function, a part of the boundary of the source surfaces, after transformation by the input transformation matrix, is assumed to be matching with a part of the boundary of the target surfaces, within a given tolerance. This function checks and finds the matching boundary edges between the source and target surfaces. Then, the target surfaces are replaced by a transformed copy of the source surfaces. The connections with the other surfaces along the matching boundary are preserved according to the original connections. The new surfaces are put in the same component as the target surfaces. If some of the targetnsurfaces are part of a solid, those solids are recreated after replacement if the new configuration forms a closed volume/volumes that allow creation of solids. If the source surfaces contain solids, those solids are also maintained in the replacement.

Parameters:
  • source_collection (Collection) – The collection containing the source entities.

  • target_collection (Collection) – The collection containing the target entities.

  • double_array (hwDoubleList) – The double array ID that contains the 4x4 transformation matrix.

  • tolerance (double) – The tolerance used for edge stitching.

  • keep_source (int) –

    0 - Keep source surfaces after replacement.

    1 - Delete source surfaces after replacement.

Example#

Replace target surfaces with IDs 4, 19 and 25 with source surfaces with IDs 7, 9, 10, 33 and 34 with a tolerance of 0.5, and using a transformation matrix which is a translation of 20 units in the z-direction only#
import hm
import hm.entities as ent

model = hm.Model()

surfs1 = hm.Collection(model, ent.Surface, [7, 9, 10, 33, 34])
surfs2 = hm.Collection(model, ent.Surface, [4, 19, 25])

doublelist = [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 20.0, 1.0]

model.feature_replace(
  source_collection=surfs1,
  target_collection=surfs2,
  double_array=doublelist,
  tolerance=0.5,
  keep_source=0
)