您的位置:首页 > 编程语言 > Python开发

PythonOCC 3D图形库学习—导入STEP模型

2016-03-04 13:44 363 查看
PythonOCC comes with importers/exporters for the most commonly used standard data files format in engineering: STEP, IGES, STL (ascii/binary) and VRML. After the import is successfull, the resulting shape can be handled as a native topology/geometry, i.e. you can use boolean operations, shape fixing, traverse topology etc. PythonOCC中含有导入/导出模块,可以处理STEP,IGES,STL等格式的CAD模型.

STEP file is a CAD file format, usually used to share 3D models between users with different CAD systems. CAD file interchangeability is a huge, huge headache in the field, so it has to be make uniform. Standard ISO 10303 is trying to solve this problem. This standard is informally known as “STEP”, which stands for “Standard for the Exchange of Product model data”. STEP-file (ISO 10303-21) is implementation method of STEP standard that can represent 3D object in Computer-aided design (CAD) and related information.

各种CAD软件一般都使用自己定义的格式存储模型,因此造成数据交换困难,比如在UG里面创建的三维模型不能直接导入到Solidworks中。因此CAD数据交换标准之一的STEP格式被制定出来,使用任何的主流三维设计软件Peo/E、UG、CATIA、Solidworks等都可以直接打开STEP格式的文件(*.step, *.stp)

下面使用PythonOCC导入飞行器STEP格式的三维模型并显示出来(模型下载网址:https://grabcad.com/library):

'''
You can translate a STEP file into an OCCT shape in the following steps:
1.load the file,
2.check file consistency,
3.set the translation parameters,
4.perform the translation,
5.fetch the results.
'''

import sys
from OCC.Display.SimpleGui import init_display
from OCC.IFSelect import IFSelect_RetDone,IFSelect_ItemsByEntity

# Reads STEP files, checks them and translates their contents into Open CASCADE models
from OCC.STEPControl import STEPControl_Reader

# Creates a reader object with an empty STEP mode
step_reader = STEPControl_Reader()

# Loads a file and returns the read status
status = step_reader.ReadFile('Drone.step')

# check status
if status == IFSelect_RetDone:  # RetDone : normal execution with a result
# Checking the STEP file
# Error messages are displayed if there are invalid or incomplete STEP entities
step_reader.PrintCheckLoad(True, IFSelect_ItemsByEntity)

# Performing the STEP file translation
step_reader.TransferRoot()

# Each successful translation operation outputs one shape
# Returns the shape resulting from a translation
shape = step_reader.Shape()
else:
print("Error: can't read file.")
sys.exit(0)

# initializes the display
display, start_display, add_menu, add_function_to_menu = init_display()

# Then the shape is sent to the renderer
display.DisplayShape(shape, update=True)

# enter the gui mainloop
start_display()


苏30:



F-22 猛禽:



大疆phantom3:



参考:

http://www.opencascade.com/doc/occt-6.9.1/overview/html/occt__tutorial.html

http://www.opencascade.com/doc/occt-6.9.0/refman/html/class_s_t_e_p_control___reader.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: