GithubHelp home page GithubHelp logo

ibois-epfl / script-sync Goto Github PK

View Code? Open in Web Editor NEW
29.0 0.0 1.0 40.21 MB

Rhino/Grasshopper/VSCode plug-in to run C# and Python (IronPython or CPython) scripts directly from VSCode.

Home Page: https://www.food4rhino.com/en/app/script-sync

License: MIT License

C# 17.48% Python 72.33% JavaScript 0.18% TypeScript 10.01%
cpython csharp ironpython rhino3d script vscode-extension

script-sync's Introduction

script-sync

What is it? Script-sync plug-in to run C# and Python (IronPython or CPython) scripts directly from VSCode into Rhino and Grasshopper. This project is a research utility from the IBOIS lab at EPFL. It was developed and currently maintained by Andrea Settimi.

Why Script-sync? Although Rhino8 has a wonderful IDE, we often miss the nice extensions and functions of a full-fledged IDE like VSCode. Script-sync allows you to run your scripts directly from VSCode, while keeping the Rhino/Grasshopper environment open. This is particularly useful if you have AI-assisted (e.g. GithubCoPilot) code completion.

You can execute the folloing languages from VSCode with script-sync:

CPython IronPython C#
Rhino
Grasshopper

Script-sync in Rhino

Script-sync in Grasshopper

Installation

🦏/🦗 Rhino/Grasshopper: Install script-sync rhino from food4rhino or the packageManager in Rhino (name: "script-sync"). For Grasshopper you might want to get rid of the old version of the plugin before installing the new one. Just right-click on the old icon and click delete.

👩‍💻 VScode: Install script-syncVSCode extension from the VSCode extension marketplace (name: "script-sync")

How to use

🦏 Rhino: To start script-sync in RhinoV8, run the command ScriptSyncStart in RhinoV8. This will start a server that listens to commands from VSCode. To close script-sync in RhinoV8, run the command ScriptSyncStop in RhinoV8.

🦗 Grasshopper: To start script-sync in Grasshopper, add the component script-sync:

  • select_file: click to open a file explorer and connect a script,
  • packages_2_reload: this can be empty in 90% of the cases, but if you develop a custom pypi package, (installed with editable pip mode) you can add the name of the package here to track the changes in its modules.
  • x: classical input parameter, you can add more,
  • stdout: all errors and print() is deviated here,
  • a: classical output parameter, you can add more.

👩‍💻 VScode: Open a script in VSCode and run it in RhinoV8 by pressing F4 to run in Rhino or shift+F4 for Grasshopper. For Python files, add a shebang to the first line of the file to specify the interpreter to use, e.g.:

  • #! python3 to interpret it with CPython
  • ⚠️ #! python2 to interpret it with IronPython (only in Rhino)

Requirements

The plug-in needs to be installed on RhinoV8, Grasshopper and VSCode

Issues

For bugs open an issue on the GitHub repo.

Contribution

All contributions are welcome. Have a look at the contribution guidelines.

References

There are a lot of plug-ins that allow to run Python in Rhino. Among them, CodeListener was working until RhinoV8 and it was a source of inspiration for this project. This is a simplified version, but it can run C# and both IronPython and CPython in RhinoV8.

For code maintainers

Packages are published (.yak and .vsix) automatically when a GitHub release is created.

script-sync's People

Contributors

9and3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

9and3

script-sync's Issues

sticky variables for output component variables

If a variaable is defined in the script like:

o_beams [0,1,2,3]

And then it is erased, the component will still output the list value as it was a sticky value:

image

To do:

  • check for cleaning out the variables from the component if not declared anymore in the script

List py to GhTree convertion not working on scriptsync

There is a problem with lists:

In a normal component if we do

import ghpythonlib.treehelpers as th
o_combinations = th.list_to_tree(o_combinations)

a list is converted to grasshopper tree

But in scriptsync it does not work.. this might be due on how we parse the final part of the output parameters in scriptsync component:

def AfterRunScript(self):
        """
            This method is called as soon as the component has finished
            its calculation. It is used to load the GHComponent outputs
            with the values created in the script.
        """
        if not self.is_success:
            return
        outparam = [p for p in ghenv.Component.Params.Output]
        outparam_names = [p.NickName for p in outparam]
        
        # TODO: add the conversion to datatree for nested lists and tuples
        for idx, outp in enumerate(outparam):
            # detect if the output is a list
            if type(self._var_output[idx]) == list or type(self._var_output[idx]) == tuple:
                ghenv.Component.Params.Output[idx].VolatileData.Clear()
                ghenv.Component.Params.Output[idx].AddVolatileDataList(gh.Kernel.Data.GH_Path(0), self._var_output[idx])
            else:
                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.clear()

Importing/refresh sub_modules not working

If my main.py is calling and importing a modules or sub-modules with this structure:

module
-- file.py
main.py

the file.py will not be refreshed, but it will be correctly imported when Rhino/Gh is open for the first time.

When imported module is modified in python the ghpython should be refreshed

Describe the wished feature
Right now if main.py is importing moduleA.py the modifications in moduleA.py in vscode to be effective you need to go back to main.py and do ctrl + S.

Imported modules should refreshed automatically when saved.
Do not know how possible it is but an option could be:

  • read and check all the imported custom modules imported by the script and add a file-modified-thread to each of the imported modules.

Freezing & crash of the Grasshopper component on Mac

Describe the bug
When click the button of select_file, the UI will freeze and not response anymore.

To Reproduce
As describe above.

Desktop (please complete the following information):

  • OS: MacOS
  • Rhino Version and sub.Version: 8.7.24138.15432

Input `DataTree` parsed automatically into nested lists in python

It would be maybe nice if datatrees are automatically parsed into nested lists in input component. It might slow down the component but thing would be much easier to prototype. On the other hand if we copy paste the script in a new ghlocaluser battery it will not work out of the box.

image

if two instances of Rhino run scriptsync it crashes Rhino

Describe the bug
When you run "_scriptsync" on two different running instances of Rhino, it crashes the last one.

Expected behavior
Scriptsync should probably check if the ip and port is free and if not say that it runs only on one?

Desktop (please complete the following information):

  • Rhino 8.3

When GH file is opened error module python load

Describe the bug
When a gh file with the scriptsync is opened again this error happens in all components:

1. Error running script: script-sync::Error in the code: reload() argument must be a module

image

A reload of the canvas solve the issue but it should be solved.
The component probably should be have a mechnaism for reloading modules that avoids this.

Desktop (please complete the following information):

  • OS:Win

Add the documentation of a RhinoCommons function when `func( ` is typed.

Describe the wished feature
This was a feature in the old ScriptEditor of RhinoV7. When you typed a RhinoCommons function before closing the parenthesis it showed you the documentation of the corresponding function.

Got this as a feedback but I would not know how to implement this properly for now.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.