Skip to content

Rhino8 gh #1427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
43682b7
created new copy of component definition for cpython
chenkasirer Nov 18, 2024
eaa2be4
removed the v8.0 flag from compas_rhino.install
chenkasirer Jan 16, 2025
5f3fc63
updated changelog
chenkasirer Jan 16, 2025
b5ac928
added configuration for cpython ghuser
chenkasirer Jan 20, 2025
eb505fc
yak template
chenkasirer Jan 20, 2025
098b3a0
added cpython build task
chenkasirer Jan 20, 2025
210b83a
updated gitignore
chenkasirer Jan 20, 2025
4158bb3
moved parent to compas_ghpython
chenkasirer Jan 20, 2025
f9fc9c1
use new publish task
chenkasirer Jan 20, 2025
9e6cfe3
added publish yak workflow
chenkasirer Jan 20, 2025
24a56b3
Merge branch 'main' into rhino8_gh
chenkasirer Jan 20, 2025
7a0c09a
reverted build tasks
chenkasirer Jan 21, 2025
270df26
added requirement header to cpython components
chenkasirer Jan 21, 2025
b752e3f
added pythonnet to dev requirements
chenkasirer Jan 21, 2025
8ceb294
fixed typo in manifest
chenkasirer Jan 21, 2025
a031814
added requirement header to components
chenkasirer Jan 27, 2025
96cf91c
Merge branch 'rhino_v8_flag' into rhino8_gh
chenkasirer Jan 27, 2025
d6a4226
updated changelog
chenkasirer Jan 27, 2025
e2c4297
removed __init__ from new non-package
chenkasirer Jan 27, 2025
9d8c448
Merge branch 'main' into rhino8_gh
chenkasirer Jan 27, 2025
6e23721
formatting
chenkasirer Jan 27, 2025
df318b8
inherit from the new SDK mode parent
chenkasirer Jan 27, 2025
08ade8b
forgot one
chenkasirer Jan 27, 2025
ab8360b
renamed components
chenkasirer Jan 27, 2025
30baeb5
error handling
chenkasirer Jan 27, 2025
90557d0
lint ignore
chenkasirer Jan 27, 2025
dd7de8f
typing
chenkasirer Jan 27, 2025
c450e8f
readability. publish rhino8 package
chenkasirer Jan 28, 2025
7e417e2
no space in keyworks allowed
chenkasirer Jan 29, 2025
ad33b94
better icon
chenkasirer Jan 29, 2025
23ae554
keywords are case sensitive
chenkasirer Feb 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/workflows/publish_yak.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: publish_yak

on: workflow_dispatch

jobs:

publish_test_yak:
runs-on: windows-latest

steps:

- name: Checkout repo
uses: actions/checkout@v4

- name: Create CPython Grasshopper user objects
run: |
invoke build-cpython-ghuser-components

- name: Create IronPython Grasshopper user objects
run: |
choco install ironpython --version=2.7.8.1
invoke clean
invoke build-ghuser-components

- name: Create Rhino7 Yak package
shell: pwsh
run: |
invoke yakerize -m $YAK_TEMPLATE\manifest.yml -l $YAK_TEMPLATE\icon.png -g $USER_OBJECTS -t rh7
env:
USER_OBJECTS: src\compas_ghpython\components\ghuser
YAK_TEMPLATE: src\compas_ghpython\yak_template

- name: Create Rhino8 Yak package
shell: pwsh
run: |
invoke yakerize -m $YAK_TEMPLATE\manifest.yml -l $YAK_TEMPLATE\icon.png -g $USER_OBJECTS -t rh8
env:
USER_OBJECTS: src\compas_ghpython\components_cpython\ghuser
YAK_TEMPLATE: src\compas_ghpython\yak_template

- name: Publish to Yak test server (Rhino 7)
shell: pwsh
run: |
$file = Get-ChildItem -Path dist\yak_package\*rh7*.yak -File | Select-Object -ExpandProperty Name
invoke publish-yak --test-server -y $file
env:
YAK_TOKEN: ${{ secrets.YAK_DF_TOKEN }}

- name: Publish to Yak test server (Rhino 8)
shell: pwsh
run: |
$file = Get-ChildItem -Path dist\yak_package\*rh8*.yak -File | Select-Object -ExpandProperty Name
invoke publish-yak --test-server -y $file
env:
YAK_TOKEN: ${{ secrets.YAK_DF_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ data/ctralie

# Grasshopper generated objects
src/compas_ghpython/components/**/*.ghuser
src/compas_ghpython/components_cpython/**/*.ghuser

dev

Expand All @@ -149,4 +150,4 @@ docs/reference/__old/

scripts/

.ruff_cache
.ruff_cache
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

* Added implementation for `compas_rhino.geometry.RhinoBrep.from_step`.
* Added CPython implementations of GH components for Rhino8.
* Added import to new `yakerize` task from `compas_invocations2`.
* Added import to new `publish_yak` task from `compas_invocations2`.

### Changed

Expand All @@ -18,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Fixed bug in `compas.geometry.Polygon.points` setter by removing duplicate points if they exist.
* Fixed bug in `compas.geometry.Polygon.plane` by aligning the normal of the bestfit plane with the approximate normal of the polygon faces.
* Changed the order of face vertices in `compas.geometry.Surface.to_vertices_and_faces` to a counter clockwise cycling direction and outward facing normals for curved surfaces.>>>>>>> main
* Deprecated the `-v8.0` flag in `compas_rhino.install`. Install to Rhino8 by following: https://compas.dev/compas/latest/userguide/cad.rhino8.html.

### Removed

Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ ruff
sphinx_compas2_theme
twine
wheel
pythonnet
20 changes: 20 additions & 0 deletions src/compas_ghpython/components_cpython/Compas_FromJson/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# r: compas>=2.8.1
"""
Deserializes JSON into COMPAS objects.
"""

import Grasshopper

import compas


class CompasLoadFromJson(Grasshopper.Kernel.GH_ScriptInstance):
def RunScript(self, json: str):
if not json:
return None

try:
return compas.json_load(json)
except Exception:
ghenv.Component.AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Warning, f"Failed to load JSON from path: {json}, Trying as string.") # noqa: F821
return compas.json_loads(json)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "From JSON",
"nickname": "From JSON",
"category": "COMPAS",
"subcategory": "Data",
"description": "Deserializes JSON into COMPAS objects.",
"exposure": 2,

"ghpython": {
"isAdvancedMode": true,
"iconDisplay": 2,
"inputParameters": [
{
"name": "json",
"description": "JSON file path or JSON string.",
"typeHintID": "str"
}
],
"outputParameters": [
{
"name": "result",
"description": "Deserialized objects."
}
]
}
}
16 changes: 16 additions & 0 deletions src/compas_ghpython/components_cpython/Compas_Info/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# r: compas>=2.8.1
"""
Displays information about the active COMPAS environment.
"""

import compas_bootstrapper
import Grasshopper

import compas


class CompasInfo(Grasshopper.Kernel.GH_ScriptInstance):
def RunScript(self):
ghenv.Component.Message = "COMPAS v{}".format(compas.__version__) # noqa: F821
info = "COMPAS Version: {}\nEnvironment: {}"
return info.format(compas.__version__, compas_bootstrapper.ENVIRONMENT_NAME)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions src/compas_ghpython/components_cpython/Compas_Info/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "Info",
"nickname": "Info",
"category": "COMPAS",
"subcategory": "Info",
"description": "Displays information about the active COMPAS environment.",
"exposure": 2,

"ghpython": {
"isAdvancedMode": true,
"iconDisplay": 2,
"inputParameters": [
],
"outputParameters": [
{
"name": "info",
"description": "Environment info."
}
]
}
}
27 changes: 27 additions & 0 deletions src/compas_ghpython/components_cpython/Compas_RpcCall/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# r: compas>=2.8.1
"""
Remote Procedure Call: to invoke Python functions outside of Rhino, in the context of the CPython interpreter.
"""

import Grasshopper
import System

from compas.rpc import Proxy


class CompasRemoteProcedureCall(Grasshopper.Kernel.GH_ScriptInstance):
def RunScript(self, module: str, function: str, parameters: System.Collections.Generic.List[object], path: str, restart: bool):
if not (module and function):
return

if restart:
proxy = Proxy(max_conn_attempts=1)
proxy.stop_server()

proxy = Proxy(module, path=path)
fn = getattr(proxy, function)
parameters = parameters or []

result = fn(*parameters)

return result
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "RPC Call",
"nickname": "RPC",
"category": "COMPAS",
"subcategory": "RPC",
"description": "Remote Procedure Call: to invoke Python functions outside of Rhino, in the context of the CPython interpreter.",
"exposure": 2,

"ghpython": {
"isAdvancedMode": true,
"iconDisplay": 2,
"inputParameters": [
{
"name": "module",
"description": "Module name to import.",
"typeHintID": "str"
},
{
"name": "function",
"description": "Function name to call.",
"typeHintID": "str"
},
{
"name": "parameters",
"description": "List of parameters to pass to the function.",
"scriptParamAccess": "list"
},
{
"name": "path",
"description": "Optional. Path where the module can be found (if not a pip installed module).",
"typeHintID": "str"
},
{
"name": "restart",
"description": "If True, try to restart the RPC server before calling it.",
"typeHintID": "bool"
}
],
"outputParameters": [
{
"name": "result",
"description": "Return value of the function call."
}
]
}
}
22 changes: 22 additions & 0 deletions src/compas_ghpython/components_cpython/Compas_ToJson/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# r: compas>=2.8.1
"""
Serializes COMPAS objects to JSON.
"""

from typing import Any

import Grasshopper

import compas


class CompasDumpToJson(Grasshopper.Kernel.GH_ScriptInstance):
def RunScript(self, data: Any, filepath: str, pretty: bool):
json = filepath

if filepath:
compas.json_dump(data, filepath, pretty)
else:
json = compas.json_dumps(data, pretty)

return json
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions src/compas_ghpython/components_cpython/Compas_ToJson/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "To JSON",
"nickname": "To JSON",
"category": "COMPAS",
"subcategory": "Data",
"description": "Serializes COMPAS objects to JSON.",
"exposure": 2,

"ghpython": {
"isAdvancedMode": true,
"iconDisplay": 2,
"inputParameters": [
{
"name": "data",
"description": "COMPAS data objects to serialize."
},
{
"name": "filepath",
"description": "File path where to store the JSON file. If empty, it will not store to disk but instead return the JSON string.",
"typeHintID": "str"
},
{
"name": "pretty",
"description": "If True, JSON data will be formatted with indentation and key sorting.",
"typeHintID": "bool"
}
],
"outputParameters": [
{
"name": "json",
"description": "JSON file path or JSON string."
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# r: compas>=2.8.1
"""
Draws COMPAS geometry in Grasshopper.
"""

from typing import Any

import Grasshopper

from compas.scene import SceneObject


class CompasToRhinoGeometry(Grasshopper.Kernel.GH_ScriptInstance):
def RunScript(self, cg: Any):
if not cg:
return None

return SceneObject(item=cg).draw()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "Draw",
"nickname": "Draw",
"category": "COMPAS",
"subcategory": "Display",
"description": "Draws COMPAS geometry",
"exposure": 2,

"ghpython": {
"isAdvancedMode": true,
"iconDisplay": 2,
"inputParameters": [
{
"name": "cg",
"description": "The COMPAS geometry or datastructure to be drawn."
}
],
"outputParameters": [
{
"name": "rg",
"description": "The Rhino geometry object."
}
]
}
}
Binary file added src/compas_ghpython/yak_template/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/compas_ghpython/yak_template/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: bluejay
version: {{ version }}
authors:
- tom van mele et. al.
description: The **COMPAS** framework is an open-source, Python-based framework for computational research and collaboration in architecture, engineering, digital fabrication and construction.
url: "https://github.com/compas-dev/compas"
keywords: ["COMPAS", "compas", "framework", "architecture", "engineering", "digital", "fabrication", "construction"]

5 changes: 2 additions & 3 deletions src/compas_rhino/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def install(version=None, packages=None, clean=False):

Parameters
----------
version : {'5.0', '6.0', '7.0', '8.0'}, optional
version : {'5.0', '6.0', '7.0'}, optional
The version number of Rhino.
Default is ``'7.0'``.
packages : list of str, optional
Expand Down Expand Up @@ -47,9 +47,8 @@ def install(version=None, packages=None, clean=False):
# instead of directly as IPy module.
# scripts_path = compas_rhino._get_rhino_scripts_path(version)

# In Rhino 8 there is no scripts folder
if version == "8.0":
installation_path = compas_rhino._get_default_rhino_ironpython_sitepackages_path(version)
raise ValueError("Installing to Rhino8 using this script is no longer supported. See https://compas.dev/compas/latest/userguide/cad.rhino8.html")
else:
installation_path = compas_rhino._get_rhino_scripts_path(version)

Expand Down
Loading
Loading