Grasshopper

algorithmic modeling for Rhino

Hi all,

 

I’m new to Grasshopper, python and mainly to Ghpython.

 

I’m struggling to reference a Rhino built geometry or the Gh geometry into my script.

I read many discussions about the similar cases as mine but couldn't manage to make it work.

 

The following script was working on the python module in Rhino, but not in Ghpython.

Note that I have imported a library, and it seems to be importing on Ghpython

--------------------------------------------------------------------------------------------------

from khepri.rhino import *

 

def iterate_quads(f, ptss):

   return [[f(p0, p1, p2, p3)

   for p0, p1, p2, p3

   in zip(pts0, pts1, pts1[1:], pts0[1:])]

   for pts0, pts1

   in zip(ptss, ptss[1:])]

    

def iterate_hexagono(pts, n, v):

 return iterate_quads(lambda p0, p1, p2, p3: hexagono_quad(p0, p1, p2, p3, n, v), pts)  

def hexagono_quad(p0, p1, p2, p3, n, v):

   def chapa(pts):

       return intersection(extrusion(line(pts), 280), shape_from_ref(v.copy_ref(v.realize()._ref)))

       #return extrusion(line(pts), -40)

       

   topo = intermediate_loc(p3, p2) + vx(distance(p3, p2)/4 * n), intermediate_loc(p3, p2) - vx(distance(p3, p2)/4 * n)

   base = intermediate_loc(p0, p1) + vx(distance(p0, p1)/4 * n), intermediate_loc(p0, p1) - vx(distance(p0, p1)/4 * n)

   lateral_esq = intermediate_loc(p3, p0), intermediate_loc(p3, p0) + vx(distance(intermediate_loc(p3, p0),intermediate_loc(p2, p1))/4 * n)

   lateral_dir = intermediate_loc(p2, p1), intermediate_loc(p2, p1) - vx(distance(intermediate_loc(p2, p1),intermediate_loc(p3, p0))/4 * n)

   conex_1 = intermediate_loc(p3, p2) - vx(distance(p3, p2)/4 * n), intermediate_loc(p3, p0) + vx(distance(intermediate_loc(p3, p0),intermediate_loc(p2, p1))/4 * n)

   conex_2 = intermediate_loc(p3, p0) + vx(distance(intermediate_loc(p3, p0), intermediate_loc(p2, p1))/4 * n), intermediate_loc(p0, p1) - vx(distance(p0, p1)/4 * n)

   conex_3 = intermediate_loc(p0, p1) + vx(distance(p0, p1)/4 * n), intermediate_loc(p2, p1) - vx(distance(intermediate_loc(p2, p1),intermediate_loc(p3, p0))/4 * n)

   conex_4 = intermediate_loc(p2, p1) - vx(distance(intermediate_loc(p2, p1),intermediate_loc(p3, p0))/4 * n), intermediate_loc(p3, p2) + vx(distance(p3, p2)/4 * n)

   return chapa(topo), chapa(base), chapa(lateral_esq), chapa(lateral_dir), chapa(conex_1), chapa(conex_2), chapa(conex_3), chapa(conex_4)



s = prompt_shape("Escolha superficie")

v = prompt_shape("Escolha solido")

iterate_hexagono(map_surface_division(lambda p:p, s, 5, 15), 0.5, v)

 

---------------------------------------------------------------------------------------------------





I imported the geometry from another cad software, and then I would select the surface and solid to perform a pattern iteration on the surface to be constrained inside the solid as a internal structure.  

 

The problem is that the surface comes with u, v and normals all weird from the other software so I wanted to pass it through Grasshopper so I can get more control and also perform other computations on Gh on the Ghpython output. Sorry, maybe I’m over complicating. All I want is the Gh inputs working on Ghpython.

 

I’ll attach the Gh definition,. Need help with the Ghpython component, the rest is just me fooling around.

 

When I try to run the sript in Ghpython I get:

 

Runtime error (MissingMemberException): 'NurbsSurface' object has no attribute 'realize'

Traceback:

 line 39, in map_surface_division, "<string>"

I'm also attaching the module I've imported

 

Any help will be very appreciated and sorry about my english

 

Thanks!

 

Views: 469

Attachments:

Replies to This Discussion

Hi Rodrigo

I think here you'd need to check with the developer of "khepri.rhino" how/if it is compatible with GhPython. That library is used in your computations and I am not 100% what it is. It's not pure GhPython.

Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Hi Giulio,

 

Thanks for your reply, I tried some simple scripts using that library and it didn’t work as well, I’am going to check with the developer.

But anyway I’am trying to implement all the definition in Grasshopper though don’t know if Gh supports this kind of iteration, but I guess I can do this on another way, halfway there. So what are the main limitations or advantages of Python instead of GH?

 

See the "Python in Grasshopper" section on the Rhino.Python guides :)

It's a work-in-progress, but Scott did already a lot of great work.

Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Great!

Thanks!

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service