Giter Club home page Giter Club logo

ghpython's Introduction

Python interpreter addon for Grasshopper

We are having fun building this Grasshopper-Python component, you are welcome to join us.

Discussions for help on using or configuring this addon can be found at:

Screenshot

Installation / Configuration

You can get a version of this addon ready for installation from http://www.food4rhino.com/project/ghpython

If you are building this addon from source, use the _GrasshopperDeveloperSettings command to add the output directory for your .gha to the list of directories Grasshopper pays attention to.

Contributing to GhPython

There are many ways to contribute to this project:

  • Test the addon and report bugs/wishes to the issue list at https://github.com/mcneel/ghpython/issues
  • Create sample python scripts that we can embed in the addon to help others learn
  • Create sample ghx files for using this addon to help others learn
  • Directly edit the source code using git. If you need help with this, please let us know.

Compiling the Source

You are going to need:

Steps:

  • Get the source code by downloading everything as a zip or using git
  • Copy the appropriate DLLs to the references directory (read the readme.txt in the references directory for a list of DLLs)
  • Start GhPython.sln and build!!!

Authors

Steve Baer - https://github.com/sbaer [email protected]

Giulio Piacentino - https://github.com/piac [email protected]

Legal Stuff

Copyright (c) 2011-2013 Robert McNeel & Associates. All Rights Reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software.

THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF MERCHANTABILITY ARE HEREBY DISCLAIMED.

Rhinoceros is a registered trademark of Robert McNeel & Associates.

Rhino Python

ghpython's People

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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ghpython's Issues

Script -> Component

Add the ability to convert a ghpython script into a stand-alone grasshopper component

rs.TransformObjects does not convert to ID

rs.TransformObjects( geo, xform, True ) does not work on geometry input from an outside component. is a Brep or any other geometry type.

Specific example:
Create a GHpython component with the x input as a Box or any Brep.

Code:

sample script to show how to use this component and rhinoscriptsyntax

import math
import rhinoscriptsyntax as rs

geo = x
cplane = rs.WorldXYPlane()
xform = rs.XformRotation2(y, cplane[3], cplane[0])

rs.TransformObjects( geo, xform, True )

I realize if I use the code:

geo=ghdoc.Objects.AddBrep(x)

to create an ID I can use in rs.TransformObjects, but that line should not be required.

Marshaling a complex number

If I create a complex number in Ghpython:

b = complex(1.0,2.0)

And I output into Grasshopper. Then try to run it into a Complex number param. It does not look like a complex number to Grasshopper.

I think with some marshaling this could be a complex to grasshopper.

Can we get a GHDoc Type Hint

In the the input Type Hint could use a GhDoc type. This would create an incoming geometry ID automatically. Steve know about this if you need more information.

"Preview Mesh Edges" on output meshes.

Hi Steve,

If one outputs a mesh from a GhPython component this mesh does not "respect" the GH setting "Display -> Preview Mesh Edges". Specifically, the mesh always renders with edges turned on.

This is not a huge deal obviously, but I do tend to issue my components in "neat packages" in which all the output "looks nice" and predictable. Usually also with a custom Rhino DisplayMode accompanying the GH definition. So if this bug could be fixed that would be great.

Best,

Anders

Add Grasshopper assembly for easy import

I often import the Grasshopper assembly in order to construct data trees for outputting nested Python lists and such.

In order to do this I usually do this:

import clr;
clr.AddReference("Grasshopper")
import Grasshopper as gh

While this is not a major problem, it would be great if the Grasshopper assembly was automatically added so I could simply go:

import Grasshopper as gh

Cheers,
Anders

Provide CodeContext?

In trying to load the NumPy packages through ghpython, I seem to need the CodeContext of the ironpython instance. Would someone now how to access this, or could you make it available?

gh_python breakage

Right now, if I create a new grasshopper definition, and add a ghpython component, the fresh component returns the following error:

Runtime error (MissingMemberException): 'ScopeStorage' object has no attribute 'scriptcontext'
Traceback (most recent call last):
AttributeError: 'ScopeStorage' object has no attribute 'scriptcontext'

I've tried changing the rhinoscriptsyntax usage to all different settings, and it appears to occur without regard to any input code.
First began after I copied and pasted a python component from an existing definition into a new definition.

Now to try other basic tactics (restart Rhino, computer, etc.) ...

Failure to coerce line

This is the exact error I get:

Runtime error (ValueErrorException): Could not convert c8d0071b-9239-4e44-b719-4a91f7eef3d0 to a list of points
Traceback:
  line 421, in coerce3dpointlist, "C:\Users\benjamin\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\utility.py"
  line 530, in coerceline, "C:\Users\benjamin\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\utility.py"
  line 44, in LineIsFartherThan, "C:\Users\benjamin\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\line.py"
  line 3, in script

from: http://www.grasshopper3d.com/xn/detail/2985220:Comment:388617

Exterior editor possible?

I was wondering if it is possible to write codes in an exterior editor like vim or emacs? The original editor is quite not friendly to use.

Interface wishes from Mitch

Posted on python forum at http://python.rhino3d.com/threads/994-Grasshopper-python-component-suggestion

Hi Giulio,

OK, thanks! Couple of other things -

  1. Once you put your own script in there, the component can't distinguish from no input, insufficient input or incorrect input. With normal GH components, the first two result in an orange component color, the last with a red. With GHPython it's always red until it's correct. I would like to see the component be orange when one or more inputs are disconnected, don't know if that's possible.

  2. I would like to be able to prompt the user as what the component is expecting at the inputs and and returning at the outputs - right now all you have is "Script variable X..." , but the standard components give you the actual description of the data it is expecting - so that would imply in the input/output manager would have a place to type in these names, and then they could show up when someone hovers the mouse over the spot.

  3. Relative to the above, if a type hint (such as "curve") is given for any input, that the input right click generic "set one data item" changes to the type specific "set one curve"...

Thanks, --Mitch

Fails to solve on initial open

When an existing grasshopper file is opened with a python component. The python engine sometimes fails on the initial execution of the script. The second time the script is executed, everything works fine. I think this is due to the initialization of the python engine occurring in another thread and somewhere a lock is not being set properly.

Coerce3dPoint & Coerce3dVector do not accept Vector3f

When you run mesh face normals through a function that calls Coerce3dPoint or Coerce3dVector, you get an exception.

This affects many functions from the RhinoScriptSyntax module. A workaround is to call Rhino.Geometry.Vector3f.ToString(). These functions work fine with a string version of the vector.

Arthur

Marshaling a Circle

If I create a circle using rs.addcircle or rs.addcircle3pt should create a Rhino Circlecurve. If I try and output that from GHpython it is not marshaled as a Circle in Grasshopper.

Import modules in same folder

It might be useful to be able to import modules that are in the same folder as the ghx file (add ghx folder to search path)

folding code blocks in code editor

In the C# and VB.NET scripting components, it is possible to include functions below the main script, in the editor, and to collapse these code blocks.

It would be really nice to have the ability to collapse blocks of code, so that one could include a large amount of additional functions or classes in a script without compromising readability. This offers an alternative to importing packages.

.Net 4.0 Security Error - GhPython Load Error - Rhino 5

GhPython will not load into Grasshopper because of a CAS .Net conflict. Error message below:

An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.

Followed MS recommendations and added a CAS configuration file in the Rhino System directory and the error is no longer reported but the component will not load. Visual Studio Shell 2010 is installed to develop WTF IronPython applications and this might be the cause of the conflict.

Followed all other MS recommendations - unblocked the file etc.

Add object browser to editor

The object/class/function browser on the left side of the standard script editor (in EditPythonScript), should also be available in the grasshopper component. We should be able to add other libraries to this browser like grasshopper.dll to view what classes and functions are available

Save as python file

The file menu should support saving the script as a stand alone python file. I think the export function is fine, it might just need to be set up to save as a .py file extension

Datatypes in Grasshopper

How would I create these datatypes in GhPython to output as the native Grasshopper datatypes?

  1. Box - should we marshall an rs.Addbox result into a Box type?
  2. Rectangle - should we marshall a rs.AddPlanesurface?

conditional failure

Here is my gh python script:

import Rhino
import scriptcontext
# if the switch is on:
if ImportSwitch == True:
    opt = Rhino.FileIO.FileReadOptions()
    opt.ImportMode = True
    # if the delete is on:
    if DeleteSwitch == True:
        objtype = Rhino.DocObjects.ObjectType.AnyObject
        enumSettings = Rhino.DocObjects.ObjectEnumeratorSettings()
        enumSettings.ObjectTypeFilter = objtype
        guids = [o.Id for o in scriptcontext.doc.Objects.FindByFilter(enumSettings)]
        scriptcontext.doc.Objects.Delete(guids, True)
    # for each file:
    for fpath in FilePaths:
        # import it
        scriptcontext.doc.ReadFile(fpath, opt)
layerTree = []
# get everything on the layers
for layname in LayerNames:
    objs = scriptcontext.doc.Objects.FindByLayer(layname)
    guidString = ','.join([str(obj.Id) for obj in objs])
    layerTree.append(guidString)
a = layerTree

the input variables are:

  • ImportSwitch , Item access, Boolean type hint
  • DeleteSwitch, Item access, Boolean type hint
  • FilePaths, list access, string type hint
  • LayerNames, list access string type hint

scriptcontext.doc is targeted to the Rhino doc, not the gh doc
if ImportSwtich is False, and I change the the contents of FilePaths, I would expect this to not read any files. But it reads files any time that the contents of FilePaths are changed. even while ImportSwitch is off.

... and the guidstrings are a hack becauuse I don't know how to make DataTrees in python. : /

my apologies if I'm posting too many issues. It means that I'm really excited about this component. :D

doc switching, a way to crash things

I think I broke something. If I open rhino 5 and grasshopper (after a fresh reinstall of both and a reboot), get out a new ghpython component and try to switch the target doc, Rhino crashes.

This started happening after I did the following:

I created a module (I'll call it module1) to be imported by the ghpython script. In this module I had a line like this:

# inside of module1
from scriptcontext import doc

I assumed that when I imported the module, it would use the same target doc as set by the ghpython component, but it does not. Instead each imported module targets only the gh doc, not the rhino doc.

So then I tried something that seems to have broken the ghpython component. In the imported module, I removed the line containing from scriptcontext import doc. But within the module, I had functions that still made use of a module-level global variable called doc that was not assigned within that module. So I tried to pass the doc object from the ghpython script into the module like so (as seen in the ghpython script):

# in the ghpython script
from scriptcontext import doc
import module1
module1.doc = doc # I think this was a bad idea, but I was curious
from module1 import myfunction # myfunction makes use of doc
myfunction()

The script ran once, correctly using the rhino doc as the target doc for both myfunction as well as in the ghpython script.
Then Rhino crashed, and I haven't been able to set the target doc without crashing Rhino since.

I'm curious how and if I really broke something that could not be fixed with a reinstall and a reboot.

Thanks.

Implement debugger

The python component really needs a debugger similar to the one in EditPythonScript

Mashalling an arc

If I use rs.AddArc, rs.AddArc3pt or rs.AddArcPtTanPt then I should get an ArcCurve. When i pass this out ghpython, I do not get an Arc. Can we marshal an arc from the guiid?

.Net 4.0 Security Error - GhPython Load Error - Rhino 5

Grasshopper fails to load the GhPython scripting plugin and the error message below is displayed:

Exception System.NotSupportedException:
Message: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.

Followed MS recommendations and added a CAS configuration file in the Rhino System directory and the error is no longer reported but the component will not load. Visual Studio Shell 2010 is installed to develop WTF IronPython applications and this might be the cause of the conflict.

Followed all other MS recommendations - unblocked the plugin file etc.

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.