Programming Programming

2012-04-05_1416

Buildz is very pleased to welcome Lilli Smith for this guest post.  Lilli is a Principal User Experience Designer at Autodesk, which means she researches and defines the look, feel, and function of the products so that software developers can implement them. While she has contributed to a huge number of Revit features over the years, today she is stepping out of her comfort zone to explore the world of code authoring. 

Lilli here. I'm an architect and longtime Revit/Vasari product designer and sit right next to Zach here in the factory.  I've been thinking a lot about building space programming lately. It's a conceptual design activity that is so ripe for computer programming. Like Zach, I am an architect not a coder.  Of course I do have geek tendencies, work for a software company, and have access to a lot of great coding minds so sometimes I do attempt to dabble.  Inspired by some of the scripts in Nathan Miller's Revit API Notebook, I set out to see if I could figure out how to turn a building program from an excel spread sheet into a model in Vasari using Darren Thomas's Revit Python Shell. I liked that with the Python shell you could quickly cut and paste code, save, and run the script immediately - no compiling or other hurdles. I also really appreciated Nathan’s Python examples as I would have never been able to get started without them since my Python knowledge was pretty much non-existent last week. 

[You can download and follow along with these files.]

I started with a simple family Space.rfa which contains a box and some parameters as well as 14 materials with color names (Red, Blue, Green, etc) that I used for the space “color” parameter. I set up the materials because it was easier for me to just create them once in the family than to figure out how to make and set them using the API. I figured that 14 colors were enough for my immediate purposes and I could always add more or get programmatically more fancy.

clip_image001

The first script MakeSpaceTypes.py does the following in Space.rfa:

1. Reads SchoolProgram.csv

2. Creates a type for each space type (Gym, Cafeteria, Library, Classroom, etc)

3. Set parameters to variables in file

Nathan gave me a little preview of this post on dealing with external data that really helped me get this first script working. I still got really stymied by figuring out how to deal with different data types like materials,  strings, and integers though.  My developer friends had to help me a bit here.

After loading the family into a project, I can run the second script place3D.py which places the defined quantity of each type separated by width and length, and at a defined floor height.  Again, my developer friends helped me figure out how to nest the loops properly.  However, being able to experiment with different things quickly by making edits, saving, and immediately running the script, was key to helping me learn how some of the code worked.

clip_image001[4]

Wah lah!  This is a helpful way to quickly visualize the size of a building program, get a kit of parts into a model and then arrange the blocks on a site to start creating a building.  You could also concurrently do energy simulations to see how much it matters if say your Cafeteria is on the south or north side of your building.  Want to change the proportions of a space?  No problem, just adjust the type and all the instances will update.  Use Vasari alignment locking to keep spaces aligned property as their type dimensions change or just replace everything with the script once they proportions have been tweaked.

To make sure the script would work on any program (given the right format of course), I also tried it on HospitalProgram.csv.  The hospital contains spaces on more floors and illustrated how spaces can also be placed three-dimensionally.  

clip_image001[6]

Of course, all of the Vasari/Revit capabilities of filters and schedules can be used on the model to study the program in different ways.  Here any space type containing "Public" is colored red for example.

clip_image001[8]

clip_image002

In the future, it would be fun to figure out different ways to place the spaces - perhaps based on different groupings or other parameters.  It would also be nice to be able to do the placement part in a visual programming tool like Ian Keogh's Dynamo so that it would be easier to programmatically wire up new possibilities.

Download the space planning Vasari files and python scripts here.

Download the Vasari2.5 RevitPythonShell addin from here.

See Nathan Miller’s RPS examples here.

Comments

  1. This looks very exciting and extremely scary. Am I brave enough to dive in to these deep waters ? Where will I find the time ? Should I wait for Lilli to figure it out and build it all in to Vasari 3.7 ?

    This stuff is so important if we are to develop a genuine BIM approach to conceptual design.

    Thankyou

    ReplyDelete
  2. Here is an entire semester long thesis project summed up and solved in a single blog post! Very fascinating! Thank you for the post and a springboard for much more to come...

    ReplyDelete
  3. Genius - pure genius! Thanks for posting this Zach & Lilli!

    Questions:
    *When customizing the py script to point to a different CSV file & location, I get an error: "Traceback (most recent call last):
    File "", line 18, in
    ValueError: Illegal characters in path." - Why?
    *Is there a bit of code in python that will place the mass on a different level instead of simply elevating it?
    *Is there a way to tie the elevation of the mass to equal level to level distance as it gets placed in the project?
    *Instead of placing the masses with a formula of 10*level number, why not multiply it by the height of the tallest mass below (and how to do this)?

    ReplyDelete
  4. More questions:
    *Is there a difference in how a python script handles family parameters vs shared parameters?
    *Is there a difference in how a python script handles type vs instance parameters?
    * Are other parameters in the mass family allowed to have formulas already entered before the script is run?

    ReplyDelete
  5. Maybe autodesk should look into grafting MassFX from the entertainment space as a design tool. Something that's already being done via Kangaroo with gH.

    ReplyDelete
  6. Hello there,
    I think there is a future market for a tool that helps you to *optimize* your building or plant design.
    Thinking of a CAD tool that produces *variants* of your room programming.
    Playing with parameters and seeing the results nearly immediately.
    Minimizing distances, surfaces, costs.

    This could be implemented as a web service, like Kean currently does with his Apollonian Gaskets (see his current post for details)
    http://through-the-interface.typepad.com/through_the_interface/2012/04/calling-a-cloud-based-web-service-from-autocad-using-net.html

    Imagine a service that gets your current Revit model and returns a bunch of new DesignOptions which you can use just a few seconds later.
    You only have to choose one of the suggested variants.
    You could modify it afterwards to adjust it to your personal style.
    The process of sending the model to the web service to get geometrically optimized variants could be invoked again and again.

    Cheers,
    Rudolf

    ReplyDelete
  7. Hello, I used this script in the past, but now that I am trying to port it to Revit 2013 I get the error "AttributeError: 'Settings' object has no attribute 'Materials'" for line 57 of the MakeSpaceTypes script, where materials are "traversed". I can't seem to debug this error, and commenting out materials is a little disappointing. Any suggestions? Did the materials property change in 2013?

    ReplyDelete
  8. Hi Mike,
    Try downloading the scripts again. We updated them a few months ago and I think this problem was addressed.
    Thanks
    Z

    ReplyDelete
  9. Hi Zach and Lillie,

    Thanks for this nice script, I have tried to modify it a bit for my own preferences and added a few lines, but I only got one major issue, how do I change the units to metric ? (I have made a new family with the same parameter names in a metric template, but the script still give my parameters imperial units.

    ReplyDelete
  10. I believe the API only deals in imperial units, and you will need to do conversion in side of your script. That is, it you want something to be a in meters you will need to have the API unit expressed as n*3.28084

    ReplyDelete
  11. Hi, this looks great, but I'm having the same problem as Mike.

    I'm using Revit 2014 and I get the error:

    File "", line 40, in
    AttributeError: 'Settings' object has no attribute 'Materials'

    This is my first time using Python and Revit, so I could be missing something really simple.

    Any thoughts?

    ReplyDelete

Post a Comment