Python API for Contact Creation

Sudhir_Ingstron
Altair Community Member
Once the set of elements is created with cardimage Surf, what is the python API equivalent of
*createentity groups cardimage=CONTACT includeid=0 name="group1"
Thank you
Sudhir
Tagged:
0
Answers
-
In 2025 there's pythonscript recorder:
import hm
import hm.entities as entdef run():
model = hm.Model()component = ent.Component(model, name="Rectangle.1")
model.ME_ModuleOccurrenceCreate(name="Rectangle.1", structural_type="part")
collection = hm.Collection(model, hm.FilterByEnumeration(ent.Component, ids=[component.id]))
model.markmovetomodule(collection=collection, module_name="Rectangle.1")
model.currentcollector(entity_type=ent.Component, name="Rectangle.1")
model.linecreatestraight(x1=-0.848400593, y1=8.19193363, z1=0, x2=-0.848400593, y2=2.10013908, z2=0)
model.linecreatestraight(x1=-0.848400593, y1=2.10013908, z1=0, x2=10.4172462, y2=2.10013908, z2=0)
model.linecreatestraight(x1=10.4172462, y1=2.10013908, z1=0, x2=10.4172462, y2=8.19193363, z2=0)
model.linecreatestraight(x1=10.4172462, y1=8.19193363, z1=0, x2=-0.848400593, y2=8.19193363, z2=0)
collection_1 = hm.Collection(model, hm.FilterByEnumeration(ent.Line, ids=[1, 2, 3, 4]))
model.deletemark(collection=collection_1)
model.linecreatestraight(x1=-0.848400593, y1=8.19193363, z1=0, x2=-0.848400593, y2=2.10013908, z2=0)
model.linecreatestraight(x1=-0.848400593, y1=2.10013908, z1=0, x2=10.4172462, y2=2.10013908, z2=0)
model.linecreatestraight(x1=10.4172462, y1=2.10013908, z1=0, x2=10.4172462, y2=8.19193363, z2=0)
model.linecreatestraight(x1=10.4172462, y1=8.19193363, z1=0, x2=-0.848400593, y2=8.19193363, z2=0)
model.surface_patch(line_collection=collection_1, tangency="non_tangent", stitch=True, dest_component="original")
model.surfacemode(mode=4)
model.deletemark(collection=collection_1)
model.set_flags_for_2dmesh_context(interactive=1)
# [TIP]: elementorder is deprecated. Activate 'Enable deprecated functions' to include them in the generated code.
# [ERROR]: model.elementorder(order=1)
model.setedgedensitylinkbytypeandaspectratio(type=0, aspect_ratio=-1)
collection_2 = hm.Collection(model, hm.FilterByEnumeration(ent.Surface, ids=[1]))
model.defaultremeshsurf(collection=collection_2, elem_size=2, elem_type=2, elem_type_2=2, previous_settings=2, comp_mode=1, size_control=1, skew_control=1, mesh_type=1, min_size=0, max_size=0, chordal_dev=0, max_angle=0)
model.set_flags_for_2dmesh_context(interactive=0)
model.setusefeatures(mode=0)
set = ent.Set(model, cardimage="SURF", name="set1")
collection_3 = hm.Collection(model, hm.FilterByEnumeration(ent.Element, ids=[11,12]+[*range(15,19)]))
model.segmentsetaddshells(name="set1", collection=collection_3, reverse_normals=0)
set_1 = ent.Set(model, cardimage="SURF", name="set2")
collection_4 = hm.Collection(model, hm.FilterByEnumeration(ent.Element, ids=[2,3]+[*range(6,10)]))
model.segmentsetaddshells(name="set2", collection=collection_4, reverse_normals=0)
group = ent.Group(model, cardimage="CONTACT", name="group1")
group.secondaryentityids = [set_1]
group.mainentityids = [set]2