Organic elevation design from image file using dynamo and Revit

In the previous blog post, we touched upon an interesting idea by creating a parametric facade generator that had the ability to analyse an Image file and then convert it’s pixel data into a usable form. which would later be used to determine the overall look of an architectural facade. in that project we used a non-destructive approach. this means that once the code is written, the user can run the program indefinitely, as many times as they wish with a number of different image files to achieve different results. this is useful when slow and gradual fine tuning of the original design is desirable. if you haven’t read that blog post yet, I highly recommend checking it out by clicking here.

But today, we’re going to be working on a whole different project. in this blog post, I’ll walk you through the process of creating an automated Dynamo Graph that would generate a parametric facade element from a given image file. in other words the designer would “model” this parametric three dimensional form in a two dimensional photo editing environment such as Adobe Photoshop or a similar application, and then use this workflow to transform the flat image into 3d. and finally import the geometry right into Revit for visualization and further documentation. The process consists of four separate steps, and since we’re going to generate our geometry from an image file, naturally the first step is to select, analyze and prepare our bitmap related information. then we can use our newly acquired pixel data to generate an array of points that will later be used to create the final form. so with all that out of the way, lets get coding already!

Although the same results can be achieved with traditional modeling techniques, but the main advantage of using Dynamo is the fact that, once the code is written, generating different results is super fast and extremely efficient.

Step 1: data extraction

This stage includes defining a fixed number of samples that we’re going to extract from our bitmap, it ensures that the code can run smoothly on high definition image files since it eliminates the need to loop and iterate through each and every pixel. here we also implement a mechanism that allows our code to programmatically detect the aspect ratio of the image file and assign a suitable number of samples in both X and Y directions.

High definition image available here
  1. Select image file path.
  2. Read from file and display a preview (optional).
  3. Acquire image width and height using Image.Dimensions.
  4. Input node for the max amount of samples. (100 in this case).
  5. boolean code block (W >= H) reports whether the image is portrait or landscape.
  6. Python script: assign smaller number of samples to the shorter side of the image file.
  1. If” code block: assign max samples to the longer side of the image file.
  2. Image.Pixel: extract the pixels based on the given number of samples.
  3. we want pixel columns as opposed to rows therefore we transpose the list.
  4. using Color.Brightness to get the brightness value of each pixel.

here is the python script used in the graph above (we could’ve just used another If node and just alternate the “true” and “false” input slots).

# Enable Python support and load DesignScript library
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

check = IN[0]
#simple if statement 
if check == True:
    OUT = IN[1]
else: OUT = IN[2]

Step 2: generating array of points

In this step we’ll generate an array of geometrical dynamo points using Point.ByCoordinates node, but to do that we’ll need X,Y and Z coordinates of each point (we’ll acquire those from the pixel data we generated in the previous step with the help of a few Python nodes). lastly we’ll use an additional piece of Python code to add two more points to each sub-list of points. one in the beginning and one in the end of each column to close the loop (note that these additional points are always located of the XY plane, in other words they always have a Z coordinate of zero).

  1. Three Python code snippets, one for generating each coordinate for it’s respective point.
  2. mapping the z values to a user defined range ( this will allow the user to control the height of the geometry).
  3. using Point.ByCoordinate to generate the list of points.
  4. additional Python Code to add the remaining points needed to for a closed loop.

Here is all the Python code that was used:

#Pythone code X
# Enable Python support and load DesignScript library
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

zdepth = IN[0]
filteredX = [[] for i in range(len(zdepth))]
columnNumber = 0


for column in zdepth:
	for z in column:		
		filteredX[columnNumber].append(columnNumber)
	columnNumber += 1

OUT = filteredX
#Python code Y
# Enable Python support and load DesignScript library
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

zdepth = IN[0]
filteredY = [[] for i in range(len(zdepth))]
columnNumber = 0


for column in zdepth:
	zIndex = 0
	for z in column:		
		filteredY[columnNumber].append(zIndex)
		zIndex += 1
	columnNumber += 1

OUT = filteredY
#Python code Z
# Enable Python support and load DesignScript library
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

zdepth = IN[0]
filteredZ = [[] for i in range(len(zdepth))]
columnNumber = 0


for column in zdepth:	
	for z in column:				
		filteredZ[columnNumber].append(z)	
	columnNumber += 1

OUT = filteredZ
# Python code Additional Points
# Enable Python support and load DesignScript library
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

lists = IN[0]

for pts in lists:
	if pts[0].Z != 0:
		pointS = Point.ByCoordinates(pts[0].X,pts[0].Y,0)
		pts.insert(0,pointS)
	if pts[-1].Z != 0:
		pointE = Point.ByCoordinates(pts[-1].X,pts[-1].Y,0)
		pts.insert(len(pts),pointE)
OUT = lists

Step 3: generating solid geometry

Now that we have the much needed list of points, the rest is just a matter of generating the relevant kinds of geometry, this is a rather painless process thanks to the amazing geometry generation tools offered by Dynamo.

  1. Generating curves that run trough each of our point sub-lists.
  2. joining the curves into PolyCurves.
  3. closing the curve loop using PolyCurve.CloseWithLine.
  4. Generating surfaces from the curve loops.
  5. turning the surfaces into solid Geometry using Surface.Thicken.

Step 4: exporting to Revit

Now all that’s left is to export the geometry back to Revit. there are many approaches to do so, in a real world project you might wanna import the geometry in the form of a family, but in this demonstration I’ll use a simple ImportInstance.ByGeometries node for the sake of simplicity.

  1. Removing potential problematic instances using Manage.RemoveNulls, this is a protective measure against importing errors down the line.
  2. Importing the geometry into Revit using ImportInstance.ByGeometries.

And… we’re done! bellow are some examples designed using this very graph that we just wrote together, this was a rather long blog post but I personally had a ton of fun creating it. thank you so much for your time and I really hope that this tutorial was of some value to you. take care and keep creating!

Parametric facade design from Image file using Revit and dynamo

In this blog post we’re going to use some fundamental Revit and Dynamo skills as well as a builtin Dynamo image processing library to create a workflow that converts an ordinary image into an amazing architectural facade in a matter of minuets (or even seconds depending on your hardware). we’re going to be using curtain walls and custom parametric curtain panels to model this. thus naturally creating the curtain panel family is the first step. after that we’ll learn how to use an image processing library inside of dynamo in order to extract all kinds of useful data from the image file. and last but not least, we’ll use that extracted pixel information to parametrically alter the facade in cool and interesting ways. so without further ado lets get started!

So the first step is to create the parametric curtain panel, the design and geometry for this element are rather simple since we will be placing thousands of these and we really don’t want to push our hardware too far (geometrical detail in the individual family instances is not that important anyways since each instance of this family represents a single pixel which together they create the final impression collectively).

So we’ll start by creating a new family, we will use the template “Metric Curtain Wall Panel”. now we’re good to go… open the exterior view and start by changing the distance between the reference lines (we want to have a 500mm x 500mm panel). once that is done create an extrusion. while in sketch mode, create a rectangular shape and constrain it to the existing reference lines as shown in the image bellow. then draw another rectangle within the first rectangle. we need to constrain this one using an instance parameter. add dimensions to the second rectangle as shown in the second image below, and associate those dimensions with an instance parameter. lets call this parameter “width” for now. once those steps are done, click create form. it’s a good idea to keep the extrusion end at around 100mm.

Constraining the first rectangle to the reference lines…
Constraining the inner rectangle with an instance parameter (width)…

You could also try and create another 20mm extrusion and constrain it to the inner rectangle to represent the glass but we’ll keep things simple for this demonstration. create a new architectural project and import the new family into it and we’re good to go. now that the custom panel family is complete we can move on to the next step and work on our curtain panel. for this demonstration we’ll be using a 50m x 50m curtain wall with 0.5m x 0.5m panels, effectively giving us 10,000 panels (pardon the unrealistic dimensions, this is for educational purposes only). after selecting our custom panel family as our curtain wall panels, we can move on to dynamo.


An image processing library will allow us to manipulate image files and extract valuable data from them. luckily for us, Dynamo happens to be very flexible in this regard, since it allows us to easily import .Net framework libraries and tools, we can even write custom nodes for Dynamo that use external C# libraries using Zero touch (more on this topic soon). but for the purposes of this tutorial we can use a builtin Dynamo node to extract the pixel data as shown in the graph bellow.

Extracting data from selected Image file (note that the image is 100 x 100 pixels) Click Here for high resolution.
  1. Get the file path to the image file
  2. Get file from file path
  3. Read image from file
  4. Get pixel data from image
  1. Get brightness of each pixel
  2. Map the values to our panel’s “width” min and max (0.02 and 0.24 in this case).
  3. Reverse the list

The graph above should be simple enough, I trust that you can easily follow through with it. now that we have extracted pixel brightness values and stored them in a 2 dimensional list (100 lists each containing 100 pixels), we’re ready to move on to the final stage of assigning those values to the relevant panels. selecting all the panels is easy enough but we need some simple list manipulation to get the lists of panels correspond to our data from the image. the following graph does just that.

Selecting and sorting all the panels in this project (Click Here for high resolution)
  1. Selecting the panel family type
  2. Getting all instances of the family type (10,000)
  3. Get the bounding box
  4. Get it’s centroid
  1. Python code: getting the Z coordinate
  2. Using “GetItemAtIndex” and “Chop” nodes in conjunction with the Z and X coordinates to sort the panels.

The python code block simply loops through the list of points to get their Z coordinates. of course just like the X coordinate, Z coordinate could also be obtained easily using a builtin dynamo node, but I thought that this was a good opportunity to demonstrate the freedom that the python code block offers us. so using it is completely optional, here’s the code:

# Enable Python support and load DesignScript library
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

#creating variables to store the lists of points
pts = IN[0]
z = []

#looping through the list of points and getting their Z component
for pt in pts:
    z.append(pt.Z)

#outputing a list of Z components 
OUT = z

Now all that is left is to assign the values to the panels using a “SetParameterByName” node:


Hit run in dynamo and…. voilà! the facade is complete! I really hope that this tutorial was somewhat useful and that you have enjoyed reading this blog post. keep creating and don’t forget to give something back to the universe!

Done!

The image has been accurately transferred onto our facade!