Recently we posted about OkPy and its parent, the Orkestra add-in. I've been using OkPy for several days and have created a few add-ins with it, with zero coding. (I haven't even so much as looked at code.) Here I'll detail the add-ins and the prompts I used to create them. It's a good cross section, from a simple scripting task to a model scanner to interactive element selection, with some snazzy dialog box design and Excel interoperability thrown in for good measure.
A little about my programming background: I have about 30 years of development experience, though it has been almost exclusively with Bentley products, especially MicroStation (I know, boo, hiss!), and primarily with Visual Basic. A few months ago, I tried to create a Revit add-in the traditional way, with C#, but you need to configure Visual Studio to work with Revit and I couldn't find a modern reference for how to do that, so I didn't even get out of the starting block.
First, let's cover an add-in I named Hammer Sync. I wanted a tool that would sync, reload selected links, and sync again. Something I could kickoff and walk away from. This process is handy before exporting CAD files to make sure everything's up to date.
I used the following prompt to create the add-in:
Create a new project named Hammer Sync. In a dialog box, list "Synchronize Now", then all the Revit links in the active file in alphabetical order, and "Synchronize Now" again. To the left of each list item, place an icon appropriate for the task, synchronize for each Synchronize Now and reload for each link. To the far left of each list item, place a checkbox. At the bottom left of the dialog, place "Check None" and "Check All" buttons. If all checkboxes are ticked, lock the Check All button. If some checkboxes are unticked, unlock the Check All button. If no checkboxes are ticked, lock the Check None button. If some checkboxes are ticked, unlock the Check None button. To the right of the list, place an image of a steaming cup of coffee. At the bottom right of the dialog, place "Apply" and "Cancel" buttons. When the user clicks Apply, if the first Synchronize Now list item is checked, synchronize the model. Then, reload each link that is checked in list order. Finally, if the second Synchronize Now is checked, synchronize the model again. To the right of the list, when a list item is being processed, show a clock icon. When a list item is done processing, display a checkmark.
Now, to be fair, it took me four prompts to get this all included, which was fortuitous because that's the number of free prompts OkPy gives you per day. But my first prompt did the lion's share of the work.
Let's see how OkPy works...
You open the OkPy agent through the Orkestra tab:
This opens the OkPy Agent dialog box, where you input prompts:
Once you enter a prompt, the OkPy agent starts thinking. It asked me one question after the above prompt, what kind of dialog box I wanted. I answered Classic:
The OkPy agent took about 5 minutes to complete this task. Total development time was about 20 minutes, and this is what I ended up with:
There are a lot of nice little touches that I didn't ask for, like whether or not a link is loaded, the messages at the top and bottom of the list, the message below the cup of coffee, and the steam coming off the cup of coffee is even animated! This means that it was created programmatically, rather than just being a static image. Also, when running the add-in, there's a nice little warning dialog that I didn't ask for:
Lastly, when running the add-in, there's a progress bar at the bottom of the dialog box, which is more than what Revit gives you:
Most importantly, the add-in works as designed!
Because AI is ever evolving, you may get slightly different results than I did with the same prompt. For instance, the cup of coffee may be a different image. And the added touches may be different, or you may have to add them yourself.
Although the dialog box has some nice bells and whistles—for instance, populating the list with the links in the active file would be challenging programmatically—ultimately, this is an example of a script because it effectively just sequences a list of Revit commands.
For my next add-in, I wanted to create a 3D view showing the elements with warnings colored red, and all other elements with 90% transparency. Here's my prompt:
Create a new project named "Color Warnings". Display a dialog box with the message, "This add-in creates or updates a view named: 3D - Warnings". Add "OK" and "Cancel" buttons. When the user clicks OK, create or update a view named "3D - Warnings". In this view, make all elements with warnings color red. Make all elements without warnings white and 90% transparent. Set the 3D view to an isometric orientation, turn off all links, turn off grids, turn off levels, turn off scope boxes, turn off shadows, set the Detail Level to fine, and set the Visual Style to Shaded. While processing, display a dialog box with a progress bar.
Again, the add-in worked as designed out of the chute, and it's fast! Here's a view created with it:
And, again, the OkPy agent threw in some nice touches: the dialog box lists the number of warnings in the file and the number of types of warnings, and the number of affected elements (I've since tweaked the add-in so I'll show this dialog a little later on in this article).
And the progress dialog is nice:
At this point, I thought, "Wouldn't it be nice if the elements were color-coded based on warning severity?" Revit doesn't rank warnings like this, but it occurred to me that I could do this easily in a spreadsheet if my add-in spit one out. So I used a second prompt to add this functionality:
Before processing, if the file exists in my Documents folder, open the spreadsheet "Color Warnings.xlsx". If it doesn't exist, create it with two columns, "Warning Message" and "Warning Color". For each element with warnings, match the warning message with the color column in the spreadsheet, and assign the element that color. If the warning doesn't exist in the spreadsheet, write it to the spreadsheet and assign it and the element color "Blue". When done, close the spreadsheet.
Simple, right? Not so simple programmatically I'm sure, but it worked! Here's the resulting dialog box:
That's pretty clear!
In the resulting spreadsheet, I then simply assigned the color I wanted each warning to have:
Then I reran the add-in, and here are the results:
Over time, with each model you run the add-in on, you'd effectively be building your own database of Revit warnings with ratings. I use it a little bit differently; I recreate the spreadsheet for each file and send it and a screengrab of the 3D - Warnings view to the project's design team and ask them to correct the red warnings. For yellow, I indicate that they can use their judgement, and I tell them that they can probably safely ignore the green warnings.
Let's do a couple more things. We want it to be easy for the user to open the spreadsheet and, while we're at it, to open the native Revit Warnings dialog. For that, we'll need another prompt:
In the last dialog box, add a checkbox labeled, "Open Color Warnings.xlsx". If any warnings are color blue, tick this checkbox on, or else, untick it. If the checkbox is ticked when the user clicks OK, open the spreadsheet. Add a second checkbox labeled, "Open Warnings dialog box". If this is ticked on when the user clicks OK, open the Warnings dialog. Remember the user's last selection and apply it on the next run.
We end up with something like this:
This is an example of a scanner; it sequences every element in the file and does something to it.
Lastly, I wanted to be able to pick elements and see what their warnings are. With our colored view, that'd be useful, right? Here's my prompt:
Create a new project named "Pick Warning". Prompt the user to select an element to see its warning(s). Allow the user to select an element and, in a dialog box with an "OK" button, display the element's warning(s). When the user clicks the OK button, loop. Exit the application when the user selects a different command or presses the Esc key.
Again, the add-in worked flawlessly, and here's a sample resulting message box:
Handy to know that a single element has multiple warnings, isn't it? And, again, the OkPy agent added some really nice things: the element type and ID of the element, related elements, and instructions on how to exit the add-in. The formatting's very professional too.
This is an example of an interactive add-in.
That's the limit of my explorations with OkPy so far.
In my nearly 40 years in the AEC industry, OkPy is the singular greatest innovation that I've seen. It's the cat's meow, the cream in my coffee. Bravo to the folks at Orkestra!
Speaking of, how do we distribute these add-ins? You need to use Orkestra, and—while there's no barrier to using OkPy or Orkestra (both have free tiers)—you'll need a paid license for both to be able to publish the add-ins. OkPy Pro costs $24/month or $200/year. Orkestra costs $100/year. Bundled together though, the price is $224/year. Downstream users only need the Orkestra license. (And you can also use Orkestra to distribute Dynamo and Grasshopper scripts in a managed way.) Is it worth it? Well, that's a value judgement. But, for me, the answer's a resounding yes.
Someone smarter than me could, perhaps, figure out how to port these add-ins to PyRevit, but I'm not going down that path.
Imagine this tool in the hands of creatives, say architects who've never coded. A colleague of mine very recently participated in such a team that won a hackathon by using OkPy to read redlines from PDFs and make the corresponding changes in Revit. Now that's brilliant!
OkPy earns an A+ from me.
Advertisement















No comments:
Post a Comment