The next part of this two-part series focuses on the actual placement of the adaptive component (Part One can be found here: https://paraanalytics.wordpress.com/2013/01/07/revit-adaptive-components-practical-architypes-the-vaulted-ceiling/. This part might tend to get boring since it entails the endless picking of Grid Intersections for all the bays of the building. Fortunately, this does not have to be the case: anytime you see a repetitive task, think of the purpose for inventing machines – the computer in this case. The only variables in this case are the eight Adaptive Points and they can be abstracted away in terms of their x & y coordinates ( the z coordinate is not being considered since it is being controlled by the internal instance parameters of the Adaptive Component). Once this information is read by a python code, it is just a matter of telling the python code to place the Adaptive Points at those coordinates.
I am no programmer, but reading through Nathan Miller’s blog, The Proving Ground, I was able to cobble together some of his code structures and tweaked it to place my Adaptive Component. I’m sure there’s tons of room for improvement – optimization – I believe is the technical term. I have posted the final version of the code further down, but for now I’ll describe the process linearly.
The first Step is to obtain the x & y coordinates on which the Adaptive components should be placed. In our case, the points coincide with the Column Grid.
This can be easily done with the Spot Coordinate tool within the project environment. This information can then be manually transcribed into a spreadsheet. I’m sure one can write a routine to automate this process, but then I decided that it would be more computing than I can handle at the moment.
The code that we write will have to do three things:
- Prime the Adaptive Component for Placement
- Open the Excel File and read the x & y coordinates for each placement instance of the Adaptive Component
- Place the component at the points indicated by the x & y coordinates listed in Step 2.
Below are the steps that describes these steps and the intermediate steps in detail. WARNING: The description is solely my interpretation of what’s going on and may not be what’s actually going on. Hey, but if the ends justify the means, this is it!
|This Step Initializes the code, loads all the requisite libraries and starts the transaction.|
|This step makes sure that you have Excel installed and it can access it.|
|This is where you specify the number of instances (Bays in the ceiling) you want to place an Adaptive Component it and the number of Adaptive points in the component|
|This is where you tell the software where to look for the x & y coordinate values. Essentially, you are specifying where to start and setting up the end points based on the Number of Bays you specified in the previous step.|
|Start the outer loop to run everything inside the loop for as many times as the Number of Bays. The operation inside essentially consists of placing a single Adaptive component. This particular step consists of assigning the name of the Adaptive Component Family to a variable (symbName). Then we prime a ‘Collector’ object to pick the Component by Resetting it.|
|Next we iterate through the project to find the Adaptive Component Family and the instance properties of each point. Once we find these two ‘Objects’ we can then assign values to place the Component.|
|This step initializes three ‘array’ variables for 1) the Adaptive Point, 2) The Coordinate Location of the Point, and 3) the Translational Motion required to place the point from the initial 0,0,0 location. Then we create a loop that initializes each of the Adaptive Point objects (adptPoint[i]) using the aPt.append() method|
|Next we have a nested loop (this could have been differently based on how the Excel Spreadsheet was set up) that collects the x & y coordinates from the Excel Spreadsheet (using the loc.append() method)|
|Finally, each of the Adpative Points are moved to the Coordinate x & y locations using the ‘ElementTransformUtils’ function using the initial location (adptPoints[i]) and moving it to the final location using trans[i] variable that is read from the spreadsheet. Finally we finish the operation by committing the transaction. Note: I had to use the variable ‘j’ for this to work as expected. I will appreciate any input that points to the flaw in the logic.|
Finally, after a couple of days of bitter wrangling with the Iron Python I was able to get to the code above. I know that its far from perfect, but this is all I had time for and any suggestions to improve it are more than welcome. Below is the result of running the code.
And here is the code on pastebin… have fun!