When Autodesk released the DirectShape API a few years back - I thought it was fantastic. Finally a way to be able to create arbitrary geometry that could live on within Revit - rather than only the elements that the API let us create in the ways that the API let us create them.
We used this to interesting effect in our own Scan to BIM product - providing a mechanism to capture irregular shapes as Revit geometry. What's also interesting - beyond the creation of geometry, the API allows you to assign these objects to be just about any category you want. Think about that for a moment - you can make any arbitrary piece of geometry, and declare that it is a wall, room, stairs, etc.
This felt incredibly cool but also incredibly dangerous to me, from a BIM perspective. And while assigning some characteristics of a wall come from assigning the wall category - it's not an actual wall element, and there are a lot of limitations there.
This Week
This week I experienced for the first time the down side of this approach. A customer was using one of our other tools on one of their models, and it was throwing a weird exception in our app. We were looking through the logs, and based on what we were seeing, it seemed like a model corruption issue. We had a method which retrieved all of the phases that had rooms assigned to that phase - and one of the rooms apparently had a phase which was not actually a phase in this model. How could this happen? maybe corruption? maybe some kind of issue with the cut-and-paste between models?
We started working on a workaround from that angle - but a day later, the customer was able to share the model with us. When we actually ran it via the debugger, we saw which room the phase was associated with: -1 (nothing). This hadn't seemed possible in our experience. Then we looked closer - the element in question was not actually a Room - it was a DirectShape element. How the heck did that get in there?!?
The real problem in the code, which we had written stuff like this a thousand times over the past 6 or 7 years (since the FilteredElementCollector was invented), looked something like this:
FilteredElementCollector coll = new FilteredElementCollector( myDoc );
IList
Historically, if all you wanted was the elements that were rooms, this was all that you needed.
That said - some API developer had created an addin that made a DirectShape box and assigned it to the Room category.
So - going forward, we as API developers can no longer rely on the category (or even Category/IsElementNotElementType) as reliable indicators of the .NET type in the Revit API.
Our quick fix for this particular issue was:
IList
coll.OfCategory( BuiltInCategory.OST_Rooms ).OfClass( typeof(SpatialElement) ).ToList();
This would ignore any DirectShape elements that were showing up as rooms. We quickly found other places (in other methods) where we had made the bad assumption, and had casting errors like:
IList
coll.OfCategory( BuiltInCategory.OST_Rooms).Cast
The DirectShape elements failed the Cast at runtime.
Even when fixed, these issues are bound to get confusing. I believe in many cases the DirectShape elements may still schedule as their assigned category, so our customers will believe they have N rooms in the model, when in fact only some of them are "real" rooms.
I'm still wrapping my head around it, but I think ultimately you'll just always have to have an "OfClass(typeof(MyDesiredClass))" on the collector. If you don't, you're liable to get things you don't expect.
All-in-all, it's not too bad to address it, if you know about it. The key is that it's a loophole that other developers can open, and all of us who make software where you don't know what other addins have been used will have to make sure that we're double-careful about our assumptions. And I'm not looking forward to digging back through all the code I've ever written and am still supporting to find all of the bad assumptions I made.
Sunday, August 14, 2016
The future minefield of DirectShape Elements.
Posted by
Matt Mason
at
12:45 PM
0
comments
Labels: Revit
Tuesday, June 28, 2011
Point Cloud Fix in Revit 2012 Web Update 1
Posted by
Matt Mason
at
3:28 PM
2
comments
Labels: PointCloud, Revit
Saturday, May 28, 2011
An oddity with Drafting View mirroring
So I was asked if it was possible to mirror a drafting view using the API (apparently the built-in project mirroring doesn't cover drafting views).
It seemed straightforward enough... so I wrote a quick test... and it didn't work...
- it worked fine in a floor plan view
- it didn't work in a drafting view
- the code completed just fine - it just didn't really seem to show any difference.
My initial code is below...
- Get all the elements in the current view
- Use the new ElementTransformUtil class to figure out which could be mirrored, and mirror them.
FilteredElementCollector coll =
new FilteredElementCollector(uiDoc.Document, uiDoc.ActiveView.Id);
IListelems = coll.ToElements();
// make sure that stuff can be mirrored
ListtoMirror = new List ();
foreach (Element elem in elems)
{
if (ElementTransformUtils.CanMirrorElement(uiDoc.Document, elem.Id) == false) continue;
toMirror.Add(elem.Id);
}
So why did this complete successfully, but not show any difference?
The answer is one of those great undocumented elements in the wilds of the Revit database. When I looked in the debugger at what I was actually attempting to mirror, I saw this:

What I see here is a mystery element called "ExtentElem" which is being copied. I have a sneaking suspicion that it might be telling the view the actual extent of what is in it... So how can we exclude it? well - it has no actual category (which is probably a sign that in general we don't want to mirror an element like that!).
So - we add a line like:
if (elem.Category == null) continue;
and voila! we have our drafting view being mirrored.
I wish that I could say that all Revit database mysteries are "easily" solvable like this - there's plenty of times where you just run into a wall, and can't get to what you want... but today's story has a happy ending!
Posted by
Matt Mason
at
9:20 PM
6
comments
Labels: Revit
Monday, May 16, 2011
DWFplus for Revit 2012
Well, it has been forever since I've last posted... I missed the release of the 2012 API and a variety of other announcements. But I'm trying to get back on the horse.
To that end - a quick video to show what I think is a cool new feature of our Utilities for Revit 2012 product - a new utility called "DWFplus".
If you've ever looked at distributing a DWF file, and figuring that Revit ought to be making it chock-full of all my BIM data... you may have been slightly disappointed. The rules for when Revit published a parameter or didn't were arcane - and I'm still not sure if we've accurately reverse engineered them. And certain features like hyperlinks... how is it that AutoCAD can have hyperlinks but not Revit!
So DWFplus is an attempt to change that. It starts with a regular DWF export, but adds in a variety of neat stuff:
- All parameters (or selected parameters) that you want to publish
- Parameters are attached to Tags - not just the elements
- Includes 2D Hyperlinks for any URL parameters (even multiples)
- Parameters are published in 3D as well as 2D.
- Includes some neat 3d viewpoints for 3D DWF views.
Here's a little video to demonstrate:
Note: IMAGINiT Utilities for Revit is available here, and is free for clients that keep their Revit subscription with IMAGINiT.
Posted by
Matt Mason
at
4:15 PM
3
comments
Thursday, April 22, 2010
Revit API 2011: Revit AddIn Manager – Almost Edit & Continue
(part of our ongoing series)
If you’ve been developing for Revit for a while – you groaned significantly when, in Revit 2010, changes were made to Revit that disabled the “Edit-and-Continue” capability within a Revit add-in. That is to say – if you wanted to make a minor code change while Revit was debugging – you had to close Revit (wait for Revit to be totally closed), perform the change, then restart Revit, re-load your model, and then try to get back to the same location. Argh – seems like 2+ minutes down the drain any time this happens.
Enter the “Revit AddIn Manager” – part of the Software Development Kit. This tool has been around since 2009, I think – it historically provided handy mechanism for a developer to test External commands or applications – even when they forgot to add them to the REVIT.INI file. It could both update the INI file for you, or even just launch the command in session.
What’s Different in 2011?
I suspect due to some conversations and posts that were had on Jeremy Tammik’s blog late in the development process, the AddIn Manager has been notably improved – such that while you can’t support edit-and-continue, you can now support updating your code while Revit is running, and just re-running your command inside of Revit.
How does this work? The Addin utility is doing some lifting behind the scenes, including copying the DLL and related files to a temporary folder, and loading the .NET assembly DLL from that location.
What does this mean for us? That when we start up Revit with the debugger attached, we can run the AddInManager. From the AddInManager we can launch our command in a way that loads it into memory before starting the debug process.
While we still cannot edit and continue, we CAN open a second copy of Visual Studio, and make changes by rebuilding the project.
- it allows us to overwrite the project, because the running project was copied to somewhere else.
- we are now able to just re-start the AddIn Manager in order to start our updated version of the command.
The Features of the AddIn Manager
The behind-the-scenes mechanics are described above. It also has (obviously) been enhanced to support the new “.addin file” mechanism rather than the Revit.INI mechanism of registering addins. The command also supports some additional options which can be a little confusing at first. The list of AddIn Manager commands looks like this:
What’s the deal with all this manual, automatic and faceless?
The Manual vs. Automatic entries refer to the new TransactionMode and RegenerationMode that must be assiged to each command. Because the AddIn Manager is going to invoke your AddIn, it would be a problem if AddInManager specified Automatic mode but your code specified manual mode. So you have to pick automatic or manual based on what YOUR command is defined as. NOTE: No mix/match on transaction and regeneration mode… you have to be either Auto/Auto or Manual/Manual. The application will stop you if you pick the wrong one (although the error message leaves something to be desired).
Faceless, while the mechanism seems a little clumsy – is a nice little feature. Fundamentally – it remembers the last command that you executed, and will just execute that again (no user interface, it just does it – that way you don’t need to re-browse, re-select, and re-run the command in question).
Conclusion
If you occasionally work with API developers – get a copy of the AddIn Manager to make it easier to test and setup API AddIns! If you’re a developer, there are now many good reasons to set up the AddIn Manager. So get to it! It’s in the Revit SDK installation folder.
Posted by
Matt Mason
at
1:02 AM
0
comments
Labels: Revit
Revit 2011 API: What’s New in Element Creation
(part of our ongoing series)
Each new version, I go through what is new in the specific API area of element creation. Every CAD API has some logical divisions, from information retrieval, to element creation, to interactivity – and you can tell from how strong each area is what the factory’s focus is in the API.
Revit’s start in this area was weak – the API was more about finding elements and updating parameters than actually creating new elements and geometry. In recent releases, Revit really played catch up – I believe it now supports 101 different element creation methods.
So what’s new in 2011 in this area: in short, not much… This was not an area of focus in 2011, so there’s only a few new things in this specific area:
- NewTruss() – now available in architecture
- NewRebarType()
- NewRebarHookType()
- NewRebarCoverType()
- FaceWall.Create()
The last one is of the greatest interest to me personally. This enables you to create a wall based on a face (typically a face that is on a mass element). This is an advanced technique used in Revit to create complex wall shapes.
Two other items deserve honorable mention here as well:
- UIDocument.PromptForFamilyInstancePlacement() – while not technically a “Element Creation” capability, it opens up some significant doors to more interactive design applications within Revit – by letting the end-user help the developer place the family instance visually.
- SolidSolidCutUtils – A new utility class to help with doing solid-to-solid cuts in the modeling environment. This is typically used either for GenericForm kind of family solids or family instances.
All in all, while this category doesn’t seem like it got much attention in 2011, the fact is that with 101 element types that can be created, it has attained a certain level of maturity. For example, if I scan the Home ribbon in 2011 – it is possible to create almost everything that is available on that toolbar (I think the exceptions are: Ceiling, Model Group (you can’t create a new one), Railing, Ramp, Stairs. That’s really not too bad – and the remaining ones are a little on the obscure/complex side.
So let me hear from you by comments? Are you really waiting for one of the missing elements that can’t be created? or are you just reluctant to do API work with geometry creation until it supports 100%? How many different kinds of elements are YOU creating in your app?
Posted by
Matt Mason
at
12:16 AM
8
comments
Labels: Revit
Saturday, April 17, 2010
Revit 2011 API Series: RevitLookup: The New Name for RvtMgdDbg
(part of our ongoing series)
Since the beginning of Revit development time – in the 8.0/8.1 range, the best way to learn about what is possible with the Revit API was to use a “Snoop Tool” – something that could interrogate all of the elements in the model and all of their properties.
In the beginning, there was RevitDbg – a tool by Fenton Webb at Autodesk. It used reflection to browse through a massive tree structure of all the elements in the model. It was slow, but cool.
Later, Jim Awe of Autodesk brought his Snoop tool (called “RvtMgdDbg”) from AutoCAD to Revit – bringing not just browsing of elements but also event testing as well as some test commands. This became the tool that most Revit developers cut their teeth on. That said – I’m still amazed at the number of developers who have tried to learn the API without the benefit of RvtMgdDbg… I have to imagine it’s like developing in the dark!
For all of its importance to Revit developers, RvtMgdDbg was always somewhat of a step-child at Autodesk… No one really owned it (so it was nice that they provided the source – at least 3 times over the past few years I had to upgrade it myself to support the latest version before someone at Autodesk took care of it). It was also unclear over time how it was going to be distributed – was it only for ADN members? Did you have to attend a particular AU session? Or did you just have to know the right people? Thankfully, in the past year or so Autodesk has caught on to how important RvtMgdDbg is to getting developers up-to-speed and has made it available to anyone, usually via Jeremy Tammik’s blog.
Which brings us to 2011… While not revolutionary – it is an important evolution for RvtMgdDbg. It has been adopted by the Revit API team – which means that there are resources devoted to updating it and providing it along with the SDK – under a new, more accessible name: RevitLookup. Kevin Vandecar as well as some of the Shanghai developers have done yeoman’s work in upgrading it (it is a grueling task – I know because I had to do it myself at least twice during the 2011 alpha/beta cycle).
RevitLookup can be found in the SDK folder under RevitLookup – it appears that you’ll have to build it yourself (binaries were not shipped) – but it’s great to see that this tool getting its proper due from Autodesk.
Posted by
Matt Mason
at
11:47 AM
1 comments
Labels: Revit
Thursday, April 08, 2010
Revit 2011 API: SDK Posted (a while ago)
We’re all still waiting anxiously for the official Revit 2011 product to become available… They set the expectation for today – but it’s not there yet! and it’s 7:58 AM! What’s the deal? :)
That said – I noticed last night that the final Revit 2011 SDK is available as a standalone download on the ADN page (posted back on 4/1 – and I didn’t notice).
In other news, I hope to get back onto posting the rest of my 2011 articles – I’m just temporarily buried in project work.
[Editor: And I can see that I have to go back and add to a few previously written articles. I can see at least 15 enhancements in the new SDK that were added late enough in the process that I was unaware of them! Woo-hoo, more toys!]
Posted by
Matt Mason
at
7:52 AM
0
comments
Labels: Revit
Sunday, March 28, 2010
Revit API 2011: The New Way to Find Elements
(Part of our Revit API 2011 Series)
[Editor’s Note: Updated with some late-breaking additions that will only be documented in the released documentation]
For the uninitiated, much of the core work in a Revit application involves finding elements within the Revit database. Whether it’s finding exterior walls, 3D Views, or wall types – it’s always the same concept… Doing a lookup from the Revit to get a list of elements.
This is an area that “the factory” has improved upon release-after-release… From the early days, where you always had to cycle through everything – through the newest incarnation, today. I think I’m counting right that this is the 4th generation of the element iteration API. And no more ignoring what’s new – because you’re required to use the new method in 2011!
The 2011 Approach
The factory has really created something great here – something that is mature and answers almost anything you could want in an element iteration API. And they’ve really tried to do it in a way that matched the best and most modern approaches in .NET – such as LINQ.
The fundamental concept for iteration is the FilteredElementCollector class.
Getting Started
You construct the class in one of three ways:
// get ready to filter across an entire document FilteredElementCollector coll = new FilteredElementCollector( myDoc ); |
or
// get ready to filter across just my pre-selected set of // elements! FilteredElementCollector coll = new FilteredElementCollector( myDoc, myElementCollection ); |
This is great when you’d rather not search your entire model when you’ve already got the subset you want…
or
// get ready to filter across just the elements visible in a view FilteredElementCollector coll = new FilteredElementCollector( myDoc, viewId ); |
This is equivalent to the old mechanism of the View.Elements collection – which is now gone.
These constructors just get you started… Then it’s time to move on to the filtering.
Filtering Mechanisms with FilteredElementCollection
The factory has introduced three different categories of filtering in 2011:
- Logical (operations like AND/OR)
- Quick (operations that are FAST)
- Slow (operations that take a bit longer)
While these kinds of things have probably conceptually always existed, but they were found out by experimentation rather than Autodesk documenting and sharing them up front…
- Quick
- ElementCategoryFilter / OfCategoryId()
- ElementTypeFilter / OfType()
- ElementIsElementTypeFilter /
WhereElementIsElementType()
WhereElementIsNotElementType() - ElementOwnerViewFilter / OwnedByView(), WhereElementIsViewIndependent()
- ElementDesignOptionFilter / ContainedInDesignOption()
- ElementIsCurveDriven / WhereElementIsCurveDriven()
- ElementStructuralTypeFilter
- BoundingBoxContainsPointFilter
- BoundingBoxIntersectsFilter
- BoundingBoxIsInsideFilter
- ExclusionFilter
- FamilySymbolFilter
- Slow
- ElementParameterFilter
- ElementLevelFilter
- FamilyInstanceFilter
- FamilyStructuralMaterialTypeFilter
- PrimaryDesignOptionMemberFilter
- StructuralInstanceUsageFilter
- StructuralMaterialTypeFilter
- StructuralWallUsageFilter
- CurveElementFilter
- RoomFilter
- SpaceFilter
- AreaFilter
- RoomTagFilter
- SpaceTagFilter
- AreaTagFilter
These are documented further in the API help file in its own introductory section called “Element Iteration API”.
I’ll give some of the typical situations here:
If you know the type:
// we want walls coll.OfClass( typeof(Wall) ); |
or if you know the category:
// we want Curtain Wall Panels: coll.OfCategoryId( BuiltInCategory.OST_CurtainWallPanels ); |
Now here’s where it starts to get interesting… If you want to put different filters together, it can look something like this:
// We want door instances coll.OfCategoryId( BuiltInCategory.OST_Doors ).OfClass( typeof(FamilyInstance)); |
What’s going on here? each filter ADDs requirements to the collector. And to make the whole thing more friendly towards combining, the methods return a pointer to their object, so that you can “chain” them together. For example, the code above would be equivalent to:
// we want door instances coll.OfCategoryId( BuiltInCategory.OST_Doors); coll.OfClass( typeof(FamilyInstance) ); |
We are updating our collector two times with the filter requirements.
The ElementType Topic
The ElementType / NotElementType can be a little confusing at first… There are two filters, the short-hand versions are:
- WhereElementIsElementType()
- WhereElementIsNotElementType()
What is ElementType? This is the renamed Symbol class in the API (re-named to match better what interactive users call things). So an “ElementType” refers to a symbol/type/definition kind of thing (a “block definition” for you AutoCAD-types). Something which is “Not an ElementType”, on the other hand – is typically something which is physically IN the model – like a specific door, line, or wall. Technically it’s a bit more broad – because it also includes items like views, etc.
That said – these two can be key filters to use to distinguish between whether you want Doors vs. Door Types, for example.
What’s the Deal with Rooms/Areas/Spaces/Tags?
Here’s a place where Autodesk’s new strategy of matching up more closely with the internal API will cause you a little bit of hassle. With Rooms/Areas/Spaces and their tags (as well as about 9 other types – see the API Introduction for the list) – there is no internal Revit type which matches them.
For example, if you look at the Room class in the 2011 API, you’ll see that it is actually a descendant of the Enclosure Class. Enclosure covers Rooms, Spaces, and Areas… Here’s the trick – Revit’s internals are obviously modeled on the “Enclosure” class – so if you’re querying by type – you can’t query on
typeof( Room ), for example.
There are some specially designed filters to compensate for this – like RoomFilter, AreaFilter, SpaceFilter, etc… These would be called as follows:
coll.WherePasses( new RoomFilter() ); |
The WherePasses method is another mechanism for specifying filters – you can use any filter with it.
Final Requirements of the Filter
Ok, ok – we’re almost to the payoff… But one thing I should note before we go on… If you’re used to being able to just query the whole model (for whatever reason) – you’ll find that a little bit tricky with this mechanism… Why? Because the rule is that after you construct the collector – you MUST apply at least one filter before you attempt to retrieve from it. You can’t (easily) just retrieve everything.
The closest I’ve come to it is:
// get EVERYTHING – like in the bad-old-days… // get all the ElementTypes + all the non-ElementTypes coll.WhereElementIsElementType().UnionWith( new ElementIsElementTypeFilter( false ) ); |
Finally – Retrieving from the Filter
Sorry to make you go through all this to get to the good part! Once you have constructed your collector and applied filter(s), then it’s time to request the contents of the collector and see what you get. Autodesk has really done a nice job of implementing some .NET 3.5 goodies here, so there are a variety of options.
coll.ToElements(); | Return an IList<Element> of the contents. |
coll.ToElementIds(); | Return an ICollection<ElementId> of the contents. |
coll.FirstElement() | Return the first Element found that matches. |
But that’s only the first part – the other thing I love is that the .NET 3.5 tricks that get around another annoyance – that these query routines return pointers to “Element” – which you immediately have to convert/cast down into, say “Room” to be able to easily access the properties and methods of that class.
// get all the wall types as wall type objects: coll.OfClass (typeof(WallType)); IEnumerable<WallType> types = coll.Cast<WallType>(); foreach (WallType wt in types ) { // do something with the wall type } |
Using with LINQ
Because the FilteredElementCollector supports the IEnumerable interface – it easily can make the jump to LINQ – being able to write full-fledged queries directly in code.
This looks something like:
FilteredElementCollector coll = new FilteredElementCollector(doc); var bigEnoughWallTypes = IEnumerable<WallType> types = bigEnoughWallTypes.Cast<WallType>(); |
ok, so the thin screen doesn’t lend itself to this… In any case – it’s not magic, it’s nothing you couldn’t have done before – but it DOES make your code a bit tighter and arguably easier to maintain because it’s clear what you’re doing (as opposed to doing the same thing in a query then loops with if statements).
The Final Analysis
In the final analysis – the new FilteredElementCollector is a fantastic new way of accessing data within Revit. It does take a little bit of adjustment, but once you’re there, I’d say it’s nicer than what existed before – and it has nice room to grow.
I still need to run the new things through a performance test (my impression is that they run faster than their 2010 equivalents – but I haven’t put a stopwatch to it yet). This post is already too long – so I’ll save that for another post…
Posted by
Matt Mason
at
11:48 AM
2
comments
Labels: Revit
Thursday, March 25, 2010
Revit 2011 API: Exceptional Stuff…
(Part of our Revit API 2011 Series)
Forgive the bad pun of a title…
One of the new capabilities in the Revit 2011 API that I haven’t covered yet is some re-working of the way that Revit throws exceptions when you do something it doesn’t like… Whereas in the past, you would have gotten something pretty generic (in terms of the type of exception thrown), in 2011 Autodesk has introduced a variety of very specific Revit exceptions which are thrown. All of these inherit from Autodesk.Revit.Exceptions.ApplicationException:
- ApplicationException
- ArgumentException
- ArgumentNullException
- ArgumentOutOfRangeException
- ArgumentsInconsistentException
- FileArgumentNotFoundException
- InvalidPathArgumentException
- InternalException
- InvalidOperationException
- AutoJoinFailedException
- FamilyContextException
- ForbiddenForDynamicUpdateException
- InapplicableDataException
- IncorrectProductException
- InvalidLicenseException
- InvalidObjectException
- ModificationForbiddenException
- ModificationOutsideTransactionException
- ObjectAccessException
- RegenerationFailedException
- IOException
- DirectoryNotFoundException
- FileAccessException
- FileNotFoundException
- InvalidDataStreamException
- ArgumentException
So what, you say? An exception is an exception, you say? I disagree – historically it has been painful to try to figure out why something didn’t work in Revit – the exceptions and error messages were not always helpful. And if you wanted to trap specific exceptions, it was pretty weak.
I see this as a great investment on Autodesk’s part in making the Revit API “grow up” to a level of maturity that you can develop strong applications with it. Applications that are easier to control and to diagnose when something goes wrong.
And speaking of diagnosis, there’s one other hidden gem in all these exceptions: the FunctionId. A property on these exceptions which gives you:
- The Revit source code file
- The Revit source code function
- The Revit source code line number
where this particular exception occurred. This strikes me as a great help when I’m sending something in to Autodesk Developer Network… Telling them EXACTLY where in their code something is going bad (and to help me figure out why).
All in all, I appreciate that they took some time to implement this in 2011.
Obscure Developer TechNote:
One thing that I had not been expecting… If you use the “Debug + Exceptions + Thrown Exceptions” in Visual Studio… When a Revit Exception is first thrown, it shows up as an “SEHException” which I believe means an unmanaged C++ exception that is bubbling up. That said, when it actually arrives – it is one of the new types shown above. So you actually have to let it bubble all the way up before you get the benefit of the knowledge of what it is.
Posted by
Matt Mason
at
8:58 AM
0
comments
Labels: Revit
Revit API 2011: Ooh Ooh! Pick Me!
(Part of our Revit API 2011 Series)
The Revit 2011 API adds some new ways to interact with elements in the project – through picking. These are all available through the UIDocument.Selection class:
- PickObject (replaces PickOne – pick something in the active view – get back a reference)
- PickObjects – pick multiple objects, click “Finish” when done.
- PickElementsByRectangle – a replacement for “WindowSelect”
- PickPoint – return an XYZ coordinate based on picking on the active workplane
What’s Even Better?
All of the above except for PickPoint support a number of options that go deeper than what we had in Revit 2010 and prior (where you could only support picking full elements):
- Element (as before a whole element)
- Face (a specific face of an element)
- Edge (any model edge)
- PointOnElement (any point on any face or curve)
Further, the methods mentioned above also support a new concept as well – a Selection Filter interface: ISelectionFilter. You can implement ISelectionFilter on any class – it will get callbacks from the pick method to help you control what is allowed to be selected or not:
- a Pre-filter method at the element-level
- a Post-filter method at the reference-level
This lets you easily limit your selections to, for example, “walls” or “exterior walls” or “an inside horizontal top edge of an exterior wall” – the mind boggles.
But Wait, There’s More!
While PickPoint() does not support the options described above – it DOES support a different set of options – Object Snaps!
- Points - Snaps to site points.
- Quadrants - Snaps to quadrant points. For arcs, jump snaps are enabled.
- Tangents - Snaps tangent to an arc.
- Perpendicular - Snaps to perpendicular elements or components.
- Centers - Snaps to the center of an arc.
- Intersections - Snaps to intersections.
- WorkPlaneGrid - Snaps to a work plane grid.
- Nearest - Snaps to the nearest element or component.
- Midpoints - Snaps to the midpoint of an element or component.
- Endpoints - Snaps to the endpoint of an element or component.
Conclusion
The Pick mechanism in Revit has gone from paltry to an embarrassment of riches… I’m not aware of a better Pick API in any CAD system. While there are still a few usability oddities, it’s a vast improvement over 2010.
Posted by
Matt Mason
at
8:09 AM
4
comments
Labels: Revit
Revit API 2011: User Interface Changes/Improvements
(Part of our Revit API 2011 Series)
The 2011 API has a variety of interesting enhancements in the ribbon user interface – making it possible to build applications which more closely match the look, feel and capability of native Revit commands (aside from being relegated to the Add-Ins tab).
In 2010, the first Ribbon release, the API already had access to controls such as:
- RibbonPanel
- Pushbutton
- Stacked Pushbutton
- Pulldown Button
What is new in 2011 are a wide variety of new controls and constructs in the ribbon:
- Combo Box
- SplitButton (like a Pulldown button, but it has a default action)
- TextBox
- SlideOut
I created the following sample ExternalApplication which illustrates the different controls now possible:
If the user has added a SlideOut to the RibbonPanel, any additional controls will be only available on the SlideOut panel – available when you click the down-arrow to the right of the Ribbon Panel name.
Figure 2
Note that the slide out is “pinnable” to keep it open. That, combined with the ability to “tear off” the panel (also available in 2010) – makes for some interesting capabilities.
Going Deeper
Beyond the new controls, there are some new capabilities a level deeper:
- Images on Pulldown buttons
- Tooltips and Long Descriptions – to provide more detail on how to run your command.
- Tooltip Images – to provide a graphic for your command – a picture is worth a thousand words
General Availability
Another new feature in 2011 is the ability to have an interface (IExternalCommandAvailability) which implements a check for whether your command should be enabled or disabled.
This is useful if your command should only be available in a 3D View, or only if the user has filled out the setup/preferences dialog, or only if they user has pre-selected a certain category of elements. The command will be automatically enabled/disabled as appropriate.
The TaskDialog
One of the new core capabilities of Windows (starting in Vista) is an upgrade for the venerable MessageBox – called the TaskDialog. Revit now provides the TaskDialog on a platform-independent basis. The TaskDialog has all of the capabilities of the old MessageBox, but also has new and interesting capabilities like:
- Expanded Content (visible when the user expands it)
- As many or few buttons as you’d like (Yes/No/Close/Retry/About/etc).
- Up to 4 Command Link buttons with supporting text.
- Checkbox with verification text
- Footer text
Here’s an example showing a bit of everything:
The code required to do a TaskDialog is pretty straightforward:
TaskDialog td = new TaskDialog("Hello World"); // or, alternatively – you can use a static method, if you only need the basics: |
Conclusion
Revit 2011 provides a good number of new controls and capabilities – it’s nice to be able to make applications that have the feel of native Revit commands.
Posted by
Matt Mason
at
8:09 AM
0
comments
Labels: Revit
The Revit API – 2011 Edition – What’s New?
For the past few years, I’ve done a series of posts describing what’s new and possible in the latest version of Revit and it’s Application Programming Interface (API). For the uninitiated, the API is the series of mechanisms that Autodesk provides to be able to drive or analyze Revit through programming.
2011 represents a watershed year in the ongoing development of the Revit API. Autodesk has taken the opportunity to re-work the API to better match how Revit works internally – and at the same time to do some amazing new things.
Over the following series of posts, I hope to cover topics such as:
- Upgrading Existing Revit API commands/applications
- New Deployment Methods
- The New UI vs. Database split.
- New Ribbon Capabilities
- Element Iteration Changes
- Ooh-ooh Pick Me! New Selection Methods
- Dynamic Model Update
- Event Model Changes
- RevitLookup: The New RevitMgdDbg
- Revit AddIn Manager: Almost Edit & Continue
- What’s New in Element Creation?
- Exceptional Stuff
- What Kinds of Applications are Possible Now?
- And More…
Posted by
Matt Mason
at
7:45 AM
2
comments
Labels: Revit
Sunday, October 11, 2009
What Type of Element is this? It depends...
(Sorry for the long interruption in blogging - project work was just too heavy to devote time to blogging).
I ran into something interesting yesterday that I had not seen before, and I figured it was worthy of a quick blog post. When doing Revit-oriented development, there are a lot of times when you check the type of an element, and have logic in place to handle that element based on the type.
I was running an application that I had tested before in the past - but it was no longer working - why? And then I stumbled upon an interesting quirk about Revit Architecture versus Revit MEP - something that I had never encountered before:
For certain types such as Pipe, when you ask Revit what type it is - the answer depends on which flavor of Revit you are using. In the sample above, I was interrogating a pipe element. In Revit MEP, it tells you it is a Pipe. BUT - with the same model in Revit Architecture - it tells you that it is an "Element" (Revit's code word for generic elements that don't have any special definition).
The element's category is consistently reported as "Pipes" - but this is just the first time I've ever noticed the type of object being different based on which flavor of Revit you're in. It makes sense that Revit behaves this way - if it did not, you would be exposing a variety of properties and methods for this type of object which should only be available in MEP.
In any case - just be aware - the code that you have that works perfectly one way in MEP could work completely differently in Revit Architecture (and I'm sure this is not the only scenario).
Posted by
Matt Mason
at
4:56 PM
0
comments
Labels: Revit
Monday, July 20, 2009
Avatech Utilities for Revit
We finally got our Avatech Utilities for Revit launched a month or so ago. We've added to the list of utilities as well:
- Room Renumber
- Change Case
- Space Update (New)
- Grid Select (New)
- Door Mark Update
- RevitCity Content Browser
- Earth Connector
- Room Phase Copy (New)
Unfortunately - we came to a hard decision... because of the amount of effort it takes to produce, support and update these utilities on an ongoing basis - we have to start charging money for them.
Because we didn't really give any warning on this - we wanted to make this as fair as possible for the 2010 release.
As such, we did the following:
- Avatech Utilities for Revit LITE - this will continue to be free (it's made up of the top four utilities above).
- Avatech Utilities for Revit - will be offered for $395 USD / seat
To take care of all of the people who had previously downloaded the software- we've put in a one-time program to give previous downloaders 5 standalone seats of the software (this was sent via e-mail to the address which was registered during the download). You should have received the second and final notice of this program today (so if you're thinking "where was that?" you might want to check your junk mail folder or something like that).
Finally, there will be other special offers for customers who purchase their Revit software through Avatech (which I realize is only a fraction of the total audience - sorry!).
While this has been a bit tough for us to work through - I'm looking forward to what this means - we should be able to do a better job growing and releasing more utilities in the future.
-Matt
Posted by
Matt Mason
at
9:03 AM
4
comments
Labels: Revit
Friday, May 08, 2009
Autodesk University 2009 Voting
Hi there, readers...
Today is the last day of public voting for the Autodesk University 2009 conference...
I've submitted three classes and I'd REALLY appreciate your vote:
- Deep Dive on the Revit API: Advanced Topics
- The Power of Creation in the Revit API
- Check It! Building Check Plugins for BIMreview
You can vote at:
Thanks!
Posted by
Matt Mason
at
8:29 AM
2
comments
Labels: AutodeskUniversity, Revit
Saturday, March 14, 2009
What’s New in the Revit 2010 API: Geometry
(Part of the What’s New in the Revit 2010 API series)
The Geometry area of the Revit API has a few interesting and helpful enhancements in the 2010 version.
Probably the most obvious of the enhancements were made to support Revit’s new conceptual massing capabilities.
HermiteSpline
While there was previously a HermiteFace class to represent the surface – we now have a HermiteSpline element for the splines that can be created (which will probably result in many more HermiteFaces as well – since it only takes one button to go from spline to face).
The HermiteSpline exposes its control points and tangent vectors (nice touch). WARNING: For those of you who have been using Tessellation – like we have on our Earth Connector application – be prepared for an explosion of points as Revit Users start using splines. The 5-point spline shown above tessellated into 287 points… (I probably have to start investing some mental energy in a “reduce” function – because that’s pretty heavy!).
Point
As I joked about in one of the previous posts – Autodesk has finally broken down and added the Point concept to Revit (yes, yes – the XYZ class was there before – but Points are now first class geometric objects).
The reference points in the picture above are part of the spline, but it is possible to create standalone ReferencePoint elements – and the geometry extracted for the reference point is a Geometry point.
I have not yet figured out why it’s important to have a point in the geometry class (since you can get the location directly from the element) – but I’m sure that there is a good reason (consistency, if nothing else, I suppose).
Making Life a Little Easier for You
Historically if you dealt with geometry in the Revit API, you had to brush up on your linear algebra in order to deal with Transformation matrices… For example, a chair might be modeled within a family centered on the 0,0,0 point – but then it gets placed 100 times into a project way out in space. Every instance has a transformation matrix that gets you from the “internal” geometry locations – also known as the “SymbolGeometry” – out to the actual geometry location in the project.
It was even worse when items are nested a few levels deep… I know that, for example, stairs have railings and railings have balusters – and balusters gave me fits for quite some time, being a good number of levels deep.
Autodesk started making this better a couple of releases ago – making it easier to get the transformed version of things – and they’ve taken it another step now.
- Instance.GetInstanceGeometry()
- Instance.GetSymbolGeometry()
(Instance is the Geometry class which represents things like FamilyInstances, and other elements where you need to dig into the definition of things). Both of these methods can optionally take a transform matrix to transform – or just give you the easy answer.
The Hit Reference
I mentioned in “Very Spatial APIs” that the Reference class has been upgraded, mainly to provide the additional information retrieved when shooting rays through elements. The new properties:
- ProximityParameter (how close the hit is to the origin)
- Element (the element that was hit)
- ElementReferenceType:
- MESH
- CUT_EDGE
- INSTANCE
- FOREIGN (from the docs: “The reference is to geometry or elements in linked Revit file.”)
- SURFACE
- LINEAR (curve or edge)
- GeometryObject (the geometry intersected)
- Transform (of an instance, if that’s what was hit)
- UVPoint (U,V parameters of the face, if that’s what was hit)
Summary
This is yet another area with modest but solid improvement in the API in 2010.
Posted by
Matt Mason
at
1:58 PM
0
comments
Labels: Revit
What’s New in the Revit 2010 API: Events
(Part of the What’s New in the Revit 2010 API series)
The Event section of the API is one area that I believe developers have been hoping for years to see more… In 2010, Autodesk re-writes a bunch of what is there, adds a few more interesting events – but probably leaves out what you were hoping for…
Before and After
The biggest change, both for the re-written events and the new events is that they can receive callbacks either “before” the action or “after” – which is a very nice, mature feature for events. The “before” events enable you to either (1) fix the model before it is saved/printed/etc OR (2) stop the process and ask the user to do something before the action can be performed.
NOTE: for those of you who are thinking immediately about having “alternative interfaces” for something like Document.SaveAs – I think you’ll be disappointed. So far as I can see all of the “before” events are still fired after the user has completed the dialog (i.e. chosen the new SaveAs target file) – but before it actually happens.
User-Driven and API-Driven
I’m not sure that this was the case in the past – but there are notes with the 2010 release that indicate that the events will fire not just when triggered by interactive usage – but also when triggered by the API. I’m not 100% sure if I love that (once we developers all start using them at the same time) – but we’ll see.
Re-written Events
The following events have been re-implemented:
- Document Creation
- Document Opening
- Document Saving
- Document Save As
- Document Closing
- DialogBox showing (Revit 2010 generally uses the newer style “TaskDialog” from WPF, rather than the old-school “MessageBox” of the last 15 years)
The New Events
The new events are:
- File Export
- File Import
- View Printing
- Document Printing
- View Activating
- Document Save to Central
The last one, saving a document to the central file – has some interesting options – including being able to see the exact properties that have been used for the operation, including:
- Compact Central File
- Relinquish Borrowed Elements
- Relinquish Family Worksets
- Relinquish Project Standard Worksets
- Relinquish User Created Worksets
- Save Local File
That said, alas, they are read-only.
In Summary
I know you were hoping for an element-level event. Autodesk knows that you’d like to have it – but there are apparently some complexities and pitfalls to giving us this power (not the least of which is that we could probably cause never-ending cascading update loops).
All in all, though – the events took a good step forward in terms of the maturity of the API. They’re better thought out than before, and they’ll get more usage.
Posted by
Matt Mason
at
1:04 PM
0
comments
Labels: Revit
Monday, March 02, 2009
What’s New in the Revit 2010 API: Import/Export
(Part of the What’s New in the Revit 2010 API series)
Revit 2010 introduces a number of nice enhancements to Importing and Exporting in general – and best of all (for developers, at least) – all of the new capabilities are also available through the API.
The ADSK File Format
One of the new exciting capabilities in 2010 product line revolves around a new file format called an ADSK file (Autodesk Exchange File). This is essentially a zip file, but it contains all the geometry and data that are needed to support DIFFERENT intra-Autodesk software workflows (including, for example – Revit to Civil3D and Inventor to Revit).
Export BuildingSite
The BuildingSite export gathers a wide variety of information useful primarily to Civil3D users, and puts it together in a package that’s easy to transfer.
The content includes:
- dwg files for the footprint, building shell, site plan and property lines.
- Data such as:
- Gross Building Area (based on a selected AreaPlan)
- Building Model data (doors, floors, roofs, etc)
- Project Information, including:
- Location information
- Building Type
- Total Occupancy
- Area per person
- Preview Images
All in all, the amount of XML data is significant in there – so I think we’re just hitting the highlights of what is potentially transferred here…
The API export gives a few options, and I think between what it picks up automatically from the model and what you can specify, you have access to pretty much everything.
Import from Inventor
Import from Inventor is another incredibly important workflow in the greater scheme of things – particularly for the MEP side of things. The ability for manufacturers to model their content in Inventor (with as much detail as they want) – but then to easily produce lower-detail models for use in Revit (including MEP connectors) – that’s powerful.
I haven’t gotten Inventor 2010 installed yet – so I haven’t tried out the export side. The import side seems to be pretty minimal (both in the UI and in code). But the capability is there.
(NOTE: I can’t recall if these are DWG or ACIS solids – but I’m pretty sure it’s not a “new” method of exchange – it’s a better-controlled, better-wrapped version, which includes additional properties and the MEP connectors – but the geometry is probably on the “heavy” side compared to native Revit).
Export to DGN
New with Revit 2010: export to Microstation DGN format. The export options include:
- Export Solids (ACIS or Polymesh)
- Layer Mapping (a layer setting or file)
- DGN Template File
Extract PartAtom
This is equivalent to the new “Publish –> Share with Autodesk Seek” capability. The capability in the UI packages up a piece of content, along with XML to fully describe the types, the parameters, etc – all a part of the PartAtom specification used by Autodesk Seek.
The API version of this only produces the XML file – you’ll have to do the rest yourself. NOTE: This method, ExtractPartAtomFromFamilyFile is on the Application class (not the Document or Family class).
Export GBXML
The GBXML export is much improved in the 2010 User Interface (shown below).
The most important new capability to note here is the “Export Complexity” option. This option will control how much detail is exported to the GBXML model from your Revit model – ranging from only the basics, to how “shading surfaces” are handled, to whether curtain wall mullions are counted as shading surfaces.
The capability for the API to export GBXML was introduced in the prior version – but this has been updated to include the all-important complexity option.
NOTE: This is technically not a change to the “Export” method for GBXML, but a change to the GBXMLparamElement which defines the export options.
Import GBXML
This is a fascinating new addition to the Revit MEP package – the ability to read GBXML back into Revit. While I’m sure that there is probably more workflows that I haven’t quite grasped yet, just being able to use Revit as a GBXML viewer (or see what went out the door as GBXML) seems very useful.
The API exists for import, however, there are currently no options.
New DWF Export Options
The API has been restructured a little around DWF export – shaping up for more robust options in the future (for example, there’s now separate options classes for DWF2D, DWFX2D, DWF3D and DWFX3D) – although they’re mostly the same between DWF and DWFX at present.
In the 2D DWF/DWFx export, they’ve added support for controlling:
- Image Format (compression level)
- ImageQuality
- PaperFormat (size)
- Paper Orientation (portrait or layout)
These additions will help fine tune the DWFs you can create.
Most of the Export Options (DWF and FBX) also now include a “StopOnError” option, so that it won’t keep going if it runs into a problem… sounds like a good idea! :)
Summary
Many of the enhancements to import/export are driven by the core 2010 product enhancements. But it’s so nice to see that they’re investing in keeping the API up with what’s new, rather than lagging a year or more behind.
Posted by
Matt Mason
at
7:06 PM
4
comments
Labels: Revit
Saturday, February 21, 2009
What’s New in the Revit 2010 API: Very Spatial APIs
One of the most exciting areas of potential API development is checking the building… Whether trying to determine if the egresses are short enough, or whether there is a nurses station close enough to each room, or just understanding how buildings, floors and rooms are modeled – there are a lot of things to check for. Historically, these things have been hard to check for – it was far easier to just look at a drawing than to try and figure it out.
But all that is beginning to change with some neat new APIs in 2010, which give you some tools to help understand the building and spatial relationships between objects.
Shooting Rays
One of the classic CAD solutions to these kinds of problems is “shooting rays” through your model… That is, set a point and a vector, then see what that “ray” hits. This was kind of possible with some creative math prior to 2010 – but it’s both better and easier now in 2010.
The new mechanism:
ReferenceArray =
Document.FindReferencesByDirection( origin, direction, View3D)
The new method returns back an array of references – and the reference class has been upgraded to include:
- Element
- Type of Reference (Surface hit, Element hit, Edge, Foreign, Mesh)
- GeometryObject of the hit
- XYZ location of the hit
- Distance of the hit from the origin (“Proximity Parameter”), UV location of the hit on a surface (if appropriate)
Important Note: The View3d that you specify controls a few things – first, if you’ve got elements or categories hidden, those do not seem to be “hit”… Also, remember that if you’ve got model phases, the ray will follow the phase of the view.
Still, it’s a great new feature for those who are trying to use the API for any kind of building analysis.
Where am I?
The other enhancements in the category of spatial awareness relate to being inside a particular architectural room or MEP space. If you want to test if a given point is in a known room or space, you now have:
- Room.IsPointInRoom( xyz )
- Space.IsPointInSpace( xyz )
Conversely – if you don’t know where a particular XYZ point is at all, you can ask:
- Document.GetRoomAtPoint (xyz)
- Document.GetSpaceAtPoint (xyz)
I think these enhancements are also critical… while FamilyInstances have long known which room they were in – these API enhancements give a great variety of additional power for analyzing buildings.
Posted by
Matt Mason
at
8:27 PM
0
comments
Labels: Revit