S206E Lecture 23, 5/26/2016, Interaction between Python and Grasshopper

Similar documents
S206E Lecture 13, 5/22/2016, Grasshopper Math and Logic Rules

S206E Lecture 16, 4/27/2018, Rhino 3D, Grasshopper & Architecture Modeling

S206E Lecture 17, 5/1/2018, Rhino & Grasshopper, Tower modeling

S206E Lecture 15, 4/27/2018, Rhino 3D, Grasshopper, Shanghai Tower modeling

S206E Lecture 22, 5/26/2016, Python and Rhino interface

S206E Lecture 5, 5/18/2016, Importing and Tracing Drawing Information

Lecture 4, 5/27/2017, Rhino Interface an overview

SWITCHING FROM GRASSHOPPER TO VECTORWORKS

S206E Lecture 19, 5/24/2016, Python an overview

S206E Lecture 3, 5/15/2017, Rhino 2D drawing an overview

Autodesk Inventor Design Exercise 2: F1 Team Challenge Car Developed by Tim Varner Synergis Technologies

Spiky Sphere. Finding the Sphere tool. Your first sphere

Tutorial Second Level

3 AXIS STANDARD CAD. BobCAD-CAM Version 28 Training Workbook 3 Axis Standard CAD

Spring 2011 Workshop ESSENTIALS OF 3D MODELING IN RHINOCEROS February 10 th 2011 S.R. Crown Hall Lower Core Computer Lab

SWITCHING FROM GRASSHOPPER TO VECTORWORKS

Generating Vectors Overview

Chapter 2: Rhino Objects

Autodesk Inventor 2019 and Engineering Graphics

This is the opening view of blender.

INTRODUCTION // MODELING PROCESS COMPARISON

Inventor 201. Work Planes, Features & Constraints: Advanced part features and constraints

3D Design with 123D Design

4) Finish the spline here. To complete the spline, double click the last point or select the spline tool again.

RHINO; AN INTRODUCTION + FAKING TRABECULAE; EndOfLine.info;

This tutorial will take you all the steps required to import files into ABAQUS from SolidWorks

CSC 110 Final Exam. ID checked

3D Modeler Creating Custom myhouse Symbols

Parametric Modeling Design and Modeling 2011 Project Lead The Way, Inc.

Envelope Parametric Model using Grasshopper

GRASSHOPPER TUTORIAL 02 PERFORATED CURVATURE.

Verification of Laminar and Validation of Turbulent Pipe Flows

COMPUTER AIDED ARCHITECTURAL GRAPHICS FFD 201/Fall 2013 HAND OUT 1 : INTRODUCTION TO 3D

CMPSCI 187 / Spring 2015 Implementing Sets Using Linked Lists

1. Open up PRO-DESKTOP from your programmes menu. Then click on the file menu > new> design.

SolidWorks Modeler Getting Started Guide Desktop EDA

Introduction to Solid Modeling Parametric Modeling. Mechanical Engineering Dept.

Each trainee receives the official 260 page courseware as part of attending this course.

RHINO SURFACE MAKING PART 1

15-110: Principles of Computing, Spring 2018

Exercise Guide. Published: August MecSoft Corpotation

solidthinking Environment...1 Modeling Views...5 Console...13 Selecting Objects...15 Working Modes...19 World Browser...25 Construction Tree...

SCENE FILE MANIPULATION SCENE FILE MANIPULATION GETTING STARTED MODELING ANIMATION MATERIALS + MAPPING RENDERING. Saving Files. Save.

Spira Mirabilis. Finding the Spiral tool. Your first spiral

Case Study 1: Piezoelectric Rectangular Plate

COS 116 The Computational Universe Laboratory 10: Computer Graphics

Feature-based CAM software for mills, multi-tasking lathes and wire EDM. Getting Started

CIS192 Python Programming. Robert Rand. August 27, 2015

Introduction to AutoCAD 2012

CS 051 Homework Laboratory #2

Autodesk Inventor - Basics Tutorial Exercise 1

This lab exercise has two parts: (a) scan a part using a laser scanner, (b) construct a surface model from the scanned data points.

Strategy. Using Strategy 1

Dgp _ lecture 2. Curves

3D Slider Crank Tutorial (Professional)

This document shows you how to set the parameters for the ModuleWorks Material Removal Simulation.

TRAINING SESSION Q3 2016

Python Basics. Lecture and Lab 5 Day Course. Python Basics

Chapter 12: Pull Toy - Solids and Transforms

SWITCHING FROM RHINO TO VECTORWORKS

ECE 480: Design Team #9 Application Note Designing Box with AutoCAD

Sketching Data

Solid Problem Ten. In this chapter, you will learn the following to World Class standards:

Dice in Google SketchUp

TOOLPATHS TRAINING GUIDE. Sample. Distribution. not for MILL-LESSON-4-TOOLPATHS DRILL AND CONTOUR

GDL Toolbox 2 Reference Manual

Solid Modeling: Part 1

LAB # 2 3D Modeling, Properties Commands & Attributes

Module 4B: Creating Sheet Metal Parts Enclosing The 3D Space of Right and Oblique Pyramids With The Work Surface of Derived Parts

Essential Mathematics for Computational Design

Input CAD Solid Model Assemblies - Split into separate Part Files. DXF, IGES WMF, EMF STL, VDA, Rhino Parasolid, ACIS

CAD Tutorial 23: Exploded View

Creating T-Spline Forms

Spring Semester 11 Exam #1 Dr. Dillon. (02/15)

Part 6b: The effect of scale on raster calculations mean local relief and slope

3 Polygonal Modeling. Getting Started with Maya 103

Table of contents 2 / 117

SWITCHING FROM SKETCHUP TO VECTORWORKS

Lesson 17 Shell, Reorder, and Insert Mode

Create a Rubber Duck. This tutorial shows you how to. Create simple surfaces. Rebuild a surface. Edit surface control points. Draw and project curves

Data Handing in Python

SketchUp + Google Earth LEARNING GUIDE by Jordan Martin. Source (images): Architecture

Lesson 1: Creating T- Spline Forms. In Samples section of your Data Panel, browse to: Fusion 101 Training > 03 Sculpt > 03_Sculpting_Introduction.

Computer Graphics Fundamentals. Jon Macey

for ArcSketch Version 1.1 ArcSketch is a sample extension to ArcGIS. It works with ArcGIS 9.1

Adobe Illustrator CS5 Part 2: Vector Graphic Effects

CIS192: Python Programming

QUICK-START TUTORIALS

Animation Basics. Learning Objectives

TUTORIAL 07: RHINO STEREOTOMIC MODELING PART 2. By Jeremy L Roh, Professor of Digital Methods I UNC Charlotte s School of Architecture

GstarCAD Complete Features Guide

Module 4A: Creating the 3D Model of Right and Oblique Pyramids

Hands on practices on products and applications.

NURBS Sailboat on Ocean (Modeling/Animation)

1 awea.com.m y

Dave s Phenomenal Maya Cheat Sheet Polygon Modeling Menu Set By David Schneider

SketchUp Tool Basics

Visual 2012 Help Index

Graphics Pipeline 2D Geometric Transformations

Images from 3D Creative Magazine. 3D Modelling Systems

Transcription:

S206E057 -- Lecture 23, 5/26/2016, Interaction between Python and Grasshopper Copyright 2016, Chiu-Shui Chan. All Rights Reserved. S206E057 Spring 2016 This lecture covers the techniques of using rhinoscriptsyntax in Python particularly for form generation. AddPolyline, AddPoints, AddInterpCurve, and AddLoftSrf are popular methods used and are introduced here briefly for our reference. Then the interaction between Python and Grasshopper are explained in detail. Methods of generating polylines through Python codes: Method A: applying control points to generate the curve. See the image. points = (0,0,0),(20,10,0),(50,-10,0),(100,50,0),(200,0,0),(250,10,0) rs.addinterpcurve(points) AddInterpCurve(points) is a function that will generate a periodic curve, which is a nonrational NURBS curve. Method B: applying control points to generate a curve and display its control points in red color. points = (0,0,0),(20,10,0),(50,-10,0),(100,50,0),(200,0,0),(250,10,0) rs.addinterpcurve(points) rs.addpolyline(points) pts_ids = rs.addpoints(points) rs.objectcolor(pts_ids, [255,0,0]) Method C: Enclosed curve. points = (-12,8.5,0),(0,2.5,0),(12,8.5,0),(18,2,0),(0,-20,0),(-18,2,0),(-12, 8.5,0) cruve1=rs.addinterpcurve(points,3,3) #3 is the degree of the curve, 1 is polyline. #5 is the knotstyle with sqrt spacing (3 is for uniform spacing. pts_ids = rs.addpoints(points) rs.objectcolor(pts_ids, [255,0,0]) ObjectColor(object_ids, color, [red, green, blue]) is a function that will generate RGB colors for the selected objects shown in the wireframe mode, but, not in the Rendered mode. Method D: Creating a series of columns through Python codes. In this example, users are required to input: 1. The values of radius and the height of the column, 2. The number of columns along the X and Y axis, 3. The intended distance on both X & Y directions, and 4. The location of the lower left corner point to start the column series. Creation of columns will be executed by the AddCylinder function and two while loops to control the X and maintain the same X coordination while generating the columns along the Y direction. This program, intended to be run privately without sharing it as class, so, the if name == main function was used for calling the ColSeries function. Coding and run results are shown in the following. Page 1 (5/1/2016)

Arch534 Spring 2016 How to connect Python to Grasshopper in Rhino? There is a Python interpreter in Grasshopper, now in version 0.5.101 called GhPython. The Python syntax in Grasshopper could be found in Food4Rhino Web page. GhPython has the following nature: The GhPython component controls the values of inputs to and outputs from the components. It includes libraries to the.net SDK and huge number of Python add-on functions. It integrates with the new Python Script Editor included in Rhino 5. To install this Grasshopper add-on: if you are new, then you have to connect to the Internet at food4python page, which should be registered as its member first. The GhPython is an open source; its membership and registration are both for free. You can get a version of this add-on ready for installation from http://www.food4rhino.com/project/ghpython. But, a copy is saved on the My.Files server. Here are the sequences of installation. 1. In Grasshopper, choose File > Special Folders > Components folder. Save the gha file in the Components folder, which is: Users/cschan/AppData/Roaming/Grasshopper/Libraries 2. Right-click the file > Properties > make sure there is no "blocked" text (unblock). 3. Restart Rhino and Grasshopper Optional: We could use the _GrasshopperDeveloperSettings command to add the output directory for your.gha to the list of directories that Grasshopper pays attention to. For instance, in the following example, the output file will be sent to the folder with path of c:\534. Page 2 (5/1/2016)

Example one: S206E057 Spring 2016 1. Here is the completed Python code of generating 24 pieces of circles, points, and lines from the for loop. In the coding, the definition of if-then-else on line five is to set the valuable of x empty first before assigning 24 to it. # sample script to show how to use Python in Rhino with rhinoscriptsyntax import math x = None if x is None: x = 24 circles = [] radii = [] #x could also defined as x=24 here. # the group of circles. # the group of radii. for i in range(x): pt = (i, math.cos(i), 0) # a tuple for a point id1 = rs.addcircle(pt, 0.3) # the x coordinate of a new point is the value of i. circles.append(id1) # add the circle to the list. endpt = rs.pointadd(pt, (0, 0.3, 0) ) #add the value of 0, 0.3,0 to the xyz of pt. id2 = rs.addline(pt, endpt) radii.append(id2) 2. This coding will be ported into Grasshopper. Thus, Restart Rhino, activate Grasshopper > Maths > Script > select Python Script and drag the component to the Grasshopper screen. Now, the Python component is on the screen. 3. Double click the Python name area > find the Open Editor function and select it to open the Grasshopper Python Script Editor > load (or write) the Python file to the window. This could be done by copy and paste. 4. The data input methods used in Python are variable declarations. In Grasshopper, it is defined by number sliders or panels. Thus, we have to change the input method in the GHPython script, for instance, adding a number slider to dynamically control the x variable with range of 1<20<50 and link the slider output to the Python GH component s x input. 5. Meanwhile, change the statement of x = 24 on line number 5 as a comment. Result of this will let the Python understand that the data of the variable of x shall be obtained from the number slider mechanism. The default Python component input names of X and Y could be changed to match with the variable names used in Python codes. This could be done by moving the mouse on top of the X (for instance) and right click to change the name on the property window. 6. At this time, we also have to define the variable type of this x as an integer type. Otherwise, the GH will not be able to process the data. Methods of defining Python coding related variable type are the following: Page 3 (5/1/2016)

Arch534 Spring 2016 Right click x variable > Select Type Hint: Int > and Wire Display > Default. 7. Put another number slider, which is a floating number representing the variable of y. Connect the output of the slider to the input of y, which controls the number of 0.3 in the statement of id1 = rs.addcircle(pt, 0.3) on line number 12. So, replace the parameter of 0.3 in the id1 variable with y, as id1 = rs.addcircle(pt, y). 8. Add another variable of z by right click the Python text area > select the variable manager and add an extra variable of Z; or zoom to 500% of the screen to see the + - sign for adding variables. 9. This z variable controls the points y coordinate value on line# 11 (see the image below) as pt = (i, math.cos(i)/z, 0). 10. Add a variable of a on line# 19 as a=circles or a=radii (see the image below) to declare the output of GH component to see results. Then, click on the Test button on the lower left corner of the Editor and OK to complete the Python codes for GH component. (Note: whenever you want to run the Python codes, just click on the Test button.) Page 4 (5/1/2016)

S206E057 Spring 2016 Generating multiple outputs: 1. Divide the case of the last Python coding example to one circle GH component for showing circles. This is the first example of showing one output variable. 2. The second example of showing two output variables of circles and the center point of the circles (CenterPt). These two variables are defined outside of for loop and after the loop is completed, they are available for output. 3. The third example of output three variables to show the center point of the circle (controlptslist), the circle (circles), and the end point of the radius (controlptelist). 4. We could also combine all output units together to make the program more efficient. Methods are to define four variables of (circles, NorthLine, controlptslist and controlptelist) in Python script, operate the functions and statements, then define four output variables in GH component and name them correctly to see geometric results. (Note: the variable input, and execution output of Python codes through GH are more efficient than executing results directly in Python. Also, it is more easy to control the modeling behavior through customized Python coding in GH.) See the results in the following image. Page 5 (5/1/2016)

Arch534 Spring 2016 Example 2: Example of Extruding Rhino surfaces The concept is to explore the different interactions between Rhino model > Python, and Rhino model > Python GH. Here we have to also call another Rhino library names: Rhino.Geometry to be used in the coding. Result are shown on the right side of the picture. Steps of doing it are explained shortly below. Step 1: Generate a Rhino module a. Apply Surface Menu > Corner points to draw two surfaces. b. Use Boolean Difference to create holes on the surface. c. Draw a line, polylilne, or Curve > Free-form > Control points on Front view to represent the distance of extrusion. Either geometry should work fine. Step 2: Develop Python codes for extruding the surface There are two variables of curveobjs and extaxis applied here for saving the geometries of the surface and the extrusion line. After the script is done, then run the Python script to see the results. Codes will be exported to GH next. import Rhino.Geometry as rg curveobjs=rs.getobject("select faces to extend") extaxis = rs.getobject("select extension reference") Extrusion=rs.ExtrudeSurface(curveObjs,extaxis) Step 3: Python Grasshopper coding a. Insert a Python Script component in GH (put the following codes to the Python Script window). b. Set up GH parameters of BREP and Curve in GH, select the resulting boolean surface for BREP and the extension line for the Curve. c. Change the name of x and y input in GH to match the Python variable names of: curveobjs and extaxis, the input type will be set up as brep and curve automatically. d. Make the Python input code as comments (because we will apply GH input mechanisms), rename the output a as the variable name of ExtrudeSurface, see the last line below. Page 6 (5/1/2016)

S206E057 Spring 2016 import Rhino.Geometry as rg #curveobjs=rs.getobject("select faces to extend") #extaxis = rs.getobject("select extension reference") extrusion=rs.extrudesurface(curveobjs,extaxis) Note 1: if you received a run time error message of missing a guid for the curve or for the brep, it might be that the ID (represented by the guid) of the geometry was missed when the geometry was unappropriated selected. It will be called only once, and the way to resolve it is to erase the GH component and reinstall it again. Note 2: this is the simplest method of creating floor plane or solid surfaces directly from GH that runs your own python codes, which could be baked to Rhino as its own geometries. Results of the extrusion Example of loft curves to make surfaces: In this example, there are two curves. The intension is to apply AddLoftSrf to generate a face between these two curses. Here are the Python codes: import Rhino.Geometry as rg HEX1=rs.GetObject("Select the first curve ") HEX2=rs.GetObject("Select the second curve ") Surface = rs.addloftsrf((hex1,hex2))[0] The codes are converted to Python GH scripts as GH component with HEX1 and HEX2 variables accepting two Curve parameter inputs. The AddLoftSrf has the format of: rs.addloftsrf (object_ids, start=none, end=none ) In this example of rs.addloftsrf ((HEX1,HEX2))[0], 1. (HEX1,HEX2) is seen as a list, that has two members. This list of two members is also treated as the object_ids of the two curves. Page 7 (5/1/2016)

Arch534 Spring 2016 2. The [0] means the first element on the list, which is HEX1, shall be used as the starting curve element for the lofted object creation. In Python GH programming syntax, a pair of parenthesis (a,b) makes a tuple, whereas [a,b] makes a list. Tuples and lists are used in different situations and for different purposes. Tuples are immutable, and contain a heterogeneous sequence of elements that are accessed via unpacking or indexing. Lists are mutable and their elements are usually homogeneous and are accessed by iterating over the list. Applications: This loft function could be utilized to generate some simple organic forms in architectural design. F The Column GH component for running the Python codes. Footnote: After the objects were created, some would like to make the objects colorful through the function of ObjectColor. Of course, the function of ObjectColor is available in Python coding environment. But, it has difficulties to run it inside the Python GH script. From the http://www.grasshopper3d.com/forum/topics/bake-tags-w-color Web page, information shows that it is currently impossible to assign colors (or material or layers) to Grasshopper objects because the Grasshopper SDK does not pass this information from an object to another. On the other hand, we could bake objects with a color or a layer into the Rhino document. This is an alternative solution. Expectation and requirements of the final project should check the assignment handout. Here are the summaries for your reference. -- Lectures covered this semester have three modules of Rhino modeling, GH algorithmic modeling and Python programming. Here are the outline of the expected final submission. 1. First level is to have the Rhino model completed for advanced level of parametric operation. Products are Rhino model files. 2. The second level is expected to use GH generate the entire Rhino model. Products would be the gy files. 3. Third level is expected to have at least one Python script done on generating one architectural form of your building. The program should be bug free with clear comments on side to explain the coding methods. Products are the py & gy files. 4. Complete the final with a project summary. Please load all the files to the server for grading. Page 8 (5/1/2016)