-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: testing out parameter for componentizer
- Loading branch information
Showing
13 changed files
with
227 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,67 +12,16 @@ jobs: | |
- name: Install Python and pythonnet | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.9' | ||
python-version: '3.9.10' | ||
- name: Install pythonnet | ||
run: | | ||
pip install pythonnet | ||
- uses: ./.github/actions/ghpython-components | ||
with: | ||
source: components | ||
target: build | ||
# upload them as artifacts: | ||
source: GH\PyGH\components | ||
target: GH\PyGH\build | ||
|
||
- uses: actions/upload-artifact@v2 | ||
with: | ||
name: ghuser-components | ||
path: build | ||
|
||
build_release_on_tag: | ||
needs: build_ghuser_components | ||
runs-on: windows-latest | ||
name: Build release | ||
if: startsWith(github.ref, 'refs/tags/v') | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: NuGet/[email protected] | ||
|
||
# create a new release | ||
- name: Create Release | ||
id: create_release | ||
uses: actions/[email protected] | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ github.ref }} | ||
release_name: Release ${{ github.ref }} | ||
draft: false | ||
prerelease: false | ||
|
||
# download the artifacts from the previous job | ||
- name: Download artifacts | ||
uses: actions/download-artifact@v2 | ||
with: | ||
name: ghuser-components | ||
path: build/ghuser-components | ||
|
||
# verify the artifacts are downloaded | ||
- name: List artifacts | ||
run: | | ||
ls -l build/ghuser-components | ||
# zip the artifacts | ||
- name: Zip artifacts | ||
run: | | ||
cd build | ||
7z a ghuser-components.zip ghuser-components | ||
# upload the downloaded artifacts as release assets | ||
- name: Upload Release Asset | ||
id: upload-release-asset | ||
uses: actions/[email protected] | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: build/ghuser-components.zip | ||
asset_name: ghuser-components | ||
asset_content_type: application/zip | ||
path: GH\PyGH\build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
from ghpythonlib.componentbase import executingcomponent as component | ||
|
||
import System | ||
import Rhino | ||
import Grasshopper as gh | ||
import sys | ||
import os | ||
import time | ||
|
||
from System.Threading import Thread | ||
from functools import partial | ||
|
||
import rhinoscriptsyntax as rs | ||
|
||
def update_component(): | ||
""" Fire the recalculation of the component solution. """ | ||
# clear the output | ||
ghenv.Component.Params.Output[0].ClearData() | ||
# expire the component | ||
|
||
ghenv.Component.ExpireSolution(True) | ||
|
||
def check_file_change(path): | ||
""" | ||
Check if the file has changed on disk. | ||
:param path: The path of the file to check. | ||
:returns: True if the file has changed, False otherwise. | ||
""" | ||
last_modified = os.path.getmtime(path) | ||
while True: | ||
System.Threading.Thread.Sleep(1000) | ||
current_modified = os.path.getmtime(path) | ||
if current_modified != last_modified: | ||
last_modified = current_modified | ||
update_component() | ||
break | ||
return | ||
|
||
def safe_exec(path, globals, locals): | ||
""" | ||
Execute Python3 code safely. | ||
:param path: The path of the file to execute. | ||
:param globals: The globals dictionary. | ||
:param locals: The locals dictionary. | ||
""" | ||
try: | ||
with open(path, 'r') as f: | ||
code = compile(f.read(), path, 'exec') | ||
exec(code, globals, locals) | ||
return locals # return the locals dictionary | ||
except Exception as e: | ||
err_msg = str(e) | ||
return e | ||
|
||
|
||
class ScriptSyncCPy(component): | ||
def __init__(self): | ||
super(ScriptSyncCPy, self).__init__() | ||
self._var_output = ["None"] | ||
ghenv.Component.Message = "ScriptSyncCPy" | ||
|
||
def RunScript(self, x, y): | ||
""" This method is called whenever the component has to be recalculated. """ | ||
# check the file is path | ||
path = r"F:\script-sync\GH\PyGH\test\runner_script.py" # <<<< test | ||
if not os.path.exists(path): | ||
raise Exception("script-sync::File does not exist") | ||
|
||
print(f"script-sync::x value: {x}") | ||
|
||
# non-blocking thread | ||
thread = Thread(partial(check_file_change, path)) | ||
thread.Start() | ||
|
||
# we need to add the path of the modules | ||
path_dir = path.split("\\") | ||
path_dir = "\\".join(path_dir[:-1]) | ||
sys.path.insert(0, path_dir) | ||
|
||
# run the script | ||
res = safe_exec(path, globals(), locals()) | ||
if isinstance(res, Exception): | ||
err_msg = f"script-sync::Error in the code: {res}" | ||
print(err_msg) | ||
raise Exception(err_msg) | ||
|
||
# get the output variables defined in the script | ||
outparam = ghenv.Component.Params.Output | ||
outparam_names = [p.NickName for p in outparam if p.NickName != "out"] | ||
for k, v in res.items(): | ||
if k in outparam_names: | ||
self._var_output.append(v) | ||
|
||
return self._var_output | ||
|
||
# FIXME: problem with indexing return | ||
def AfterRunScript(self): | ||
outparam = ghenv.Component.Params.Output | ||
for idx, outp in enumerate(outparam): | ||
if outp.NickName != "out": | ||
ghenv.Component.Params.Output[idx].VolatileData.Clear() | ||
ghenv.Component.Params.Output[idx].AddVolatileData(gh.Kernel.Data.GH_Path(0), 0, self._var_output[idx]) | ||
self._var_output = ["None"] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.