{ "cells": [ { "cell_type": "markdown", "id": "0bf6a7b1", "metadata": {}, "source": [ "# Modeling: Body color assignment and usage\n", "\n", "In PyAnsys Geometry, a *body* represents solids or surfaces organized within the ``Design`` assembly.\n", "As users might be already familiar with, Ansys CAD products (like SpaceClaim, Ansys Discovery and the\n", "Geometry Service), allow to assign colors to bodies. This example shows how to assign colors to a body,\n", "retrieve their value and how to use them in the client-side visualization.\n", "\n", "## Perform required imports\n", "\n", "Perform the required imports." ] }, { "cell_type": "code", "execution_count": 1, "id": "81ebe9b6", "metadata": { "execution": { "iopub.execute_input": "2025-04-16T11:00:00.435345Z", "iopub.status.busy": "2025-04-16T11:00:00.434914Z", "iopub.status.idle": "2025-04-16T11:00:02.029827Z", "shell.execute_reply": "2025-04-16T11:00:02.029276Z" } }, "outputs": [], "source": [ "import ansys.geometry.core as pyansys_geometry\n", "\n", "from ansys.geometry.core import launch_modeler\n", "from ansys.geometry.core.math import Point2D, UNITVECTOR3D_X, UNITVECTOR3D_Y\n", "from ansys.geometry.core.sketch import Sketch" ] }, { "cell_type": "markdown", "id": "88846b7d", "metadata": {}, "source": [ "## Create a box sketch\n", "\n", "Create a ``Sketch`` instance and insert a box sketch with a width and height of 10\n", "in the default plane." ] }, { "cell_type": "code", "execution_count": 2, "id": "15a86e6c", "metadata": { "execution": { "iopub.execute_input": "2025-04-16T11:00:02.032394Z", "iopub.status.busy": "2025-04-16T11:00:02.031758Z", "iopub.status.idle": "2025-04-16T11:00:02.041056Z", "shell.execute_reply": "2025-04-16T11:00:02.040444Z" } }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sketch = Sketch()\n", "sketch.box(Point2D([0, 0]), 10, 10)" ] }, { "cell_type": "markdown", "id": "605614e3", "metadata": {}, "source": [ "## Initiate design on server\n", "\n", "Establish a server connection and initiate a design on the server." ] }, { "cell_type": "code", "execution_count": 3, "id": "c7475a50", "metadata": { "execution": { "iopub.execute_input": "2025-04-16T11:00:02.043103Z", "iopub.status.busy": "2025-04-16T11:00:02.042657Z", "iopub.status.idle": "2025-04-16T11:00:02.183334Z", "shell.execute_reply": "2025-04-16T11:00:02.182792Z" } }, "outputs": [], "source": [ "modeler = launch_modeler()\n", "design = modeler.create_design(\"ServiceColors\")" ] }, { "cell_type": "markdown", "id": "5f82118a", "metadata": {}, "source": [ "## Extrude the box sketch to create the matrix style design\n", "\n", "Given the initial sketch, you can extrude it to create a matrix style design.\n", "In this example, you can create a 2x3 matrix of bodies. Each body is separated by 30 units\n", "in the X direction and 30 units in the Y direction. You have a total of 6 bodies." ] }, { "cell_type": "code", "execution_count": 4, "id": "991e004c", "metadata": { "execution": { "iopub.execute_input": "2025-04-16T11:00:02.185512Z", "iopub.status.busy": "2025-04-16T11:00:02.185144Z", "iopub.status.idle": "2025-04-16T11:00:02.760959Z", "shell.execute_reply": "2025-04-16T11:00:02.760319Z" } }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c2075c2a67a04c31b84c907e652ce77b", "version_major": 2, "version_minor": 0 }, "text/plain": [ "EmbeddableWidget(value='" } }, "2eb4a0a46e6d433eb4992c37cf56f6a6": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "315a196cc9d04104b793ee8b2c707960": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "HTMLModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_2eb4a0a46e6d433eb4992c37cf56f6a6", "placeholder": "​", "style": "IPY_MODEL_a97eb2c1a5bf40b899b3bfba126e36fb", "value": "" } }, "3369890f63044fbdbb48f78e56d07339": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "4b6127847a5c4fbeb0c0679c20e9b713": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "HTMLModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_5abb4e548c244c88b56a451307012248", "placeholder": "​", "style": "IPY_MODEL_ae55ff3d976a4231816d8fac8b53d3fc", "value": "" } }, "5abb4e548c244c88b56a451307012248": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "71774c1a7264427ead886a5f01325848": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } }, "7a8dba60800a41b893171096b9d9a808": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } }, "8383a6008a5d482d8b2b0518e55524fa": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "HTMLModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_3369890f63044fbdbb48f78e56d07339", "placeholder": "​", "style": "IPY_MODEL_71774c1a7264427ead886a5f01325848", "value": "" } }, "978b17fcc92e49429e4828e0ff2ed1cf": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "9a513f46fcf64c1380e2f3303dff1f47": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } }, "a97eb2c1a5bf40b899b3bfba126e36fb": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } }, "ae55ff3d976a4231816d8fac8b53d3fc": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } }, "b12bcf2aa2b340ccbe696237d6547f9a": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } }, "c2075c2a67a04c31b84c907e652ce77b": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "HTMLModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_fb4f84d195c0422c890b5b6214d09583", "placeholder": "​", "style": "IPY_MODEL_b12bcf2aa2b340ccbe696237d6547f9a", "value": "" } }, "da938d381aa84674b612f3601c5f932b": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "DescriptionStyleModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "StyleView", "description_width": "" } }, "f16e12b9e7874a499b26f5945f3e0dd6": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "HTMLModel", "state": { "_dom_classes": [], "_model_module": "@jupyter-widgets/controls", "_model_module_version": "1.5.0", "_model_name": "HTMLModel", "_view_count": null, "_view_module": "@jupyter-widgets/controls", "_view_module_version": "1.5.0", "_view_name": "HTMLView", "description": "", "description_tooltip": null, "layout": "IPY_MODEL_978b17fcc92e49429e4828e0ff2ed1cf", "placeholder": "​", "style": "IPY_MODEL_7a8dba60800a41b893171096b9d9a808", "value": "" } }, "fb4f84d195c0422c890b5b6214d09583": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": { "_model_module": "@jupyter-widgets/base", "_model_module_version": "1.2.0", "_model_name": "LayoutModel", "_view_count": null, "_view_module": "@jupyter-widgets/base", "_view_module_version": "1.2.0", "_view_name": "LayoutView", "align_content": null, "align_items": null, "align_self": null, "border": null, "bottom": null, "display": null, "flex": null, "flex_flow": null, "grid_area": null, "grid_auto_columns": null, "grid_auto_flow": null, "grid_auto_rows": null, "grid_column": null, "grid_gap": null, "grid_row": null, "grid_template_areas": null, "grid_template_columns": null, "grid_template_rows": null, "height": null, "justify_content": null, "justify_items": null, "left": null, "margin": null, "max_height": null, "max_width": null, "min_height": null, "min_width": null, "object_fit": null, "object_position": null, "order": null, "overflow": null, "overflow_x": null, "overflow_y": null, "padding": null, "right": null, "top": null, "visibility": null, "width": null } } }, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 5 }