Grasshopper

algorithmic modeling for Rhino

Hi everyone,

 

I encountered one problem while executing this simple code in GhPython below:

 

import rhinoscriptsyntax as rs
rs.RebuildCurve(crv, 3, 15)

rs.EnableObjectGrips(crv)

 

the error turned to be:

Runtime error (MissingMemberException): 'AttributedGeometry' object has no attribute 'GripsOn'Traceback:  line 15, in EnableObjectGrips, "C:\Users\Hurriarc\AppData\Roaming\McNeel\Rhinoceros\5.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript\grips.py" 

 

So, I tracked back to the grips.py script, in which, the .gripson method could not work.

Btw,  this code runs ok in Rhino python script editor.

 

Does anyone have any ideas?

Thanks

Views: 2901

Attachments:

Replies to This Discussion

Hi hurriarc,

yes, Grips are not currently implemented.

Most things can work exactly as in Rhino, I hope. Only difference may be that rs.ObjectGripsSelected will only be modifiable through scripting (rs.SelectObjectGrip), because there is no "time" for users to do anything during a Grasshopper recalculation.

The issue is now here:
https://github.com/mcneel/ghpython/issues/30

Thanks,

- Giulio
_______________
giulio@mcneel.com

Hi Giulio,
Thanks for this quick reply and the useful info.
Looking forward to see the update of GhPython.
all the best,
Peter

Actually, maybe I can offer something better.
Here is a workaround: using RhinoCommon.

I hope this helps for now. A tip on using "more exotic" RhinoCommon methods is also included.

Cheers,

- Giulio
_______________
giulio@mcneel.com

Attachments:

Hi Giulio,

While you're discussing the more exotic ways of RhinoCommon. Do you know if "they" plan to expose the Explode Text methods anytime soon. I was looking at trying to update your textToLines component but cannot see a way to do so.

Danny

Hi Danny,

back then I did not have to do it in "a clean way" as I did not have a @mcneel.com email address. :)

I can imagine a RhinoCommon counterpart to that script, but I'll have to ask Steve if we have something better in this area. Thanks,

- Giulio
_______________
giulio@mcneel.com

 

That is great, really helpful! Thanks a lot, Giulio.

The idea is very clear.

However, I am fresh to RhinoCommon, so here come several questions:

 

1. "coercecurve" is the function pass curve to rhinocommon. 

    how about passing other types of objects?

2. before running the line below:

    curveObj = curveObj.ToNurbsCurve()

    the curveObj is not NURBS representation? why?

 

Sorry for these basic questions. But it will help better understand the code.

And for sure RhinoCommon is very powerful, but I don't know how to set up the link 

between it and python. Are there tutorials that I could go through?

 

Thanks again for your time。

 

yours,

peter

 

Hi Peter,

I meant giving this sample so you could do this without any delay.

1. "coercecurve" is the function pass curve to rhinocommon. 

    how about passing other types of objects?

Just write "rs." and wait a second to see all the coerce(...) functions.
About how they work: they look up the geometry using the ID from inside scriptcontext.doc and make sure that the geometry is of the type you want.

They are written in Python, you can see how they work from the _EditPythonScript editor (just type one, put a breakpoint on that line and enter it with F11).

 

2. before running the line below:

    curveObj = curveObj.ToNurbsCurve()

    the curveObj is not NURBS representation? why?

A curve can be of any of the types that are listed on this RhinoCommon page, in the Inheritance Hierarchy section. Use the Python type(obj) function to discover the type of a variable.

curveObj might be a NURBS curve already, or not. All Curves have a ToNurbsCurve() method that creates a new instance with control poin. For example, a LineCurve only has the Start+EndPoint, and does not really have "control" points from this point of view. An ArcCurve only has a plane and StartAngle+EndAngle, but can be tranformed to a degree-2 NURBS curve with control points as well with this method.

Cheers,

- Giulio
_______________
giulio@mcneel.com

 

Thanks a lot, Giulio. It is really helpful.

One more dumb question, I used to write the code using rhinoscript package: 

like pts= rs.curvepoints(curveObj)

but you write in python: curveObj.Points, which is much shortter and clearer.

I am wondering to start writing in python. But don't know the functions of specfice class. i.e. for the Curve Class, there is funtion: curve.Points, how can i access to other funtions ? Are there any libraries or references? 

Both are Python :)

The difference is that rs.DoSomething is a RhinoScriptSyntax function, while attributes/methods and such things, e.g. curveObj.Points are RhinoCommon. RhinoScriptSyntax functions are written for your utility and speed of coding, using RhinoCommon.

 

RhinoScriptSyntax has the advantage of a easy, "short" list of these functions (I think about 1000 in total) that are nicely explained. RhinoCommon is quite big, with several thousands (I haven't tried counting) methods, constructors, etc etc.

For the RhinoScriptSyntax help, run the _EditPythonScript command, go to Help -> Python Help. (*)

For the RhinoCommon help file, see here -> Online Documentation.

 

I hope this helps,

- Giulio
______________
giulio@mcneel.com

* I'll add a link from the GhPython editor in the next release

 

Thank you for this quick reply. I think I will go through RhinoCommon.

Maybe end with counting how many methods it has got ; )

 

Peter

My pleasure.

Then you might directly request the component to provide RhinoCommon objects instead of using the RhinoScriptSyntax coerce(...) functions.

Right-click the center of the component, and choose "rhinoscriptsyntax usage" -> RhinoCommon.

Inputs will be RhinoCommon geometry after that (rhinoscriptsyntax often does not work with it). To create new objects, you need to import classes from Rhino, Rhino.Geometry, etc.

- Giulio
________________
giulio@mcneel.com

Hi Giulio,

I just opened the code and saw the following lines:

`# pass the object to rhinocommon
curveObj = rs.coercecurve(x)

# NURBS representation
curveObj = curveObj.ToNurbsCurve()`

If rhinoscriptsyntax was written using RhinoCommon, why do you need to pass rs back to it?

Is there no way to import Rhinocommon directly?

Many thanks,

Arthur

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service