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);
coll.OfClass(typeof(WallType));

var bigEnoughWallTypes =
from element in coll
where element.get_Parameter(BuiltInParameter.WALL_ATTR_WIDTH_PARAM).AsDouble() > 0.5 &&
   element.get_Parameter(BuiltInParameter.FUNCTION_PARAM).AsInteger() == 1
                         select element;

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…

Friday, March 26, 2010

Revit API 2011: Upgrading Existing Add-Ins

(Part of our Revit API 2011 Series)
If there is a dark side to all of the positive changes in the 2011 API – it is that the amount of re-work required for existing add-ins is FAR more than previous upgrades. I’m tired just writing this post…

While previous upgrades have been fairly painless, in 2011 you’re up against:

  • Massive namespace renaming/restructuring.
  • Deprecation and replacement of many of the fundamental element search and iteration APIs.
  • Fundamentally new transaction and regeneration mechanisms
  • Non-trivial changes to the fundamental XYZ, UV and ElementId class
  • Changes to the Element.ObjectType structure.
  • Replacement of the Analytical Model classes
  • New Event Model
  • New Selection Mechanisms
  • Ribbon API changes
  • Print API changes
  • Re-work of the gbXML class
  • Installer changes (if you want to take advantage of new capabilities)

Massive Namespace Restructuring

The factory has taken this opportunity to completely re-work the namespace hierarchy into something which more closely matches Revit’s internals – as well as to clean house, straighten up, and simplify some things.

While I would argues that this is probably a good thing in the long term, it will require a bit of work to recompile your code.

While I won’t cover the namespaces in detail here, to give you an idea of what you’re looking at:

  • Autodesk
    • Autodesk.Revit
          • Autodesk.Revit.UI (where all the User Interface and command/application integration classes landed)
          • Autodesk.Revit.DB   (this is the container for most core elements, geometry, parameters, and other concepts)
              • Autodesk.Revit.DB.Architecture ( contains architecture-specific elements like Rooms, RoomTags, Gutter, Fascia, etc)
              • Autodesk.Revit.DB.Electrical (contains electrical-related elements and concepts, from CableTray to DemandFactor)
              • Autodesk.Revit.DB.Events (contains the event arguments for all the different kinds of events)
              • Autodesk.Revit.DB.Mechanical (Spaces, Zones, SpaceTags, Ductwork, etc)
              • Autodesk.Revit.DB.Plumbing ( Piping, PipingSystems, etc)
              • Autodesk.Revit.DB.Structure ( Analytical Model, Loads, Rebar, Trusses, etc)

Other key re-naming issues:

  • the Symbol class has been re-named to “ElementType”
  • the old Geometry.Element class has been renamed to GeometryElement
  • the old Geometry.Instance class has been renamed to GeometryInstance
  • These are further described in the “What’s New” section of the API Help File

Autodesk is also providing in the SDK a spreadsheet of all of the class renames, and their corresponding new names. It is a long list :).

Where Did My ElementIterator Go?

Autodesk has taken somewhat of an unusual step in 2011 – that of ripping and replacing all of the three different element search and iteration schemes from before 2011 and replacing them with the new FilteredElementCollector. The Document.Elements collection, the Document.get_Elements( type ) and the filter mechanism have all been removed.

See our separate post on the new mechanism (which is quite superior) – but it may take a minute or two to re-work any of your code which iterates through elements in the document (which almost every command does at least once).

Also note – the View.Elements collection has also been re-worked to the new scheme.

The New Transaction Mechanisms

There are fundamentally new transaction mechanisms that you will likely need to deal with (unless your application was very straightforward). Commands are now attributed with one of two Transaction modes:

  • Automatic – like what has existed historically.
  • Manual – the developer must control their own transactions explicitly.

For upgrading an existing application, you’ll probably want to stay with Automatic because it most closely matches the prior release behavior. However, if you had been using transactions within your code in the past (i.e. Document.BeginTransaction) you must replace these with the new “SubTransaction” classes.

//New SubTransaction approach

SubTransaction subTr = new SubTransaction( myDoc );
try
{
    subTr.Start();
   // do something
    subTr.Commit()
}
catch (Exception ex)
{
    TaskDialog.Show(“Error”, “An unexpected error was encountered: “ + ex.GetType().Name + “: “ + ex.Message);
    if (subTr.HasStarted()) subTr.Rollback();
}

Developer TechTip:
If you go the manual transaction approach, don’t forget to name your transaction. This name shows up in the “Undo” box, but because there is a constructor which does not require a name, it’s easy to forget. And Revit throws a nasty exception at you if you forget to name it.

The New Regeneration Mechanism

All commands in Revit are now attributed with another attribute: RegenerationMode:

  • Automatic – same way Revit has worked traditionally – after every action in Revit, the model is regenerated (unless you’re using SuspendUpdate). Solid, but slow on occasion. Also – Autodesk has indicated that this mode is going away in the future.
  • Manual – you are in complete control of your own regeneration (powerful and fast but occasionally painful).

With manual regeneration, you issue a Document.Regenerate any time that you want the project to regenerate. Seems easy enough, right? Well… First you have to understand when you NEED to regenerate. There are a variety of cases, particularly when you are creating or modifying geometry, that the changes will not be propagated until you do the regenerate. For example, if you create a line, you are unable to query for the reference to that line until the document has been regenerated.

Why it can be challenging: If you’ve got library code that you re-use in multiple commands. Are you currently in Manual Regeneration mode or not? it depends on how you entered the current command. If you call Document.Regenerate and you’re already in Automatic mode, Revit will throw an exception (seems like a harmless problem – factory guys, chill out!). To further complicate things, if your code is being called as part of an event callback, I believe that it is ALWAYS going to be in Automatic Transaction mode (even if the whole thing is in the context of a manual transaction command). So there’s some potential trickiness to deal with.

XYZ, UV and ElementId - All Change to be Unchangeable!

OK – this is just cruel… I’d swear that this is the third change to the XYZ class in three releases! And it’s worse than previous issues. In 2011, you can no longer do the following code:

myPoint.X = 10;

What?? why not? Well, Autodesk has made the XYZ, UV, and ElementId classes immutable – they cannot be changed once they are created. There’s a reasonable reason behind this from a framework design perspective – because it implies that you could do something that you really couldn’t. For example, if you did:

myWall.Location.Point.X = myWall.Location.Point.X + 1;

What would this do? You would think that it might move the wall 1 foot in the X direction. In fact, it does not. The Point here was a COPY of the actual data – so changing the X value did nothing.

To do what you wanted to do above, you had to:

XYZ newPt = new XYZ( myWall.Location.Point.X + 1,
                               myWall.Location.Point.Y, 
                               myWall.Location.Point.Z);
myWall.Location.Point = newPt;

In the case of the new immutable XYZ class, the only way to modify an XYZ, or UV, or ElementId is to construct a new version. So to modify an XYZ point, you must:

myPoint = new XYZ( myPoint.X +1, myPoint.Y, myPoint.Z);

If you did much with XYZ coordinates in the past, this likely means a bunch of grumbling, painful code re-writing and re-testing.

Oh – and ElementId? they changed the name of the actual Id property to “IntegerValue”. They’re not as bad as the Autodesk Vault team with the seemingly meaningless renames, but I definitely have had cause to grumble here.

Changes to the Element.ObjectType mechanism

Prior to 2011, if you wanted to interrogate the type of a given element, you navigated via the Element.ObjectType mechanism and voila, you were at the type element.

In 2011, this mechanism has been deprecated. In its place, you actually have to call a couple of methods to do the same thing:

Element.GetTypeId()   - which returns an ElementId, not an element. You’ll still have to call Document.get_Element() to get the element object.

Correspondingly – whereas you could previously just modify the element type through the property, you now much do Element.ChangeTypeId().

Further, if you used to use “Element.SimilarObjectTypes” to browse the corresponding other types that could be swapped to – you’ll now have to call Element.GetValidTypes().

Replacement of the Analytical Model classes

I have to say I’m relatively unfamiliar with AnalyticalModels – but suffice it to say it’s all been ripped out and replaced with something better! Unfortunately, you’ll have to re-work any existing usages.

Deprecated Events

If you were lazy last time – and didn’t remove your 2009-era events like Application.OnDocumentSaved, OnDocumentSavedAs, OnDocumentOpened, OnDocumentClosed, OnDocumentNewed, OnDialogBox, Document.OnSaveAs, OnSave, OnClose…

Then you’ve got some work to do – because they’ve all been removed now. They’ve all been replaced with newer and better events, though.

New Selection Mechanisms

The existing selection mechanisms (PickOne/Window Select). Find out all about the new mechanisms here.

Ribbon API changes

The ribbon API has had some non-trivial changes… if you’ve done a ribbon panel, it will require updates. See more here.

Print API changes

The PrintSetup.CurrentPrintSetting has been changed to a new interface: IPrintSetting. This should make things better going forward, but again – it will make for a little bit of cleanup time.

Re-work of the gbXML class

If you were previously getting at the gbXMLelement class, there’s some work required to get at its replacement – the EnergyDataSettings class. While it does inherit from Element, it’s been my experience so far that it is not retrievable in the same ways as in the past – it is not a parameter within the ProjectInformation class. Also, it is not queryable in the same ways as before.

To retrieve it in 2011, you need to actually call a static methods:

EnergyDataSettings.GetFromDocument(myDoc)

Also note the other static method: EnergyDataSettings.IsDocumentUsingEnergyDataAnalyticalModel(myDoc) – which tells you if there is an analytical model as well.

 

Installer Changes

While only a minimal installer change is necessary for 2011 (if you still like the bad-old-way of looking through registry uninstall keys to find which versions of Revit are installed and where) – you should probably think about going further.

While the Revit.INI file approach still works – the AddIn file mechanism is better, and the redistributable AddInUtility.dll can really help make this an easier process.

Whew!

While there’s a lot in this document, don’t despair… Chances are your application doesn’t use ALL of these features – does it? There are a variety of common, painful ones – but it’s mostly just mindless grinding through errors.

Just go into it with the right expectations – it will take you at least 3-5x as long as it used to take you with previous upgrade projects! It will be worth it to get to Revit 2011!

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

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.

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.

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:

Figure 1
Figure 1

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.

image
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

image

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:

image

The code required to do a TaskDialog is pretty straightforward:

TaskDialog td = new TaskDialog("Hello World");
td.MainContent = "This is main content";
td.ExtendedContent = “This is shown on demand”;
td.Show();

// or, alternatively – you can use a static method, if you only need the basics:
TaskDialog.Show("The Title", "The Main Instruction");

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.

Revit API 2011: The New UI vs. Database Split

(Part of our Revit API 2011 Series)
One interesting development in the Revit 2011 API is the splitting of the single Revit API into two – a Revit User-Interface DLL and a core Revit database DLL.

The “RevitAPI.dll” continues to cover the core database, while the new “RevitAPIUI.dll” covers the user-interface integration. This split extends to the core of the object model as well – while in the past the two primary classes in the API were Application and Document. Now, these classes have been split into:

  • UIApplication and Application
  • UIDocument and Document

UIApplication has picked up the classes and methods defining the RibbonPanels, the loaded applications, and some UI-oriented events like view changes and dialog boxes. The Application class retains the rest of the core application capability.

UIDocument picks up some of the UI-oriented aspects of the document, like selection, showing elements, and refreshing the active view.

The IExternalCommand and IExternalApplication interfaces live in the RevitAPIUI.dll, so all Add-In DLLs will have to reference the new DLL.

What does it all mean?

I don’t know this for certain, but I’m hopeful that this signals a shift towards an ability to access the Revit model outside of the user interface (similar to ObjectDBX/RealDWG on the AutoCAD side). I’m sure this is a hard feature for the factory to pursue – but here’s hoping that we might see it in a release or two.

What’s New in the Revit 2011 API: New Deployment Methods

(Part of our Revit API 2011 Series)
Deploying commands and applications in Revit up until now has required a mental visit back to the 90’s… You had to create or edit sections within the Revit.INI file – keywords and values (and ugly ones at that). And developing installers which would programmatically add and remove things? Ugh!

Autodesk has heard and finally answered the call on this issue – new in 2011 are XML-based “add-in” files. These new files (typically one for each program) also address some of the issues with permissions – particularly in Vista and Windows 7:

The locations are:

  • For “All Users”:
    • Windows XP: C:\Documents and Settings\All Users\Application Data\Autodesk\Revit\Addins\2011\
    • Windows Vista/Windows 7: C:\ProgramData\Autodesk\Revit\Addins\2011\
  • For “User-Specific”:
    • Windows XP: C:\Documents and Settings\<user>\Application Data\Autodesk\Revit\Addins\2011\
    • Windows Vista/Windows 7: C:\Users\<user>\AppData\Roaming\Autodesk\Revit\Addins\2011\

For .NET programmers, I would recommend using the Environment.GetFolder() method, where you can specify:

  • All Users: Environment.SpecialFolder.CommonApplicationData
  • Current User: Environment.SpecialFolder.ApplicationData

A basic Command sample might look like:

<?xml version="1.0" encoding="utf-16" standalone="no"?>
<RevitAddIn>
<AddIn Type="Command">
<Assembly>C:\MyDirectory\MyCommand.DLL</Assembly>
<ClientId>64end01a-5d66-4243-b4544-31429ecae9ed</ClientId>
<FullClassName>Avatech.RoomRenumber</FullClassName>
<Text>Room Renumber</Text>
<VisibilityMode>NotVisibleInFamily</VisibilityMode>
<VisibilityMode>NotVisibleInMEP</VisibilityMode>
<AccessibilityClassName></AccessibilityClassName>
</AddIn>
</RevitAddIn>

I’ll write more about some of the capabilities implied here – but as you can see it represents a big step forward versus the REVIT.INI file (which still works).

More Deployment Help Still… For Installers.

As mentioned above – writing installers for Revit in the olden-days was no picnic. While it’s no picnic in 2011, beyond the new file format, Autodesk has also provided an all-new redistributable DLL – specifically to help developers do installations in .NET.

The “RevitAddInUtility.DLL” can:

  1. Provide you information about which versions of Revit 2011 are installed (no much reverse engineering 6+ uninstall registry keys!).
  2. Get all existing addins, and manifest.

All in all, there are a variety of new features, capabilities and tools which bring more power and professionalism to Revit AddIn deployment in 2011.

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:

  1. Upgrading Existing Revit API commands/applications
  2. New Deployment Methods
  3. The New UI vs. Database split.
  4. New Ribbon Capabilities
  5. Element Iteration Changes
  6. Ooh-ooh Pick Me! New Selection Methods
  7. Dynamic Model Update
  8. Event Model Changes
  9. RevitLookup: The New RevitMgdDbg
  10. Revit AddIn Manager: Almost Edit & Continue
  11. What’s New in Element Creation?
  12. Exceptional Stuff
  13. What Kinds of Applications are Possible Now?
  14. And More…

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).

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

Getting back into the swing of things

I apologize! I've committed the cardinal sin of blogging - not doing it once you got started.

But you know how it is - work gets busy, yadda, yadda, yadda.

In any case - I think it's back to a level where I can blog occasionally... and I'm looking forward to it. Now if I can just remember all the ideas I had while I've been "away".

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:

AU Session Selection

Thanks!

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.

image 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.

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.

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).

image

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.

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.

image

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.

What’s New in the Revit 2010 API: Element Enhancements

(Part of the What’s New in the Revit 2010 API series)

As with each release of the Revit API, there are a ton of enhancements to the “Elements” area of the Revit API. Whether it’s new capabilities on existing elements, or new Element classes to make Revit elements more identifiable and understandable – enhancements here are a big deal.

Elements and Materials

One of the features I’m most excited about is the new Element/Material part of the API. In the past, trying to do material take-offs with the API was tough – especially if the designers were using Split Faces (which almost everyone does). You pretty much had to export out to ODBC or schedules to Excel in order to extract what you needed. But no more.

image This room floor has been divided by a split face – with one of the sides being carpet and the other tile.

In Revit 2010, every Element has a Materials property to show all the materials associated with an element. Further, you can call Element.GetMaterialArea( Material ) or
Element.GetMaterialVolume (Material)

to get the area or volume of material for that element. With this, people trying to do material take-offs through the API should be in far better shape!

Element Hiding

For a number of releases, Revit has supported the hiding of individual elements on a view-specific basis. While great for designers, it did pose occasional challenges for developers. Now, the API offers up:

Element.CanBeHidden ( View v )
Element.IsHidden( View v )
as well as:
View.Hide( Element e)
View.UnHide( Element e)

This should give developers powers similar to what you can do in Revit interactively (that fairness which every CAD developer yearns for :) ).

Family Enhancements

There are few enhancements with Family and FamilyInstance elements:

  • Family.IsInPlace (this was possible heuristically in previous releases – but it’s always better to make it obvious)
  • Family.IsCurtainPanelFamily (because of the special additional properties – it’s good to know this directly)
  • FamilyInstance.IsSlantedColumn (another situation where there are special additional properties)
  • FamilyInstance.Space  (similar to familyInstances knowing which Room they reside in, now they know which space they reside in – very useful for MEP families!)

New Element Classes

The following classes are new in 2010:

  • Alignment
  • AreaScheme (see below)
  • BasePoint
  • Control
  • CurveByPoints
  • CurveElement
  • DividedSurface (with an amazing amount of depth!)
  • Form (representing all of the Family solid content, and also with a huge amount of depth)
  • ImportInstance (used for DWG imports, etc)
  • ModelText
  • PointOnEdge
  • PointOnEdgeEdgeIntersection (I think you might need to have a PhD or be Russian to understand this :) ).
  • PointOnEdgeFaceIntersection
  • PointOnFace
  • PointOnPlane
  • ReferencePoint
  • ReferencePointArray
  • SpacingRule (structure and grids)
  • SweptBlend
  • SymbolicCurve
  • TopographySurface (with an “AddPoints” method, no less)

Areas

There appear to be a few enhancements to Area elements that are of note:

  • New AreaScheme element (this typically is set for “Rentable”, “Gross” but also apparently has some new BOMA settings for facilities management people)
  • Areas have a link to their scheme
  • ViewPlans have a link to the AreaScheme (where appropriate)

Dimensioning

Dimensions also seem to have some upgrades in 2010. In particular:

  • Dimensions have DimensionSegments
  • The “Locked” property (read/write) has been added

Other Miscellaneous Enhancements

A few others that I couldn’t categorize:

  • Blends now have access to Profiles, Offsets and VertexConnections.
  • CurtainGridLines now have ExistingSegmentCurves
  • Grid.ExtendToAllLevels method
  • GridNodes
  • GBXMLParamElement now has an ExportComplexity object associated with it which contains all sorts of things to control how GBXML is exported (including, for example, how to handle Shading Surfaces).
  • ModelCurve now exposes:
    • IsReferenceLine
    • SubCategory
    • TrussCurveType
    • Visibility
  • Mullion.LocationCurve
  • Opening exposes IsTransparentIn3D and IsTransparentInElevation.
  • Path3D.AllCurveLoops

Two that I’ll be writing about a little later:

  • Room.IsPointInRoom (XYZ)
  • Space.IsPointInSpace( XYZ )

A few items seem targeted at making it easier to get geometry references and planes:

  • Level now exposes a PlaneReference (to make things easier)
  • ReferencePlane.Reference
  • SketchPlane exposes:
    • Reference
    • IsSuitableForModelElements
  • View.SketchPlane


Wow. Again – there’s enough in these enhancements, new classes and more to keep us busy for quite some time.

What’s New in the Revit 2010 API: Element Creation

(Part of the What’s New in the Revit 2010 API series)

For some people, the measure of a CAD API is always how many different types of elements it can create. Revit got off to a slow start in this category, but it continues to get stronger.

In this release, the new Revit API capabilities seem divided into:

  • A significant amount of new MEP element creation
  • A little bit of new Structure / Rebar options
  • A significant amount of new capabilities around family content creation.
  • A few very interesting things around the new freeform geometry and divided surface modeling in Revit 2010.

All in all, Revit can now create 70-100 different types of elements (depending on how you count the family content-related things).

What’s New for MEP Creation?

Here are the new MEP-oriented creation capabilities:

  • Duct
  • Elbow
  • ElectricalSystem
  • FlexDuct
  • FlexPipe
  • MechanicalSystem
  • Pipe
  • PipingSystem
  • Cross Fitting
  • TakeOffFitting
  • TeeFitting
  • UnionFitting
  • Wire

(not being very MEP-savvy myself, I can’t add any real commentary to them other than to say it looks like an impressive list).

What’s New in Family Content Creation?

This whole area is new and exciting…

  • Solid Forms
    • Blend
    • Extrusion
    • ExtrusionForm
    • Form By Cap
    • Form By ThickenSingleSurface
    • Loft
    • Revolution
    • SweptBlend
  • Supporting Elements
    • Angular Dimension
    • ArcLength Dimension
    • Linear Dimension
    • Radial Dimension
    • Symbolic Curve
    • Control
    • Alignment (this looks interesting)
    • Vertex Index Pair (this is a construct which defines how different profiles in a blend link together, I believe)
    • Family Symbol Profile
  • More Elements
    • Openings
    • Model Text
  • Freeform Modeling / Surfacing
    • Curve By Points
    • Divided Surface
    • Reference Point

A Brief Story on Reference Points

A year or so ago I pinged Emile Kfouri, the Revit Platform Product Manager about why there were no “Points” in Revit (I can’t recall why I needed them – but I do know how old-time CAD people’s heads look like they’re going to explode when I say that they don’t exist). He said “Points are not BIM” – and I came to agree with the statement, in general (not that Lines are BIM – and they were prevalent in Revit still). In any case – while they’re not BIM, they are quite handy for building things – and it’s nice to see them in there.

A Few More…

Finally, there are a couple last additions and changes…

  • Rebars defined by RebarShapes
  • Hermite Splines (these are one of the building blocks of the new freeform modeling capabilities)
  • Plane from Curves
  • Topography Surface (Now this looks very interesting – just pass in an array of XYZ points and get back a surface? I haven’t had a chance to try it out yet – but it should be cool!)

image

Image: a spline-controlled surface with control points that can be dragged/modified.

Summary

All in all, this release presents a great deal of new capabilities around Element creation… certainly enough to keep most of us busy for the next year until Revit 2011 comes out!

Thursday, February 19, 2009

What's New in the Revit 2010 API: User Interface

From the (What's New in Revit 2010 API series).

As you may know, Revit 2010 brings the Ribbon-style User-Interface to the world of Revit. Similar to bringing the Ribbon to Microsoft Office or AutoCAD - this has far-reaching effects on how users will navigate Revit.

For better or worse, ExternalCommands and ExternalApplications will be shoe-horned into the new Ribbon concept.

How it Works

First, if you have any "Add-ins" of any kind, the "Add-in" tab is visible in Revit.

Second, any ExternalCommands which previously were on the Tools > External Tools menu are now on the Add-Ins menu under the "External Tools" pulldown-button.

Third, there are a number of "constructs" for how you can customize the ribbon. Unlike AutoCAD's WPF Ribbon UI, you are limited to just a couple of UI elements.



The key elements are:

  • RibbonPanel - creating an "area" to contain your application

  • Pushbutton - a single Pushbutton command

  • PulldownButton - a button which drops down a list of commands

  • Separator - basic separation

Both Pushbuttons and PulldownButtons can have large (32x32) icons and small (16x16) icons (not shown above). The large icon is always displayed on the button, while the small icon is only shown if the user adds the button to the "Quick Access Toolbar" - which is always available.

Autodesk also released a 29-page document describing how icons should be created to fit in with Revit (who knew it could be so complicated? :) ).

Existing Applications

The existing APIs that applications use to create both top-level menus or toolbars have disappeared - so you MUST migrate to this approach.

Summary Opinion

While I think that it's great that the Ribbon has come to Revit - I really like it... The UI straightjacket that we've been put in with the UI is a little tight... It would be nice if we could at least do stacked buttons like the rest of Revit.

(Editors Note: Stacked buttons, 2 or 3 high - was added in the API after this was written)

It's also a little unfortunate that everything external is confined to the "AddIns" tab - both because we used to be able to have "top-level" menus, but also because if you have a lot of applications loaded, the real-estate may get crowded.

What's New in the Revit 2010 API: Finally Families!






(Part of the What's New in Revit 2010 API series)





Probably the biggest single improvement to the Revit API in 2010 is a wide variety of enhancements to supporting Revit Families - and it's been a long time coming.


Until now, the support for families has been spotty - for example, you could open family files as documents - but you couldn't see the types inside them - or really do anything with them.

Autodesk has implemented a dizzying amount of capabilities to help with:

  • Analyzing Families

  • Creating new Families (geometry, parametrics and all!)

  • Reading and Writing Family Types, parameters, and even formulas

  • Ability to examine Families embedded in projects

  • Read/Write Family Element Visibility

  • Control the loading behavior of families
Personally, after doing a number of Family manipulation projects which had to be done with Journal Files - I'm excited to be back dealing with the API!

Enhanced Document class
The core concept of working with families in the Revit 2010 API is the improved "Document" class. The Document class still represents both Project and Family documents, but it has been enhanced with the following properties and methods:



  • EditFamily( family) - similar to context-menu Edit Family command

  • FamilyManager (provides access to the types, parameters, and formulas related to the family)

  • OwnerFamily - to deal with nested family components

The Family Manager is able to do a wide variety of tasks, including full control of adding, removing and renaming types, adding and removing parameters, and setting values and formulas.

Creating Solids



Creation of elements will be covered in more depth in another post - but suffice it to say there is an impressive list of things that you can programmatically create through the new APIs, including:


  • Extrusions

  • Blends

  • Sweeps

  • Loft

  • Model Text

  • Openings

  • Revolutions

  • Dimensions

  • and much more



Visibility Settings

For those of you who are not familiar with content building, one of the most critical topics to "get right" when building content is the visibilty settings:




Each element in a family has visibility settings - both which levels of detail it appears in as well as whether it appears in different types of views. These options are critical to building good content. For example, if you have intricate details in your family, consider if they should only be shown in "Fine" detail views. Also, if you have 3D solid content, one alternative is to NOT show the 3D solid in Plan views - instead, you would use 2D linework in Plan View. These approaches can make a SUBSTANTIAL difference in the performance of Revit - particularly as your building model grows.

While there had been undocumented parameter access to this information before, the new FamilyElementVisibility class makes this information easy to access for each element in a family.

Loading Control
If you've ever written an application that loads families into a project, you may have run into the problem of what happens when the family already exists in the project (particularly if you're using shared families). While the "DialogBox" event controls used to give a poor-but-workable method to suppress Revit's pop-up dialog boxes, the new loading methods give far better control over what happens.

The new LoadFamily method signature:

Family = Document.LoadFamily( string path, IFamilyLoadOptions options );
or
Family = Document.LoadFamily( Document familyDocument, IFamilyLoadOptions options);

The IFamilyLoadOptions, as implemented by the RevitUIFamilyLoad class, give you events for family loading as well as specific behavior control for whether to update the family, and whether to override parameters.


What Can You Do With All This?

There are a variety of capabilities that these features open to you... First of all, I suspect that a variety of new content tools will become available to better manage your content. If you manage a great deal of content, and need to make large-scale changes to content, these features will make it happen.

It IS possible now to extract project families back to RFAs - as well as doing better comparisons than previously possible between "embedded" families and standalone families.

Another big step for Autodesk - they now allow you to use the API insert a DWG file into a family. This had previously been deliberately disabled.

Hypothetically speaking, this means that you could possibly crank out thousands of families based on existing DWGs. But before you consider doing this - let me be among the voices saying - DON'T. Our research indicates that families created using DWG files are fundamentally terrible - they are "heavy", "slow", and "dumb". Almost all firms using Revit have discovered this - and are systematically removing these families from their library. Doing content correctly would be a great other post - and the API now gives you the tools to do things right... Please try to do the right thing!

-Matt