示例#1
0
from __future__ import print_function

import logging

from OCC.Display import SimpleGui
from OCCUtils import Topo

from OCCDataExchange.iges import IgesImporter
from OCCDataExchange import path_from_file

logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s :: %(levelname)6s :: %(module)20s :: %(lineno)3d :: %(message)s')
display, start_display, add_menu, add_function_to_menu = SimpleGui.init_display()

# my_iges_importer = occaddons.dataexchange.iges.IgesImporter("../../data/IGES/splines.igs")
filename = path_from_file(__file__, "./models_in/iges/2_boxes.igs")
iges_importer = IgesImporter(filename)

the_shapes = iges_importer.shapes

print(iges_importer.nb_shapes)  # 13
print(len(iges_importer.shapes))  # 13

# display.DisplayShape(iges_importer.compound)

# there are no shells or solids in the compound (IGES specific)

for fc in Topo(iges_importer.compound).faces():
    display.DisplayShape(fc)

display.FitAll()
示例#2
0
#!/usr/bin/env python
# coding: utf-8

r"""Exporting multiple shapes to STEP"""

import logging

from OCC import BRepPrimAPI

from OCCDataExchange.step import StepExporter
from OCCDataExchange import path_from_file

logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s :: %(levelname)6s :: %(module)20s :: %(lineno)3d :: %(message)s')

# First create a simple shape to export
box_shape = BRepPrimAPI.BRepPrimAPI_MakeBox(50, 50, 50).Shape()
sphere_shape = BRepPrimAPI.BRepPrimAPI_MakeSphere(20).Shape()

# Export to STEP
filename = path_from_file(__file__, "./models_out/result_export_multi.stp")
step_exporter = StepExporter(filename)
step_exporter.add_shape(box_shape)
step_exporter.add_shape(sphere_shape)
step_exporter.write_file()
示例#3
0
from __future__ import print_function

import logging

from OCCUtils import Topo

from OCCDataExchange.iges import IgesImporter
from OCCDataExchange import path_from_file

logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s :: %(levelname)6s :: %(module)20s :: %(lineno)3d :: %(message)s')

display, start_display, add_menu, add_function_to_menu = SimpleGui.init_display()

# my_iges_importer = occaddons.dataexchange.iges.IgesImporter("../../data/IGES/splines.igs")
filename = path_from_file(__file__, "./models_in/iges/aube_pleine.iges")
iges_importer = IgesImporter(filename)

print(iges_importer.nb_shapes)  # 13
print(len(iges_importer.shapes))  # 13

the_compound = iges_importer.compound
# display.DisplayShape(the_compound)

# there are no shells or solids in the compound (IGES specific)
for fc in Topo(iges_importer.compound).faces():
    display.DisplayShape(fc)

display.FitAll()
display.View_Iso()
start_display()
示例#4
0
r"""Importing STL"""

import logging

from OCCUtils import Topo

from OCCDataExchange.stl import StlImporter
from OCCDataExchange import path_from_file

logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s :: %(levelname)6s :: %(module)20s :: %(lineno)3d :: %(message)s')

# open/parse STL file and get the resulting TopoDS_Shape instance
# filename = OCCDataExchange.path_from_file(__file__, "./models_in/sample.stl")
# filename = OCCDataExchange.path_from_file(__file__, "./models_in/USS_Albacore.STL")
filename = path_from_file(__file__, "./models_in/stl/USS_Albacore.STL")
my_stl_importer = StlImporter(filename)
the_shape = my_stl_importer.shape

# Then display the shape
display, start_display, add_menu, add_function_to_menu = SimpleGui.init_display()
# display.DisplayShape(the_shape, color='BLUE', update=True)

# 1 shell to display

for sh in Topo(the_shape).shells():
    display.DisplayShape(sh)

# faces
# OCCUtils.display.topology.faces(display, the_shape, show_numbers=False)  # super slow !!
display.FitAll()
示例#5
0
import logging

from OCC.Display import SimpleGui
from OCCUtils import Topo

from OCCDataExchange.step import StepImporter
from OCCDataExchange import path_from_file

logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s :: %(levelname)6s :: %(module)20s :: %(lineno)3d :: %(message)s')
display, start_display, add_menu, add_function_to_menu = SimpleGui.init_display()

# filename = OCCDataExchange.path_from_file(__file__, "./models_in/step/dm1-id-214.stp")
# filename = OCCDataExchange.path_from_file(__file__, "./models_in/step/APB_GC.stp")  # big file 50 Mb !
# filename = OCCDataExchange.path_from_file(__file__, "./models_in/step/66m.stp")
filename = path_from_file(__file__, "./models_in/step/ASA.STEP")
# filename = OCCDataExchange.path_from_file(__file__, "./models_in/step/Groupama_VO70.stp")
step_importer = StepImporter(filename)

the_shapes = step_importer.shapes
print("Nb shapes : %i" % len(the_shapes))  # 4
# print("number_of_shapes(): %i" % step_importer.number_of_shapes)  # 0 ??

# display.DisplayColoredShape(the_shapes[0], Quantity.Quantity_Color(Quantity.Quantity_NOC_GRAY3))
for s in Topo(the_shapes[0]).solids():
    display.DisplayShape(s)

display.FitAll()
display.View_Iso()
start_display()
示例#6
0
from __future__ import print_function

import logging

from OCC.Display import SimpleGui
from OCCUtils import Topo

from OCCDataExchange.step import StepImporter
from OCCDataExchange import path_from_file

logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s :: %(levelname)6s :: %(module)20s :: %(lineno)3d :: %(message)s')

display, start_display, add_menu, add_function_to_menu = SimpleGui.init_display()

filename = path_from_file(__file__, "./models_in/step/aube_pleine.stp")
step_importer = StepImporter(filename)

# step_importer.read_file() -> automatic read_file !!

print("Nb shapes: %i" % len(step_importer.shapes))
for shape in step_importer.shapes:
    print(shape.ShapeType())  # 2 -> solid
# print("number_of_shapes: %i" % step_importer.number_of_shapes)  # 0 ??
# display.DisplayShape(step_importer.shapes)
for s in Topo(step_importer.shapes[0]).solids():
    display.DisplayShape(s, transparency=0.8)

for e in Topo(step_importer.shapes[0]).edges():
    display.DisplayShape(e)
示例#7
0
#!/usr/bin/env python
# coding: utf-8

r"""Exporting a shape to STL"""

from __future__ import print_function

import logging

from OCC import BRepPrimAPI

from OCCDataExchange.stl import StlExporter
from OCCDataExchange import path_from_file

logging.basicConfig(
    level=logging.DEBUG, format="%(asctime)s :: %(levelname)6s :: %(module)20s :: %(lineno)3d :: %(message)s"
)

# First create a simple shape to export
my_box_shape = BRepPrimAPI.BRepPrimAPI_MakeBox(50, 50, 50).Shape()

# Export to STL. If ASCIIMode is set to False, then binary format is used.
filename = path_from_file(__file__, "./models_out/result_export.stl")
my_stl_exporter = StlExporter(filename, ascii_mode=True)
my_stl_exporter.set_shape(my_box_shape)
my_stl_exporter.write_file()
示例#8
0
r"""Importing BREP"""

import logging

from OCC.Display import SimpleGui
from OCCUtils import Topo

from OCCDataExchange.brep import BrepImporter
from OCCDataExchange import path_from_file

logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s :: %(levelname)6s :: %(module)20s :: %(lineno)3d :: %(message)s')

# open/parse BREP file and get the resulting TopoDS_Shape instance
filename = path_from_file(__file__, "./models_in/brep/carter.brep")
my_brep_importer = BrepImporter(filename)
the_shape = my_brep_importer.shape

# Then display the shape
display, start_display, add_menu, add_function_to_menu = SimpleGui.init_display()
# display.DisplayShape(the_shape, color='BLUE', update=True)

# 1 solid to display

for s in Topo(the_shape):
    display.DisplayShape(s)

# faces
# OCCUtils.display.topology.faces(display, the_shape, show_numbers=False)  # super slow !!
display.FitAll()
示例#9
0
#!/usr/bin/env python
# coding: utf-8

r"""Exporting a single shape to BREP"""

import logging

from OCC import BRepPrimAPI

from OCCDataExchange.brep import BrepExporter
from OCCDataExchange import path_from_file

logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s :: %(levelname)6s :: %(module)20s :: %(lineno)3d :: %(message)s')

# First create a simple shape to export
box_shape = BRepPrimAPI.BRepPrimAPI_MakeBox(50, 50, 50).Shape()

# Export to BREP
filename = path_from_file(__file__, "./models_out/box.brep")
step_exporter = BrepExporter(filename)
step_exporter.set_shape(box_shape)
step_exporter.write_file()