def display_shape(self, shape, rgb=None, transparency=None, material=Graphic3d_NOM_DEFAULT): """ Display a shape. :param OCCT.TopoDS.TopoDS_Shape shape: The shape. :param rgb: The RGB color (r, g, b). :type rgb: collections.Sequence[float] or OCCT.Quantity.Quantity_Color :param float transparency: The transparency (0 to 1). :param OCCT.Graphic3d.Graphic3d_NameOfMaterial material: The material. :return: The AIS_Shape created for the part. :rtype: OCCT.AIS.AIS_Shape """ ais_shape = AIS_Shape(shape) if isinstance(rgb, (tuple, list)): r, g, b = rgb if r > 1.: r /= 255. if g > 1.: g /= 255. if b > 1.: b /= 255. color = Quantity_Color(r, g, b, Quantity_TOC_RGB) ais_shape.SetColor(color) elif isinstance(rgb, Quantity_Color): ais_shape.SetColor(rgb) if transparency is not None: ais_shape.SetTransparency(transparency) ma = Graphic3d_MaterialAspect(material) ais_shape.SetMaterial(ma) self.my_context.Display(ais_shape, True) return ais_shape
## ##You should have received a copy of the GNU Lesser General Public License ##along with pythonOCC. If not, see <http://www.gnu.org/licenses/>. from OCCT.AIS import AIS_Shape from OCCT.BRepPrimAPI import BRepPrimAPI_MakeBox from OCC.Display.SimpleGui import init_display display, start_display, add_menu, add_function_to_menu = init_display() # # Create a box # s = BRepPrimAPI_MakeBox(200, 100, 50).Shape() # # Create an AIS_Shape from the previous shape # ais_shp = AIS_Shape(s) ais_shp.SetWidth(4) ais_shp.SetTransparency(0.10) # # Get context and display shape # # Get Context ais_context = display.GetContext() ais_context.Display(ais_shp, True) display.View_Iso() display.FitAll() start_display()