Revit APP Blog

Information on Revit APP.

Browsing Posts in Technical

We don’t want to discuss how you can modify or set Revit built-in schedule, instead we want to discuss how we can leverage different tools to get most customized schedule. Most of you may suffer when try to customize Revit built-in schedule especially when you want to follow some localization requirements. Revit API doesn’t provide comprehensive access for schedule but it allows 3rd party developer to have almost fully control of elements’ parameters. In addition, Microsoft Excel has powerful customization capability for whatever kinds of schedule you want with plenty help documentation like MSDN. As a result, you have the data and the tool, what obstacle you still? :) (For excel help: MSDN-http://msdn.microsoft.com/en-us/library/wss56bz7%28v=vs.80%29.aspx or other documentation)

Here we want to share how you can get up-to-date excel worksheet instead of detail of how you need to write code for excel or get parameters. Revit API provides a wonderful mechanism as IUpdater to let API developer be notified when something is changed inside.

public class ParameterUpdater : IUpdater

{

AddInId addinID;

UpdaterId updaterID;

ElementId paramId;

public ParameterUpdater(AddInId id, BuiltInParameter param)

{

addinID = id;

paramId = new ElementId(param);

updaterID = new UpdaterId(addinID, new Guid(“6BBDEB2B-F83B-40df-9101-01A02DFC1A37″));

}

public void Execute(UpdaterData data)

{

Document doc = data.GetDocument();

// update your Excel worksheet…

}

public string GetAdditionalInformation() { return “Element Parameter Changed”; }

public ChangePriority GetChangePriority() { return ChangePriority.FloorsRoofsStructuralWalls; }

public UpdaterId GetUpdaterId() { return updaterID; }

public string GetUpdaterName() { return “Element Parameter Changed”; }

public ChangeType GetChangeType() { return Element.GetChangeTypeParameter(paramId); }

}

This class gets Revit model parameter change events through implementing IUpdater interface. All functions are must implemented interfaces except the GetChangeType which is for convenient. The most important interface is the Execute which will be called when subscribed events happen (here is the parameter value changed event). We can also subscribe Application.DocumentChanged but this event will be triggered for any change in the document. So we would strongly suggest to use IUpdater mechanism for this case.

Then in your own OnStartup interface function add following code:

ParameterUpdater updater = new ParameterUpdater(uiControlledApplication.ActiveAddInId, BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS);

if (!UpdaterRegistry.IsUpdaterRegistered(updater.GetUpdaterId()))

UpdaterRegistry.RegisterUpdater(updater);

ElementCategoryFilter pipeFilter = new ElementCategoryFilter(BuiltInCategory.OST_PipeCurves);

ElementIsElementTypeFilter nonTypeFilter = new ElementIsElementTypeFilter(true);

LogicalAndFilter filter = new LogicalAndFilter(pipeFilter, nonTypeFilter);

UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), filter, updater.GetChangeType());

UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), filter, Element.GetChangeTypeElementAddition());

UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), filter, Element.GetChangeTypeElementDeletion());

Here we subscribed the Comments parameter which you can change to any parameter you want. Another thing I want to mention is that ParameterUpdater won’t be triggered when new element is added or element is deleted, so we also registered Element.GetChangeTypeElementAddition() and Element.GetChangeTypeElementDeletion() to track new element and element deletion.

All materials in a document is stored in doc.Settings.Materials (doc is the pointer of the document). You can get all available materials through this property.

Material’s specified properties:

Color The color of the material.
CutPattern The cut pattern of the material.
CutPatternColor The cut pattern color of the material.
Glow Whether the material can glow.
RenderAppearance The rendering appearance property of the material.
Shininess The shininess of the material.
Smoothness The smoothness of the material.
SurfacePattern The surface pattern of the material.
SurfacePatternColor The surface pattern color of the material.
Transparency The transparency of the material.

You can modify a meterial through these properties. Of course, you can also add/insert/remove materials for doc.Settings.Materials.

An old post http://blog.revitapp.com/2010/05/autodesk-revit-api-overview/ descibed what we can do with Revit API. Let’s recall the concept:

What Can I Do With the Autodesk Revit API?

The following are general areas where the API is suitable:

  • Creating add-ins to automate repetitive tasks in the Autodesk Revit user interface
  • Enforcing project design standards by checking for errors automatically
  • Extracting project data for analysis and to generate reports
  • Importing external data to create new elements or parameter values
  • Integrating other applications, including analysis applications, into Autodesk Revit products
  • Creating Autodesk Revit project documentation automatically

From the items, we can see that there actually are still restrictions for us to develop Revit addins applications. The main point is, most disabilities of Revit cannot be achieved by Revit API. That’s to say, if user can’t do the work manually in Revit, then most probably it also can’t be accomplished by Revit API. However, I think Revit API would be able to extend much in the future and real extend Revit capabilities.

So this doc only wants to help an API developer quickly judge the feasiblity of a requirement. Anyway, keep in mind that this is not always true, sometimes there is workaround for us.

Revit 2011 API provides user methods to select objects or point.

You can get Selection object from  commandData.Application.ActiveUIDocument.Selection.

The Selection has following members to select:

  • PickElementsByRectangle: Prompts the user to select multiple elements by drawing a rectangle.
  • PickObject: Prompts the user to select one object.
  • PickObjects: Prompts the user to select multiple objects.
  • PickPoint: Prompts the user to pick a point on the active work plane.

You can use the return value for these functions to get the selection results. We already posted a doc (http://blog.revitapp.com/2010/06/the-new-way-to-select-elements/) for PickObject, others are similar to use.

There are many changes to the VSTA framework:

  1. Revit VSTA no longer depends on the proxy DLL. Macros are now written referencing RevitAPI.dll and RevitAPIUI.dll directly. This allows macros access to the full features of the Revit API, including generic methods, all events and other methods missing from the proxy previously.  Module templates have been updated accordingly, and the references will be added automatically when upgrading macros from previous releases.
  2. The entry point classes ThisApplication and ThisDocument have been adjusted to the direct reference of the API classes.  They also now represent UIApplication and UIDocument (instead of Application and Document).
  3. The Transaction and Regeneration attributes must be applied to the ThisApplication and ThisDocument class. Their meanings for VSTA are same as for external commands.  Module templates have been updated with default assignments, but upgraded modules must have these added manually.
  • A special AddInId attribute can be added to modules.  This allows VSTA macros to work with updaters.  When new modules are created this attributes is automatically generated with a random Guid.
  • The Module_Startup methods are now executed at the time when the module is first loaded (as the Revit application starts for Application-level macros, and as the document is loaded for document-level macros).

4. No transactions may be opended in the Module_Startup and Module_Shutdown methods.

New modules created in Revit 2011 should be “ready to code” – all framework changes have been incorporated into the templates.

Upgraded macros and modules will need to be adjusted to the framework changes mentioned above, as well as all of the API changes (namespace changes, modified APIs).

Revit doesn’t provide API to export/extract thumbnail from Revit files, especially Revit family files. However, there always is workaround in the world.

There is a very good article talking about this with detail, here is the link:

http://redbolts.com/blog/post/2008/12/01/Getting-your-Revit-thumbnails.aspx

If this isn’t work for you. There is another way: open the Revit file, export a bitmap then close it and use the bitmap according it. If anyone is interesting in this, I will write article later on this topic.

All Revit API methods have been changed to throw subclasses of Autodesk.Revit.Exceptions.ApplicationException. Some Revit exceptions, such as

  • ArgumentException
  • InvalidOperationException
  • FileNotFoundException

closely mirror the corresponding .NET System exception types. However, some of them have subclasses which are unique to Revit, e.g.

  • AutoJoinFailedException
  • RegenerationFailedException
  • ModificationOutsideTransactionException

In addition, there is a special exception type called InternalException, which represents a failure path which was not anticipated. Exceptions of this type carry extra diagnostic information which can be passed back to Autodesk for diagnosis.

The class hierarchy for accessing the structural analytical model has been replaced. The new class hierarchy offers a more streamlined interface and more capabilities to read data and modify analytical model settings.

The following AnalyticalModel subclasses have been removed:

  • AnalyticalModel3D
  • AnalyticalModelFloor
  • AnalyticalModelFrame
  • AnalyticalModelLocation
  • AnalyticalModelWall

 

Access the data you used to find on those subclasses on the base AnalyticalModel class, as follows:

 Old property  Found on  New method  Notes
 .Curve  AnalyticalModelFrame  GetCurves()  If analytical model was approximated, .Curve would have previously returned non-approximated analytical model. Now GetCurves() will return approximated analytical model when analytical model is approximated. GetCurve() is a shortcut method returning the single curve.
 .Curves  AnalyticalModel3D, AnalyticalModelFloor, AnalyticalModelFrame, AnalyticalModelLocation, AnalyticalModelWall  GetCurves()  AnalyticalCurveType.ActiveCurves will return the analytical model displayed by Revit. Most of the time, this is what is desired.
 .Point  AnalyticalModelLocation  GetPoint()  GetCurves() can also be called, the return will be a single curve of almost 0-length containing the point.
 .Profile  AnalyticalModelFrame  GetSweptProfile()  
 .RigidLink  AnalyticalModelFrame  GetCurves(AnalyticalCurveType.RigidLinkHead) or GetCurves(AnalyticalCurveType.RigidLinkTail)  AnalyticalCurveType.RigidLinkHead retrieves the Rigid Link at the end, and AnalyticalCurveType.RigidLinkTail retrieves the Rigid Link at the start.
 .SupportData  AnalyticalModel3D, AnalyticalModelFloor, AnalyticalModelFrame, AnalyticalModelLocation, AnalyticalModelWall  GetAnalyticalModelSupports()  

Note that the curves returned from these new methods will not have their Reference properties set, and cannot be used for the properties like Curve.EndPointReference. Instead, you can obtain References to the curves and their endpoints through construction of an AnalyticalModelSelector object containing the necessary information.

The AnalyticalModel class offers new methods to access other Analytical Model properties, such as:

  • Adjustment information, both manual and automatic
  • Parameter information, including projection, hard points, approximation, and rigid links
  • Analytical offset

The AnalyticalModelProfile class has been replaced by the AnalyticalModelSweptProfile class, which offers similar contents to the original class.

The AnalyticalSupportData and AnalyticalSupportInfo classes have been replaced by collections of AnalyticalModelSupport objects. This new class offers the same information offered by AnalyticalSupportInfo, plus:

  • The support priority
  • The curve, point, and face providing support

The new AnalyticalSupportChecking interface offers the ability to run the check for unsupported structural elements. The new AnalyticalConsistencyChecking interface offers the ability to run a consistency check for the Analytical Model.

The results of both checks are added to the document as warnings.

Access the AnalyticalModel through the method GetAnalyticalModel() on Element. This replaces the AnalyticalModel property of Wall, Floor, ContFooting and FamilyInstance.

The integer values of the enumerated type AnalyticalSupportType have changed.  They no longer match the values returned for the built-in parameter BOUNDARY_CONDITIONS_TYPE, use the members of the enum BoundaryConditionsType instead.

Powered by WordPress Web Design by SRS Solutions © 2012 Revit APP Blog Design by SRS Solutions