### Install COMPAS using compas_blender.install with clean Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/cad.blender.rst Installs COMPAS using symlinks after removing any previous installations. ```bash python -m compas_blender.install --clean ``` -------------------------------- ### Install Development Requirements Source: https://github.com/compas-dev/compas/wiki/Dev-Install Install all necessary development dependencies from the requirements file. ```bash $ pip install -r requirements-dev.txt ``` -------------------------------- ### Install COMPAS using Conda Source: https://github.com/compas-dev/compas/blob/main/README.md Recommended installation method using Anaconda/conda. Ensure the conda-forge channel is added before installing. ```bash conda config --add channels conda-forge conda install compas ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/compas-dev/compas/blob/main/docs/devguide/workflow.rst Navigate to the COMPAS directory and install the project with development dependencies using pip. ```bash cd path/to/compas pip install -e ".[dev]" ``` -------------------------------- ### Install COMPAS using compas_blender.install Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/cad.blender.rst Installs COMPAS by creating symlinks to an existing COMPAS installation. Dependencies must be pre-installed in Blender's Python environment. ```bash python -m compas_blender.install ``` -------------------------------- ### Load VolMesh from OBJ File (Specific Example) Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.volmeshes.rst Loads a VolMesh from a specific OBJ file named 'volmeshring.obj'. This is an example of loading a VolMesh from file. ```python from compas.datastructures import VolMesh volmesh = VolMesh.from_obj("volmeshring.obj") ``` -------------------------------- ### Install COMPAS using compas_blender.install with version Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/cad.blender.rst Installs COMPAS using symlinks, specifying the target Blender version. ```bash python -m compas_blender.install -v 4.2 ``` -------------------------------- ### Install COMPAS from Local Path using install_in_rhino Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/cad.rhino8.rst Install COMPAS from a specified local path using the `install_in_rhino` utility. This allows for installing packages that are not in the current directory. ```bash install_in_rhino path/to/package ``` -------------------------------- ### install_userobjects Source: https://github.com/compas-dev/compas/blob/main/docs/api/compas_ghpython.components.rst Installs user-defined GH Components. ```APIDOC ## install_userobjects ### Description Installs user-defined GH Components. ### Signature `install_userobjects(paths)` ### Parameters * **paths** (list of str) - A list of paths to the user object files or directories. ``` -------------------------------- ### Install COMPAS with Pip Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/installation.rst Install COMPAS from the Python Package Index using pip. ```bash pip install compas ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/compas-dev/compas/blob/main/CONTRIBUTING.md Install the necessary development dependencies for the COMPAS project. This command should be run within a virtual environment. ```bash pip install -r requirements-dev.txt ``` -------------------------------- ### Install Compas Components to Rhino Source: https://github.com/compas-dev/compas/blob/main/docs/devguide/ghcomponent.rst Install compiled Compas components into a specific Rhino version using the compas_rhino.install command. ```bash python -m compas_rhino.install -v 7.0 ``` -------------------------------- ### Install COMPAS from Requirements File using install_in_rhino Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/cad.rhino8.rst Install COMPAS and other dependencies from a requirements file using the `install_in_rhino` utility. This is useful for managing multiple package installations. ```bash install_in_rhino -r requirements.txt ``` -------------------------------- ### Clear and Install COMPAS in Specific Environment using install_in_rhino Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/cad.rhino8.rst Clear an existing environment and then install COMPAS into it using the `install_in_rhino` utility. This ensures a clean installation for the specified environment. ```bash install_in_rhino compas --env compas-dev --clear ``` -------------------------------- ### Verify COMPAS Installation Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/installation.rst Run this command to check if COMPAS has been installed successfully. ```bash python -m compas ``` -------------------------------- ### Second-Level Imports Example Source: https://github.com/compas-dev/compas/blob/main/docs/devguide/code.rst Demonstrates how to make new public functions or classes importable from a second-level package by importing them in the package's __init__.py file. ```bash compas ├── __init__.py └── my_package ├── __init__.py └── new_module.py ``` ```python # new_module.py class NewClass(object): ... ``` ```python # compas.my_package.__init__.py from .new_module import NewClass __all__ = ['NewClass'] ``` ```python >>> from compas.my_package import NewClass ``` -------------------------------- ### GH Component Metadata Example Source: https://github.com/compas-dev/compas/blob/main/docs/devguide/ghcomponent.rst Define component settings, including name, category, and input/output parameters, in metadata.json. ```json { "name": "Example Component", "nickname": "Example", "category": "COMPAS Bananas", "subcategory": "Example", "description": "This is an example component.", "exposure": 4, "ghpython": { "isAdvancedMode": true, "iconDisplay": 0, "inputParameters": [ { "name": "Arg1", "description": "First example argument.", "typeHintID": "none", "scriptParamAccess": 1 }, { "name": "Arg2", "description": "Second example argument.", "typeHintID": "bool", "scriptParamAccess": 0 } ], "outputParameters": [ { "name": "Output1", "description": "First output." }, { "name": "Output2", "description": "Second output." } ] } } ``` -------------------------------- ### Install COMPAS from Current Directory using install_in_rhino Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/cad.rhino8.rst Install COMPAS from the current directory using the `install_in_rhino` utility. This is convenient when working directly with the COMPAS source code. ```bash install_in_rhino . ``` -------------------------------- ### Verify COMPAS Setup in Grasshopper Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/cad.grasshopper.rst Paste this script into a GhPython component to verify your COMPAS installation for Grasshopper. It loads a mesh and adds it to the scene. ```python import compas from compas.datastructures import Mesh from compas.scene import Scene mesh = Mesh.from_obj(compas.get('faces.obj')) scene = Scene() scene.add(mesh) a = scene.draw() ``` -------------------------------- ### Install COMPAS from PyPI in Blender Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/cad.blender.rst Install the COMPAS package into Blender's Python environment using pip. ```bash /Applications/Blender.app/Contents/Resources/4.2/python/bin/python3.10 -m pip install compas ``` -------------------------------- ### Install Editable Pip Version from Local Source Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/installation.rst Install COMPAS in editable mode from local source code using pip. Ensure you are in the COMPAS directory. ```bash cd path/to/compas pip install -e . ``` -------------------------------- ### Successful COMPAS Installation Message Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/installation.rst This message is displayed when COMPAS is verified to be installed correctly. ```none Yay! COMPAS is installed correctly! ``` -------------------------------- ### Install COMPAS from Source in Blender Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/cad.blender.rst Install COMPAS into Blender's Python environment from local source code using pip in editable mode. ```bash cd path/to/compas /Applications/Blender.app/Contents/Resources/4.2/python/bin/python3.10 -m pip install -e . ``` -------------------------------- ### Install Specific COMPAS Version with Pip Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/installation.rst Install a specific version of COMPAS using pip. ```bash pip install compas==1.17.9 ``` -------------------------------- ### Install Python Package from PyPI using install_in_rhino Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/cad.rhino8.rst Use the `install_in_rhino` utility to install any Python package available on PyPI into the Rhino 8 CPython environment. This is a simplified method for package management. ```bash install_in_rhino requests numpy ``` -------------------------------- ### Activate Conda Environment and Install Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/cad.rhino.rst If COMPAS is installed in a conda environment, activate it first before running the installation command. ```bash conda activate compas-dev python -m compas_rhino.install ``` -------------------------------- ### Creating a Mesh with Face Colors from a Color Map Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.colors.rst This example demonstrates creating a mesh and assigning face colors based on a color map. It requires importing several COMPAS modules and the Viewer. ```python from compas.geometry import Point, Polygon from compas.utilities import linspace, pairwise from compas.datastructures import Mesh from compas.colors import Color, ColorMap from compas_viewer import Viewer n = 1000 t = 0.3 up = [] down = [] for i in linspace(0, 10, n): point = Point(i, 0, 0) up.append(point + [0, t, 0]) down.append(point - [0, t, 0]) polygons = [] for (d, c), (a, b) in zip(pairwise(up), pairwise(down)): polygons.append(Polygon([a, b, c, d])) mesh = Mesh.from_polygons(polygons) cmap = ... # define color map here facecolor = {i: cmap(i, minval=0, maxval=n - 1) for i in range(n)} viewer = Viewer(show_grid = False) viewer.scene.add(mesh, facecolor=facecolor, show_lines=False) viewer.show() ``` -------------------------------- ### NumPy Style Docstring Example Source: https://github.com/compas-dev/compas/blob/main/docs/devguide/code.rst Functions and methods should have NumPy style docstrings for API documentation generation. ```python def my_function(point, line): """This is a one-line description of the function. This is a longer description of the function. It can span multiple lines. Parameters ---------- point : :class:`~compas.geometry.Point` Point to check. line : :class:`~compas.geometry.Line` Line to analyze. Returns ------- :class:`~compas.geometry.Plane` The resulting plane of the operation. """ ... ``` -------------------------------- ### Install COMPAS from Local Source using Pip Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/cad.rhino8.rst Install a COMPAS package from local source using pip and the Python executable included with Rhino 8. This is useful for development or when packages are not on PyPI. ```bash $ cd path/to/compas $ ~/.rhinocode/py39-rh8/python3.9 -m pip install . ``` -------------------------------- ### Install COMPAS from Local Source (Editable) Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/cad.rhino8.rst Create an editable installation of COMPAS from local source within the Rhino 8 Python environment. This allows for direct code changes to be reflected without reinstallation. ```bash $ cd path/to/compas $ ~/.rhinocode/py39-rh8/python3.9 -m pip install -e . ``` -------------------------------- ### Install Specific COMPAS Version with Conda Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/installation.rst Install a specific version of COMPAS using conda. ```bash conda install compas=1.17.9 ``` -------------------------------- ### Verify COMPAS Installation Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/cad.blender.rst Check the installed COMPAS version within Blender's Python console. ```python import compas print(compas.__version__) ``` -------------------------------- ### Install COMPAS with Specific Python Version Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/installation.rst Create a new conda environment with a specific Python version (e.g., 3.9) and install COMPAS. ```bash conda create -n research python=3.9 compas ``` -------------------------------- ### Create Conda Environment and Install COMPAS Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/installation.rst Use this command to create a new conda environment named 'research' and install COMPAS from the 'conda-forge' channel. ```bash conda create -n research -c conda-forge compas ``` -------------------------------- ### Install COMPAS Package via Requirements Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/cad.rhino8.rst Add COMPAS packages as requirements in a comment for direct installation in Rhino 8 CPython scripts. This method requires the package to be available on PyPI. ```python #! python3 # r: compas import compas from compas.datastructures import Mesh mesh = ... ``` -------------------------------- ### Install COMPAS in Specific Environment using install_in_rhino Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/cad.rhino8.rst Install COMPAS into a specific named environment within Rhino 8 using the `install_in_rhino` utility. This helps in managing different project dependencies. ```bash install_in_rhino compas --env compas-dev ``` -------------------------------- ### Traversing a Halfedge Loop Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.meshes.rst Prints the sequence of halfedges forming a loop starting from a given halfedge. ```python for edge in mesh.halfedge_loop((32, 33)): print(edge) ``` -------------------------------- ### Get Brep Type Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.geometry.breps.rst Demonstrates how to check the type of a Brep instance, which can vary based on the active COMPAS backend (e.g., Rhino). ```python >>> type(brep) compas_rhino.geometry.RhinoBrep ``` -------------------------------- ### Accessing Vertex XYZ Coordinates Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.meshes.rst Shows how to get and set the XYZ coordinates of a vertex, and retrieve a specific coordinate for all vertices. ```python mesh.vertex_attributes(0, 'xyz') ``` ```python mesh.vertices_attribute('x') ``` -------------------------------- ### Verify COMPAS Installation in Rhino Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/cad.rhino.rst Execute this Python script within Rhino to confirm that COMPAS is installed and accessible, printing the installed version. ```python import compas print(compas.__version__) ``` -------------------------------- ### Create a Cell Network from Scratch Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.cellnetwork.rst Demonstrates how to initialize an empty CellNetwork and add vertices, faces, and cells programmatically. Use this when building a cell network incrementally. ```python from compas.datastructures import CellNetwork cell_network = CellNetwork() vertices = [(0, 0, 0), (0, 1, 0), (1, 1, 0), (1, 0, 0), (0, 0, 1), (1, 0, 1), (1, 1, 1), (0, 1, 1)] faces = [[0, 1, 2, 3], [0, 3, 5, 4], [3, 2, 6, 5], [2, 1, 7, 6], [1, 0, 4, 7], [4, 5, 6, 7]] cells = [[0, 1, 2, 3, 4, 5]] vertices = [cell_network.add_vertex(x=x, y=y, z=z) for x, y, z in vertices] faces = [cell_network.add_face(fverts) for fverts in faces] cells = [cell_network.add_cell(fkeys) for fkeys in cells] print(cell_network) ``` -------------------------------- ### Comment Usage Example Source: https://github.com/compas-dev/compas/blob/main/docs/devguide/code.rst Use comments sparingly to clarify portions of code that are best understood in a specific context. ```python def my_function(): # while seems unlikely, 42 is the answer to everything return some_piece_of_code() + 42 ``` -------------------------------- ### Specify custom path for RPC server modules Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/advanced.rpc.rst Use the 'path' parameter when creating a Proxy to add a directory to the server's PYTHONPATH. This allows the server to find custom modules not installed in the environment. ```python from compas.geometry import Pointcloud from compas.rpc import Proxy cloud = Pointcloud.from_bounds(10, 5, 3, 100) proxy = Proxy(package='clustering', path=r'C:\\Users\\\\Desktop') clusters = proxy.cluster(cloud, 10) ``` -------------------------------- ### Assembly JSON Serialization and Deserialization Source: https://github.com/compas-dev/compas/blob/main/docs/api/compas.datastructures.Assembly.rst Demonstrates how to save an Assembly to a JSON file and load it back. ```APIDOC ## Assembly JSON Operations ### Description This section covers the methods for converting an Assembly object to and from JSON format. ### Methods #### `Assembly.to_json(filepath, pretty=False)` Converts the Assembly object to a JSON string and saves it to a file. * **filepath** (str): The path to the file where the JSON data will be saved. * **pretty** (bool, optional): If True, the JSON output will be pretty-printed. Defaults to False. ### `Assembly.from_json(filepath)` Loads an Assembly object from a JSON file. * **filepath** (str): The path to the JSON file to load. ### Request Example ```python from compas.datastructures import Assembly # Create an assembly assembly = Assembly() # ... add components to the assembly ... # Save to JSON assembly.to_json("my_assembly.json", pretty=True) # Load from JSON loaded_assembly = Assembly.from_json("my_assembly.json") ``` ### Response Example * `to_json` returns None. * `from_json` returns an Assembly object. ``` -------------------------------- ### Run Linting and Tests Source: https://github.com/compas-dev/compas/blob/main/docs/devguide/workflow.rst Execute the invoke commands to ensure code quality and pass all tests. ```bash invoke lint invoke test ``` -------------------------------- ### Run Lint, Test, and Docs Checks Source: https://github.com/compas-dev/compas/blob/main/docs/devguide/workflow.rst Before submitting a PR, ensure code quality, test coverage, and documentation compilation. ```bash invoke lint invoke test invoke docs ``` -------------------------------- ### Predefined Vector Constructors Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.geometry.points_and_vectors.rst Shows how to create special vectors like the X, Y, and Z axes using predefined constructor methods. ```python Vector.Xaxis() Vector(x=1.0, y=0.0, z=0.0) Vector.Yaxis() Vector(x=0.0, y=1.0, z=0.0) Vector.Zaxis() Vector(x=0.0, y=0.0, z=1.0) ``` -------------------------------- ### Create and Access Point Coordinates Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.geometry.points_and_vectors.rst Demonstrates how to create a Point object and access its individual coordinates by name or index. The Z coordinate defaults to zero if not provided. ```python from compas.geometry import Point a = Point(1, 2, 3) a Point(x=1.0, y=2.0, z=3.0) a.x 1.0 a.y 2.0 a.z 3.0 a[0] 1.0 a[1] 2.0 a[2] 3.0 b = Point(1, 2) b Point(x=1.0, y=2.0, z=0.0) b.z 0.0 ``` -------------------------------- ### Creating Color Maps from a Single Color Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.colors.rst Demonstrates creating color maps from a single color, with options to generate variations based on lightness ('light') or darkness ('dark'). ```python cmap = ColorMap.from_color(Color.red()) cmap = ColorMap.from_color(Color.red(), rangetype='light') cmap = ColorMap.from_color(Color.red(), rangetype='dark') ``` -------------------------------- ### Install COMPAS in Existing Conda Environment Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/installation.rst Install COMPAS into an already existing conda environment named 'research'. ```bash conda install -n research compas ``` -------------------------------- ### Convert Rhino Geometry to COMPAS Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/cad.rhino.rst Examples of converting various Rhino geometry types (Point, Line, Plane, Box, Mesh, Curve, Surface, Brep) to their COMPAS equivalents using the compas_rhino.conversions module. ```python import Rhino.Geometry import compas_rhino.conversions point = Rhino.Geometry.Point3d(...) point = compas_rhino.conversions.point_to_compas(point) line = Rhino.Geometry.Line(...) line = compas_rhino.conversions.line_to_compas(line) plane = Rhino.Geometry.Plane(...) plane = compas_rhino.conversions.plane_to_compas(plane) box = Rhino.Geometry.Box(...) box = compas_rhino.conversions.box_to_compas(box) mesh = Rhino.Geometry.Mesh(...) mesh = compas_rhino.conversions.mesh_to_compas(mesh) curve = Rhino.Geometry.Curve(...) curve = compas_rhino.conversions.curve_to_compas(curve) surface = Rhino.Geometry.Surface(...) surface = compas_rhino.conversions.surface_to_compas(surface) brep = Rhino.Geometry.Brep(...) brep = compas_rhino.conversions.brep_to_compas(brep) ``` -------------------------------- ### Create Plane from Frame and Convert Back Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.geometry.planes_and_frames.rst Demonstrates creating a Plane from a Frame and then creating a new Frame from that Plane. Verifies point and z-axis equality, but notes differences in x and y axes. ```python >>> from compas.geometry import Frame >>> from compas.geometry import Plane >>> frame1 = Frame([0, 0, 0], [0, 1, 0], [-1, 0, 0]) >>> plane = Plane.from_frame(frame1) >>> frame2 = Frame.from_plane(plane) >>> frame1.point == frame2.point True >>> frame1.zaxis == frame2.zaxis True >>> frame1.xaxis == frame2.xaxis False >>> frame1.yaxis == frame2.yaxis False ``` -------------------------------- ### Mesh Constructors Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.meshes.rst Demonstrates various class methods for creating meshes from different sources like lines, grids, polygons, polyhedra, shapes, or vertex/face data. ```python from compas.datastructures import Mesh mesh = Mesh.from_lines(...) mesh = Mesh.from_meshgrid(...) mesh = Mesh.from_polygons(...) mesh = Mesh.from_polyhedron(...) mesh = Mesh.from_shape(...) mesh = Mesh.from_vertices_and_faces(...) ``` -------------------------------- ### Create and Draw a Simple Box Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/firststeps.rst Demonstrates the creation of a basic box geometry and its addition to a scene for visualization. ```python from compas.geometry import Box from compas.scene import Scene box = Box(1, 1, 1) scene = Scene() scene.add(box) scene.draw() ``` -------------------------------- ### Load Cell Network from File Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.cellnetwork.rst Shows how to load a CellNetwork from various file formats like OBJ or JSON. Use this when you have existing cell network data stored in files. ```python from compas.datastructures import CellNetwork cell_network = CellNetwork.from_obj(...) ``` ```python from compas.datastructures import CellNetwork cell_network = CellNetwork.from_json(...) ``` -------------------------------- ### Create a Mesh from Scratch Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.meshes.rst Constructs a new mesh and adds vertices and a face programmatically. Useful for building meshes with custom topology. ```python from compas.datastructures import Mesh mesh = Mesh() a = mesh.add_vertex(x=0, y=0, z=0) b = mesh.add_vertex(x=1, y=0, z=0) c = mesh.add_vertex(x=1, y=1, z=0) d = mesh.add_vertex(x=0, y=1, z=0) face = mesh.add_face([a, b, c, d]) mesh ``` -------------------------------- ### Install COMPAS Rhino Packages Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/cad.rhino.rst Run this command in the terminal to install COMPAS and its GH Components into Rhino. Ensure your conda environment is activated and Rhino is closed before running. ```bash python -m compas_rhino.install ``` -------------------------------- ### RPC Server with Context Manager Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/advanced.rpc.rst Uses a context manager to ensure the RPC server restarts after every call. This mimics the behavior of the older XFunc predecessor. ```python >>> with Proxy('compas.numerical') as numerical: ... numerical.pca_numpy(...) ... ``` -------------------------------- ### Visualize Cell Network with Scene Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.cellnetwork.rst Demonstrates how to visualize a CellNetwork using the COMPAS Scene manager. Ensure the 'compas.scene' module is imported and a Scene object is created. ```python import compas from compas.datastructures import CellNetwork from compas.scene import Scene cell_network = CellNetwork.from_json(compas.get('cellnetwork_example.json')) scene = Scene() scene.add(mesh) scene.show() ``` -------------------------------- ### Upgrade Pip in Rhino 8 Environment Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/cad.rhino8.rst Upgrade the pip package installer within the Rhino 8 Python environment before performing editable installs. This ensures compatibility and access to the latest features. ```bash $ ~/.rhinocode/py39-rh8/python3.9 -m pip install --upgrade pip ``` -------------------------------- ### Stage, Commit, and Push Changes Source: https://github.com/compas-dev/compas/blob/main/docs/devguide/workflow.rst Stage all changes, commit them with a descriptive message, and push the branch to your remote repository. ```bash git add . git commit -m "add functionality X to compas" git push origin feature-new-method ``` -------------------------------- ### Attributes Source: https://github.com/compas-dev/compas/blob/main/docs/api/compas.datastructures.Graph.rst Methods for getting, setting, and updating attributes associated with nodes and edges. ```APIDOC ## Attributes Methods for managing node and edge attributes. ### `Graph.edge_attribute(key, default=None)` Returns the value of an edge attribute. ### `Graph.edge_attributes(keys=None, default=None)` Returns a dictionary of edge attributes. ### `Graph.edges_attribute(name, default=None)` Returns a list of values for a specific edge attribute across all edges. ### `Graph.edges_attributes(name, default=None)` Returns a dictionary mapping edges to the values of a specific attribute. ### `Graph.node_attribute(key, default=None)` Returns the value of a node attribute. ### `Graph.node_attributes(keys=None, default=None)` Returns a dictionary of node attributes. ### `Graph.nodes_attribute(name, default=None)` Returns a list of values for a specific node attribute across all nodes. ### `Graph.nodes_attributes(name, default=None)` Returns a dictionary mapping nodes to the values of a specific attribute. ### `Graph.update_default_edge_attributes(attributes)` Updates the default attributes for edges. ### `Graph.update_default_node_attributes(attributes)` Updates the default attributes for nodes. ### `Graph.unset_edge_attribute(key)` Removes an edge attribute. ### `Graph.unset_node_attribute(key)` Removes a node attribute. ``` -------------------------------- ### Get a single attribute for all vertices Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.volmeshes.rst Retrieves the value of a specific attribute for all vertices in the VolMesh. ```python >>> volmesh.vertices_attribute(name="a") [None, None, None, ... None] ``` -------------------------------- ### Create an Empty Brep Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.geometry.breps.rst Instantiates an empty Brep object. The specific type of the Brep instance depends on the currently available backend. ```python >>> from compas.geometry import Brep >>> brep = Brep() ``` -------------------------------- ### Get a single vertex attribute Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.volmeshes.rst Retrieves the value of a specific attribute for a given vertex. ```python >>> volmesh.vertex_attribute(vertex=0, name="a") None ``` -------------------------------- ### Run All Tests and Checks Source: https://github.com/compas-dev/compas/blob/main/CONTRIBUTING.md Execute all tests and code quality checks. This command ensures that the codebase is in a healthy state before and after making changes. ```bash invoke test ``` -------------------------------- ### Get a single attribute for a selection of vertices Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.volmeshes.rst Retrieves the value of a specific attribute for a subset of vertices. ```python >>> volmesh.vertices_attribute(name="b", vertices=[0, 1, 2, 3]) [0.0, 0.0, 0.0, 0.0] ``` -------------------------------- ### Auto-format Code Source: https://github.com/compas-dev/compas/blob/main/CONTRIBUTING.md Automatically format your code according to project standards. This should be run before committing changes. ```bash invoke format ``` -------------------------------- ### Get multiple attributes for all vertices Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.volmeshes.rst Retrieves the values of multiple specified attributes for all vertices in the VolMesh. ```python >>> volmesh.vertices_attributes(names=["b", "c"]) [(0.0, False), (0.0, False), (0.0, False), ..., (0.0, False)] ``` -------------------------------- ### Creating a Mesh from a Grid Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.meshes.rst Initializes a mesh using the `from_meshgrid` constructor, useful for grid-like structures. ```python mesh = Mesh.from_meshgrid(dx=9, nx=9) ``` -------------------------------- ### Get multiple vertex attributes Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.volmeshes.rst Retrieves the values of multiple specified attributes for a single vertex. ```python >>> volmesh.vertex_attributes(vertex=0, names=["a", "b"]) (None, 0.0) ``` -------------------------------- ### Get all vertices from VolMesh Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.volmeshes.rst Converts the iterator of vertices into a list. Note that vertex identifiers are integers. ```python >>> vertices = list(volmesh.vertices()) >>> vertices [0, 1, 2, 3, 4, ..., 63] ``` -------------------------------- ### Traversing an Edge Strip Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.meshes.rst Prints the sequence of edges forming a strip starting from a given edge. ```python for edge in mesh.edge_strip((20, 30)): print(edge) ``` -------------------------------- ### Add and Draw a Box to the Scene Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.visualisation.rst Import necessary classes, create a Box object, add it to a Scene, and then draw the scene. This is the fundamental workflow for visualising objects. ```python from compas.scene import Scene from compas.geometry import Box box = Box(1) scene = Scene() scene.add(box) scene.draw() ``` -------------------------------- ### Traversing an Edge Loop Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.meshes.rst Prints the sequence of edges forming a loop starting from a given edge. ```python for edge in mesh.edge_loop((62, 63)): print(edge) ``` -------------------------------- ### Add Scene Object with Color Argument Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.visualisation.rst Visualisation settings, such as color, can be provided directly as arguments to the Scene.add() method for convenience. ```python sceneobj = scene.add(box, color=(0, 255, 0)) sceneobj.color ``` -------------------------------- ### Initialize VolMesh with default vertex attributes Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.volmeshes.rst Creates a VolMesh from a grid and initializes default values for vertex attributes. It's good practice to declare default values. ```python >>> volmesh = VolMesh.from_meshgrid(dx=3, nx=10) >>> volmesh.update_default_vertex_attributes(a=None, b=0.0, c=False) ``` -------------------------------- ### Get multiple attributes for a selection of vertices Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.volmeshes.rst Retrieves the values of multiple specified attributes for a subset of vertices. ```python >>> volmesh.vertices_attributes(names=["a", "c"], vertices=[0, 1, 2, 3]) [(None, False), (None, False), (None, False), (None, False)] ``` -------------------------------- ### Loading a COMPAS Working Session with Type Hinting Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/advanced.serialisation.rst Shows how to load a COMPAS working session using `compas.json_load` while providing type hints for better code completion and static analysis. ```python # script B from typing import List import compas from compas.datastructures import Mesh from compas.geometry import Box session = compas.json_load('session.json') mesh: Mesh = session['mesh'] boxes: List[Box] = session['boxes'] ``` -------------------------------- ### Get all cells from VolMesh Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.volmeshes.rst Converts the iterator of cells into a list. Cell identifiers are implicit and not directly accessible. ```python >>> cells = list(volmesh.cells()) >>> cells [0, 1, 2, 3, 4, ..., 27] ``` -------------------------------- ### Get all faces from VolMesh Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.volmeshes.rst Converts the iterator of faces into a list. Face identifiers are implicit and not directly accessible. ```python >>> faces = list(volmesh.faces()) >>> faces [???] ``` -------------------------------- ### Test Points Against a Box Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/firststeps.rst Creates a box and a point cloud, then tests which points lie inside the transformed box, visualizing the results with different colors. ```python from compas.geometry import Box, Pointcloud from compas.colors import Color from compas.scene import Scene box = Box(1, 1, 1) pcl = Pointcloud.from_bounds(x=10, y=10, z=10, n=100) box.rotate([0, 0, 1], 45) box.translate(pcl.centroid) scene = Scene() scene.add(box) for point in pcl: color = Color.red() if box.contains(point) else Color.blue() scene.add(point, color=color) scene.draw() ``` -------------------------------- ### Get all edges from VolMesh Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.volmeshes.rst Converts the iterator of edges into a list. Edges are represented as tuples of vertex identifiers. ```python >>> edges = list(volmesh.edges()) >>> edges [(0, 1), (0, 4), (0, 16), (1, 2), (1, 5), ..., (62, 63)] ``` -------------------------------- ### Load Mesh from File Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.meshes.rst Loads mesh data from common file formats like OBJ, OFF, PLY, and STL using dedicated constructor methods. ```python from compas.datastructures import Mesh mesh = Mesh.from_obj('mesh.obj') mesh = Mesh.from_off('mesh.off') mesh = Mesh.from_ply('mesh.ply') mesh = Mesh.from_stl('mesh.stl') ``` -------------------------------- ### Adding a Box to the Scene Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.visualisation.rst Demonstrates how to create a Box object and add it to the COMPAS scene. The scene will automatically use the correct object implementation based on the current context. ```python box = Box.from_width_height_depth(1, 1, 1) scene.add(box) # Expected output: ``` -------------------------------- ### Mesh Utilities Source: https://github.com/compas-dev/compas/blob/main/docs/api/compas.datastructures.Mesh.rst Utility methods for mesh operations like getting a summary, copying, or clearing the mesh. ```APIDOC ## Mesh.summary ### Description Returns a summary of the mesh, including the number of vertices and faces. ### Method `Mesh.summary()` ### Returns * (str) - A string containing the mesh summary. ## Mesh.copy ### Description Returns a deep copy of the mesh. ### Method `Mesh.copy()` ### Returns * (compas.datastructures.Mesh) - A new mesh object that is a copy of the original. ## Mesh.clear ### Description Removes all vertices and faces from the mesh. ### Method `Mesh.clear()` ``` -------------------------------- ### Update pip in Blender Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/cad.blender.rst Before installing COMPAS, it's recommended to update pip using the Blender Python executable. ```bash /Applications/Blender.app/Contents/Resources/4.2/python/bin/python3.10 -m pip install --upgrade pip ``` -------------------------------- ### Basic Arithmetic with Points Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.geometry.points_and_vectors.rst Illustrates basic arithmetic operations (addition, subtraction, scalar multiplication, and division) between Point objects and scalars, or between a Point and a list/tuple. ```python a = Point(1, 0, 0) b = Point(0, 1, 0) a + b Point(x=1.0, y=1.0, z=0.0) a - b Vector(x=1.0, y=-1.0, z=0.0) a * 2 Point(x=2.0, y=0.0, z=0.0) a / 2 Point(x=0.5, x=0.0, z=0.0) a + [0, 1, 0] Point(x=1.0, y=1.0, z=0.0) ``` -------------------------------- ### Configure GHPython Componentizer Source: https://github.com/compas-dev/compas/blob/main/docs/devguide/ghcomponent.rst Configure the GHPython Componentizer by specifying source, target directories, and a prefix for your package. ```python ns.configure( { "ghuser": { "source_dir": "src/compas_bananas/components", "target_dir": "src/compas_bananas/components/ghuser", "prefix": "(COMPAS_BANANAS)", }, } ) ``` -------------------------------- ### Import Local Module in Grasshopper Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/cad.grasshopper.rst Example of importing a local module, such as `my_module.py`, which is in the same folder as your Grasshopper file, after enabling auto-reloading. ```python import my_module ``` -------------------------------- ### torus_to_rhino_brep Source: https://github.com/compas-dev/compas/blob/main/docs/api/compas_rhino.conversions.rst Converts a COMPAS torus to a Rhino Brep. ```APIDOC ## torus_to_rhino_brep ### Description Converts a COMPAS torus to a Rhino Brep. ### Parameters * **torus**: `compas.geometry.Torus` - The COMPAS torus object. ### Returns * `Rhino.Geometry.Brep` - The Rhino Brep object. ``` -------------------------------- ### Graph Constructors Source: https://github.com/compas-dev/compas/blob/main/docs/api/compas.datastructures.Graph.rst Methods for creating new Graph instances from various data sources. ```APIDOC ## Graph Constructors These methods are used to create new Graph objects. ### `Graph.from_edges(edges, attributes=None)` Creates a graph from a list of edges. ### `Graph.from_json(filepath)` Loads a graph from a JSON file. ### `Graph.from_lines(lines, attributes=None)` Creates a graph from a list of lines. ### `Graph.from_networkx(graph)` Creates a graph from a NetworkX graph object. ### `Graph.from_nodes_and_edges(nodes, edges, attributes=None)` Creates a graph from separate lists of nodes and edges. ### `Graph.from_obj(filepath)` Loads a graph from an OBJ file. ### `Graph.from_pointcloud(pointcloud, threshold=None, attributes=None)` Creates a graph from a point cloud, connecting points within a given threshold. ``` -------------------------------- ### Get Attribute for Selected Vertices Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.meshes.rst Retrieves the value of a specific attribute for a subset of vertices. Useful for targeted attribute queries. ```python mesh.vertices_attribute('b', vertices=[0, 1, 2, 3]) ``` -------------------------------- ### Get Single Attribute for All Vertices Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.meshes.rst Retrieves the value of a specific attribute for all vertices in the mesh. Returns a list of attribute values. ```python mesh.vertices_attribute('a') ``` -------------------------------- ### Create and Access Vector Components Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.geometry.points_and_vectors.rst Illustrates the creation of Vector objects and accessing their components using attribute names or indices. The Z component defaults to zero. ```python from compas.geometry import Vector u = Vector(1.0, 0.0, 0.0) u Vector(x=1.0, y=0.0, z=0.0) u.x == u[0] True u.y = 1.0 u[2] = 1.0 u Vector(x=1.0, y=1.0, z=1.0) Vector(1, 0) Vector(x=1.0, y=0.0, z=0.0) ``` -------------------------------- ### Get Multiple Vertex Attributes Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.meshes.rst Retrieves the values of multiple attributes for a single vertex. Returns a tuple of attribute values. ```python mesh.vertex_attributes(0, ['a', 'b']) ``` -------------------------------- ### Loading a COMPAS Working Session from JSON Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/advanced.serialisation.rst Demonstrates how to load a COMPAS working session previously saved to a JSON file using `compas.json_load`. ```python # script B import compas session = compas.json_load('session.json') mesh = session['mesh'] boxes = session['boxes'] ``` -------------------------------- ### surface_to_rhino Source: https://github.com/compas-dev/compas/blob/main/docs/api/compas_rhino.conversions.rst Converts a COMPAS surface to a Rhino surface. ```APIDOC ## surface_to_rhino ### Description Converts a COMPAS surface to a Rhino surface. ### Parameters * **surface**: `compas.geometry.Surface` - The COMPAS surface object. ### Returns * `Rhino.Geometry.Surface` - The Rhino surface object. ``` -------------------------------- ### Get Vector Direction and Magnitude Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.geometry.points_and_vectors.rst Demonstrates how to retrieve the direction and magnitude (or length) of a Vector object. The direction is represented as a normalized vector. ```python u = Vector(1.0, 1.0, 1.0) u.direction Vector(x=0.5773502691896258, y=0.5773502691896258, z=0.5773502691896258) u.magnitude 1.7320508075688772 u.length 1.7320508075688772 ``` -------------------------------- ### Visualize VolMesh using COMPAS Scene Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.volmeshes.rst Visualizes a VolMesh by loading it from an OBJ file and adding it to a COMPAS Scene. Requires 'compas.scene.Scene' and 'compas.datastructures.Mesh'. ```python from compas.datastructures import VolMesh from compas.scene import Scene mesh = Mesh.from_obj("volmeshring.obj") scene = Scene() scene.add(mesh) scene.show() ``` -------------------------------- ### Create Brep from Native Object Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.geometry.breps.rst Instantiates a COMPAS Brep from a native Brep object provided by a specific CAD environment (e.g., Rhino). ```python >>> import Rhino >>> from compas.geometry import Brep >>> ... >>> Brep.from_native(Rhino.Geometry.Brep()) ``` -------------------------------- ### BibTeX Citation for COMPAS Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/citing.rst Use this BibTeX entry in your LaTeX documents to cite the COMPAS framework. Ensure you have the 'biblatex' or 'natbib' package installed. ```bibtex @misc{compas-dev, title = {{COMPAS}: A framework for computational research in architecture and structures.}, author = {Tom Van Mele and many others}, note = {http://compas.dev}, year = {2017-2021}, doi = {10.5281/zenodo.2594510}, url = {https://doi.org/10.5281/zenodo.2594510}, } ``` -------------------------------- ### cone_to_rhino_brep Source: https://github.com/compas-dev/compas/blob/main/docs/api/compas_rhino.conversions.rst Converts a COMPAS cone to a Rhino Brep. ```APIDOC ## cone_to_rhino_brep ### Description Converts a COMPAS cone to a Rhino Brep. ### Parameters * **cone**: `compas.geometry.Cone` - The COMPAS cone object. ### Returns * `Rhino.Geometry.Brep` - The Rhino Brep object. ``` -------------------------------- ### Get Nodes by Name Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.trees.rst Retrieve a list of all nodes in the tree that match a given name. This is useful for finding specific nodes when their names are known. ```python nodes = tree.get_nodes_by_name('branch1') nodes ``` -------------------------------- ### Restart RPC Server Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/advanced.rpc.rst Restarts the COMPAS RPC server. This is useful for reloading functionality or applying changes made to packages after the server has started. ```python >>> from compas.rpc import Proxy >>> proxy = Proxy() >>> proxy.restart_server() ``` -------------------------------- ### Get Multiple Attributes for All Vertices Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.meshes.rst Retrieves the values of multiple attributes for all vertices. Returns a list of tuples, where each tuple contains the attribute values for a vertex. ```python mesh.vertices_attributes(['b', 'c']) ``` -------------------------------- ### Assembly Source: https://github.com/compas-dev/compas/blob/main/docs/api/compas.datastructures.rst Represents an assembly of components. ```APIDOC ## Assembly ### Description Represents an assembly of components. ### Class compas.datastructures.Assembly ``` -------------------------------- ### Get Single Vertex Attribute Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.meshes.rst Retrieves the value of a specific attribute for a given vertex identifier. Use when only one attribute's value is needed. ```python mesh.vertex_attribute(0, 'a') ``` -------------------------------- ### Tree Constructors Source: https://github.com/compas-dev/compas/blob/main/docs/api/compas.datastructures.Tree.rst Methods for creating new Tree instances. ```APIDOC ## Tree.from_json ### Description Creates a Tree object from a JSON file. ### Method `Tree.from_json(filepath)` ### Parameters * **filepath** (str) - The path to the JSON file. ### Returns * Tree - The constructed Tree object. ``` -------------------------------- ### Calculate Angles Between Vectors Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.geometry.points_and_vectors.rst Demonstrates how to calculate the angle between two vectors in radians. It also shows how to get signed angles with respect to a normal vector. ```python u = Vector(1, 0, 0) v = Vector(0, 1, 0) u.angle(v) 1.5707963267948966 u.angles(v) (1.5707963267948966, 4.71238898038469) u.angle_signed(v, normal=[0, 0, -1]) -1.5707963267948966 ``` -------------------------------- ### Construct VolMesh from Scratch (Unit Cube) Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.volmeshes.rst Constructs a VolMesh with one cell representing a unit cube. Vertices are added first, followed by the cell definition using face vertex lists, ensuring face normals point inwards. ```python from compas.datastructures import VolMesh volmesh = VolMesh() a = volmesh.add_vertex(x=0, y=0, z=0) b = volmesh.add_vertex(x=1, y=0, z=0) c = volmesh.add_vertex(x=1, y=1, z=0) d = volmesh.add_vertex(x=0, y=1, z=0) e = volmesh.add_vertex(x=0, y=0, z=1) f = volmesh.add_vertex(x=1, y=0, z=1) g = volmesh.add_vertex(x=1, y=1, z=1) h = volmesh.add_vertex(x=0, y=1, z=1) faces = [[a, b, c, d], [e, h, g, f], [a, e, f, b], [b, f, g, c], [c, g, h, d], [a, d, h, e]] cell = volmesh.add_cell(faces) ``` -------------------------------- ### Get Node by Name Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.trees.rst Retrieve a single node from the tree that matches a given name. Assumes names are unique or returns the first match found. ```python node = tree.get_node_by_name('branch1') node ``` -------------------------------- ### Serializing and Deserializing Mesh to JSON File Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.datastructures.meshes.rst Saves a mesh to a JSON file and then loads it back, demonstrating file-based serialization. ```python mesh.to_json('mesh.json') ``` ```python mesh = Mesh.from_json('mesh.json') ``` -------------------------------- ### Create Special Planes Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/basics.geometry.planes_and_frames.rst Construct predefined planes such as worldXY, worldYZ, and worldZX using class methods. ```python xy = Plane.worldXY() print(xy.normal) ``` ```python yz = Plane.worldYZ() print(yz.normal) ``` ```python zx = Plane.worldZX() print(zx.normal) ``` -------------------------------- ### Saving a COMPAS Working Session to JSON Source: https://github.com/compas-dev/compas/blob/main/docs/userguide/advanced.serialisation.rst Example of how to save a dictionary containing various COMPAS objects (Mesh, Boxes) to a JSON file using `compas.json_dump`. ```python # script A import compas from compas.datastructures import Mesh from compas.geometry import Pointcloud, Box box = Box.from_width_height_depth(1, 1, 1) mesh = Mesh.from_poyhedron(12) boxes = [] for point in Pointcloud.from_bounds(10, 10, 10, 100): boxcopy = box.copy() boxcopy.frame.point = point session = {'mesh': mesh, 'boxes': boxes} compas.json_dump(session, 'session.json') ``` -------------------------------- ### ColorDict Source: https://github.com/compas-dev/compas/blob/main/docs/api/compas.colors.rst A dictionary for storing colors with string keys. ```APIDOC ## ColorDict ### Description A dictionary for storing colors with string keys. ### Class compas.colors.ColorDict ```