{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import random\n", "import os\n", "import os.path\n", "import sys\n", "\n", "from OCC.STEPControl import STEPControl_Reader\n", "from OCC.IFSelect import IFSelect_RetDone, IFSelect_ItemsByEntity\n", "\n", "sys.path.append('..')\n", "from core_topology_traverse import Topo" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from OCC.Display.WebGl.jupyter_renderer import JupyterRenderer, format_color" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def read_step_file(filename):\n", " \"\"\" read the STEP file and returns a compound\n", " \"\"\"\n", " step_reader = STEPControl_Reader()\n", " status = step_reader.ReadFile(filename)\n", "\n", " if status == IFSelect_RetDone: # check status\n", " failsonly = False\n", " step_reader.PrintCheckLoad(failsonly, IFSelect_ItemsByEntity)\n", " step_reader.PrintCheckTransfer(failsonly, IFSelect_ItemsByEntity)\n", "\n", " ok = step_reader.TransferRoot(1)\n", " _nbs = step_reader.NbShapes()\n", " aResShape = step_reader.Shape(1)\n", " else:\n", " print(\"Error: can't read file.\")\n", " sys.exit(0)\n", " return aResShape\n", "\n", "shp = read_step_file(os.path.join('..', 'models', 'RC_Buggy_2_front_suspension.stp')) # this is a compound" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "my_renderer = JupyterRenderer(size=(700, 700))\n", "my_renderer.Display()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# loop over subshapes so that each subshape is meshed/displayed\n", "t = Topo(shp)\n", "from random import randint\n", "for solid in t.solids():\n", " random_color = format_color(randint(0,255), randint(0,255), randint(0,255))\n", " my_renderer.DisplayShape(solid, shape_color=random_color)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.4" } }, "nbformat": 4, "nbformat_minor": 2 }