1 Star 0 Fork 1

kaohui/occ_example

forked from loujiand/occ_example 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
mytest_measure_niubi.py 1.13 KB
一键复制 编辑 原始数据 按行查看 历史
loujosh 提交于 2021-07-09 01:14 . Add files via upload
from OCC.Display.SimpleGui import init_display
from OCC.Core.TopoDS import topods_Edge
from OCC.Extend.DataExchange import read_step_file
display, start_display, add_menu, add_function_to_menu = init_display()
# loads and displays a step file
the_shape = read_step_file('SFU01610-4.step')
from OCC.Core.GProp import GProp_GProps
from OCC.Core.BRepGProp import brepgprop_LinearProperties,BRepGProp_EdgeTool,BRepGProp_EdgeTool_Value
def line_clicked(shp, *kwargs):
""" This function is called whenever a line is selected
"""
for shape in shp: # this should be a TopoDS_Edge
print("Edge selected: ", shape)
e = topods_Edge(shape)
props = GProp_GProps()
brepgprop_LinearProperties(e, props)
length = props.Mass()
print("此边的长度为: %f" % length)
centerMass = props.CentreOfMass()
print("此边的中心点为", centerMass.X(), centerMass.Y(), centerMass.Z())
display.DisplayShape(the_shape, update=True)
display.SetSelectionModeEdge() # switch to edge selection mode
display.register_select_callback(line_clicked)
start_display()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/kaohui/occ_example.git
[email protected]:kaohui/occ_example.git
kaohui
occ_example
occ_example
main

搜索帮助