PythonOCC 3D圖形庫學習—導入STEP模型


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):

 1 '''
 2 You can translate a STEP file into an OCCT shape in the following steps:
 3  1.load the file,
 4  2.check file consistency,
 5  3.set the translation parameters,
 6  4.perform the translation,
 7  5.fetch the results.
 8 '''
 9 
10 import sys
11 from OCC.Display.SimpleGui import init_display
12 from OCC.IFSelect import IFSelect_RetDone,IFSelect_ItemsByEntity
13 
14 # Reads STEP files, checks them and translates their contents into Open CASCADE models
15 from OCC.STEPControl import STEPControl_Reader
16 
17 
18 # Creates a reader object with an empty STEP mode
19 step_reader = STEPControl_Reader()
20 
21 # Loads a file and returns the read status
22 status = step_reader.ReadFile('Drone.step')
23 
24 # check status 
25 if status == IFSelect_RetDone:  # RetDone : normal execution with a result
26     # Checking the STEP file
27     # Error messages are displayed if there are invalid or incomplete STEP entities
28     step_reader.PrintCheckLoad(True, IFSelect_ItemsByEntity)
29 
30     # Performing the STEP file translation
31     step_reader.TransferRoot()
32 
33     # Each successful translation operation outputs one shape
34     # Returns the shape resulting from a translation
35     shape = step_reader.Shape()
36 else:
37     print("Error: can't read file.")
38     sys.exit(0)
39           
40 # initializes the display
41 display, start_display, add_menu, add_function_to_menu = init_display()
42 
43 # Then the shape is sent to the renderer
44 display.DisplayShape(shape, update=True)
45 
46 # enter the gui mainloop
47 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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM