100331-{Show me the CODE}- on Fire- Surface panelization in python . noob lesson 3

abril 1, 2010

another lesson and code for surface panelization in rhino 5 through python… really fun!!.

so , lets show the code!!!

#surface panelization
#script by Diego Pinochet Puentes / escripto.wordpress.com
#Rhino Py lesson 3- Shameless NOOB level- how to make panels from a complez surface.

#import rhinoscript
import rhinoscript as rs
#a little and stupid line to know the init time of the running script
from time import strftime
print strftime("RhPy script initiated at" " %H:%M:%S" "-of-" "%Y-%m-%d")

#user inputs
uDiv= rs.userinterface.GetInteger ("enter the U divisions")
vDiv= rs.userinterface.GetInteger ("enter the V divisions")

#empty array
arrPt=[]

#the first definition that makes an array of points on a surface
def srfpanel():
 #user input for a surface
 srf= rs.selection.GetObject ("select the surface", rs.selection.filter.surface )
 if( srf == None ):
 return
 #redim the list
 for i in range(0,uDiv,1):
 arrPt.append ([0]*vDiv)

 if( uDiv==None or vDiv==None):
 return
 #get the domain of the surface 0 for U and 1 for V
 uDom= rs.surface.SurfaceDomain (srf,0)
 vDom= rs.surface.SurfaceDomain (srf,1)

 #get the coordinates from the domains and add a point
 for i in range (0,uDiv,1):
 for j in range (0,vDiv,1):
 paramU= uDom[0] + i *(uDom[1]-uDom[0])/uDiv
 paramV= vDom[0] + j *(vDom[1]-vDom[0])/vDiv
 arrPt[i][j]= rs.surface.EvaluateSurface(srf,paramU,paramV)
 rs.geometry.AddPoint (arrPt[i][j])
 print arrPt
#end of function


 #definition for the panels
def trianpanel():
 #loop
 for i in range(uDiv-1):
 for j in range(vDiv-1):
 #list that contains the panel coordinates
 panelPt=[]
 #add the four points to the list
 panelPt.append (arrPt[i][j])
 panelPt.append (arrPt[i+1][j])
 panelPt.append (arrPt[i+1][j+1])
 panelPt.append (arrPt[i][j+1])
 #add the panel
 trSrf= rs.surface.AddSrfPt (panelPt)

#end of function


#call the definitions
if( __name__ == '__main__' ):
 srfpanel()
 trianpanel()
 print strftime("RhPy script finished at" " %H:%M:%S" "-of-" "%Y-%m-%d")

#End of the script
<pre>

enjoy, learn and share….

Anuncios

3 comentarios to “100331-{Show me the CODE}- on Fire- Surface panelization in python . noob lesson 3”


  1. Nice Work Diego how are you feeling the sytax is it much easier tha normal Rhinoscript?

  2. escripto Says:

    i dont know if it´s easier, but definetly more intuitive. i think rhinoscriot is a good language to start (for me at least , a self taught coder….). declaring variables as dim, etc etc. this is less explicit but easier and fast.

  3. Juan Pablo Says:

    one question, are all the polygons equal.
    i mean are all the surfaces the same


Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s

A %d blogueros les gusta esto: