OCC: interface to open-cascade
Preamble
OCC performs reading of IGES or STEP files with open-cascade. It returns a triangular mesh.
To use the module with the Converter.array interface:
import OCC
To use the module with the CGNS/Python interface:
import OCC.PyTree as OCC
List of functions
– CAD/surface mesh conversion
Convert a CAD (IGES or STEP) file to arrays. |
|
Convert a CAD (IGES or STEP) file to pyTree. |
– CAD manipulation
Read CAD file and return CAD hook. |
|
Write CAD file. |
|
Return the number of edges in CAD hook. |
|
Return the number of faces in CAD hook. |
|
Return the area of given faces. |
|
Translate all or given faces. |
|
Rotate all or given faces. |
|
Split all faces to be less than area. |
|
Merge some faces. |
Contents
CAD/mesh conversion
- OCC.convertCAD2Arrays(fileName, format='fmt_iges', h=0., chordal_err=0., growth_ratio=0., algo=1)
Read a CAD and return arrays.
- Parameters:
fileName (string) – CAD file name
format (string) – file format (‘fmt_iges’ or ‘fmt_step’)
h (float) – step size on output mesh. If 0., automatic setting [algo=1,2].
chordal_error (float) – max error between CAD and mesh. Result in curvature adaptation. If 0., automatic setting.
growth_ratio (float) – max growth ratio between adjacent triangles [algo=1,2].
algo (int) – algo=0: mesh with only respect to curvature, algo=1 or algo=2: mesh with regular triangles.
- Return type:
a list of TRI arrays
Example of use:
# - convertCAD2Arrays (arrays) - import Converter as C import OCC # IGES avec T3Mesher A = OCC.convertCAD2Arrays('hammer.iges', format='fmt_iges', h=0., chordal_err=0., growth_ratio=0.8, algo=1) C.convertArrays2File(A, 'hammer1.plt') # IGES avec OCC A = OCC.convertCAD2Arrays('hammer.iges', format='fmt_iges', chordal_err=1, algo=0) C.convertArrays2File(A, 'hammer2.plt') # STEP avec T3Mesher A = OCC.convertCAD2Arrays('as1-oc-214.stp', format='fmt_step', h=0., chordal_err=0., growth_ratio=0.8, algo=1) C.convertArrays2File(A, 'as1.plt') # STEP avec OCC A = OCC.convertCAD2Arrays('as1-oc-214.stp', format='fmt_step', chordal_err=1, algo=0) C.convertArrays2File(A, 'as2.plt')
- OCC.PyTree.convertCAD2PyTree(fileName, format='fmt_iges', h=0., chordal_err=0., growth_ratio=0., algo=1)
Read a CAD and return a zone.
- Parameters:
fileName (string) – CAD file name
format (string) – file format (‘fmt_iges’ or ‘fmt_step’)
h (float) – step size on output mesh. If 0., automatic setting [algo=1,2].
chordal_error (float) – max error between CAD and mesh. Result in curvature adaptation. If 0., automatic setting.
growth_ratio (float) – max growth ratio between adjacent triangles [algo=1,2].
algo (int) – algo=0: mesh with only respect to curvature, algo=1 or algo=2: mesh with regular triangles.
- Return type:
CGNS pyTree
Example of use:
# - convertIGES2PyTree (PyTree) - import OCC.PyTree as OCC import Converter.PyTree as C t = OCC.convertCAD2PyTree('hammer.iges', h=0., chordal_err=0., algo=1) C.convertPyTree2File(t, 'out.cgns')
CAD manipulation
- OCC.readCAD(fileName, format='fmt_step')
Read a CAD file and return a CAD hook.
- Parameters:
fileName (string) – CAD file name
format (string) – file format (‘fmt_iges’ or ‘fmt_step’)
- Return type:
CAD hook
Example of use:
# - readCAD (array) - import OCC hook = OCC.readCAD("cube.step", "fmt_step")
- OCC.writeCAD(hook, fileName, format='fmt_step')
Write a CAD hook to a file.
- Parameters:
hook (CAD hook) – CAD hook
fileName (string) – CAD file name
format (string) – file format (‘fmt_iges’ or ‘fmt_step’)
Example of use:
# - writeCAD (array) - import OCC hook = OCC.readCAD("cube.step", "fmt_step") OCC.writeCAD(hook, "out.step", "fmt_step")
- OCC.getNbEdges(hook)
Return the number of edges in a CAD hook.
- Parameters:
hook (CAD hook) – CAD hook
- Return type:
int
Example of use:
- OCC.getNbFaces(hook)
Return the number of faces in a CAD hook.
- Parameters:
hook (CAD hook) – CAD hook
- Return type:
int
Example of use:
- OCC._translate(hook, vector)
Translate a CAD hook by a given vector.
- Parameters:
hook (CAD hook) – CAD hook
vector (tuple of floats) – translation vector (dx, dy, dz)
Example of use:
# - translate (array) - import OCC hook = OCC.readCAD("cube.step", "fmt_step") OCC._translate(hook, (1,0,0)) OCC._translate(hook, (0,5,0), listFaces=[1]) OCC.writeCAD(hook, 'out.step', 'fmt_step')
- OCC._rotate(hook, Xc, axis, angle)
Rotate a CAD hook around a given axis by a given angle.
- Parameters:
hook (CAD hook) – CAD hook
Xc (tuple of floats) – rotation center (x, y, z)
axis (tuple of floats) – rotation axis
angle (float) – rotation angle in degrees
Example of use:
# - rotate (array) - import OCC hook = OCC.readCAD("cube.step", "fmt_step") OCC._rotate(hook, (0,0,0), (0,0,1), 30.) OCC._rotate(hook, (0,0,0), (0,0,1), 30., listFaces=[1]) OCC.writeCAD(hook, 'out.step', 'fmt_step')
- OCC._splitFaces(hook, area)
Split faces in a CAD hook.
- Parameters:
hook (CAD hook) – CAD hook
area (float) – split face if area greater than this value
Example of use:
# - splitFaces (array) - import OCC hook = OCC.readCAD("cube.step", "fmt_step") OCC._splitFaces(hook, 20.) OCC.writeCAD(hook, "out.step", "fmt_step")
- OCC._mergeFaces(hook, listFaces=[])
Merge faces in a CAD hook.
- Parameters:
hook (CAD hook) – CAD hook
listFaces (list of integers) – list of faces number to merge.
Example of use:
# - mergeFaces (array) - import OCC hook = OCC.readCAD("cube.step", "fmt_step") OCC._splitFaces(hook, 200.) # merge given faces OCC._mergeFaces(hook, [1,2,3]) # merge all faces OCC._mergeFaces(hook) OCC.writeCAD(hook, "out.step", "fmt_step")
- OCC.getFaceArea(hook, listFaces=[])
Return the area of given faces.
- Parameters:
hook (CAD hook) – CAD hook
listFaces (list of integers starting from 1) – list of faces number to calculate the area.
- Return type:
float
Example of use:
# - getFaceArea (array) - import OCC h = OCC.readCAD('cube.step', 'fmt_step') # Area of all model print(OCC.getFaceArea(h)) # Area of seome faces print(OCC.getFaceArea(h, [1,2]))