当前位置:首页>python>HyperView Python二次开发自动测量position和两点距离(安全带有效固定点到限制面距离)

HyperView Python二次开发自动测量position和两点距离(安全带有效固定点到限制面距离)

  • 2026-10-11 08:44:08
HyperView Python二次开发自动测量position和两点距离(安全带有效固定点到限制面距离)

「CAE仿真记」

愿与您一同,用代码提升效率!

座椅安全带固定点强度分析,需要测量安全带有效固定点是否落在限制面下方,如果前期建模没有集成限制面,可以直接测量安全带有效固定点z向position,然后与目标值比较,如果前期加入限制面,可以测量两点z向距离。

HyperView基于Tcl二次开发,测量节点位置,两点距离的实现方法如下:

Hyperview二次开发之测量(Position)
Hyperview二次开发之测量(Distance Between)
Hyperview二次开发之测量(Relative_angle)

HyperView基于Python二次开发,测量节点位置,两点距离的实现方法如下:

def measure_position (nodeid):    import hw    import hw.hv as hv    sess = hw.Session()# 获取当前激活的page    page = sess.get(hw.Page) # 获取当前激活的window    win = sess.get(hw.Window)# 获取当前激活的model    model = win.getActiveModel()# or model = sess.get(hv.Model)# 新建一个测量position类,并设置测量属性,测量节点,显示字体等    position = hv.MeasurePosition()    position_id = position.id    node_object = model.get(hv.Node,nodeid)    position.addEntities(node_object)    position.label               = 'Position'    position.displayLabel        = True    position.displayId           = True    position.color               = (255,0,0)    position.fontSize            = 8    position.numericFormat       = 'scientific'    position.numericPrecision    = 3    position.transparency        = True    position.autohide            = True    position.prefix              = True#   增加一个window 设置window类型为curve plot    page.setAttributes(layout = 1)    win2 = sess.get(hw.Window,window = 2)     win2.type = "xy"    hw.evalHWC(f'annotation measure curve measure={position_id} plot=w:2 livelink=true yaxis=X')def measure_distance (node1id,node2id):    import hw    import hw.hv as hv    sess = hw.Session()# 获取当前激活的page    page = sess.get(hw.Page) # 获取当前激活的window    win = sess.get(hw.Window)# 获取当前激活的model    model = win.getActiveModel()# or model = sess.get(hv.Model)# 新建一个测量距离类,并设置测量点,显示字体等属性    distance = hv.MeasureDistanceBetween()    distance_id = distance.id    node_1_object = model.get(hv.Node,node1id)    node_2_object = model.get(hv.Node,node2id)    distance.addEntities([node_1_object,node_2_object])    distance.label               = 'Distance Between'    distance.displayLabel        = True    distance.displayId           = True    distance.color               = (255,0,0)    distance.fontSize            = 8    distance.numericFormat       = 'scientific'    distance.numericPrecision    = 3    distance.transparency        = True    distance.autohide            = True    distance.prefix              = True    distance.displayX              = True    distance.displayY              = True    distance.displayZ              = True#   增加一个window 设置window类型为curve plot    page.setAttributes(layout = 1)    win2 = sess.get(hw.Window,window = 2)     win2.type = "xy"    hw.evalHWC(f'annotation measure curve measure={distance_id} plot=w:2 livelink=true yaxis=X')#def start_animation ():    import hw             import hw.hv as hv    ani = hw.AnimationTool()    ani.start(num_cycles = 1)def refresh_window ():    import hw    import hw.hv as hv    sess = hw.Session()    page = sess.get(hw.Page)     win = sess.get(hw.Window)    win.draw() # 代码只是说明方法,具体案例需要小修改
往期文章
HyperView 基于Tcl 二次开发常用功能合集
HyperView Python二次开发自动截图
Hyperview Python二次开发之模型分组并配色
Hyperview Python二次开发自动读取结果云图contour
10分钟快速了解HyperMesh Python 二次开发(附源码-创建一个4节点shell单元)
HyperMesh Python二次开发-自动修改Component名字

最新文章

随机文章