2 Revit UI API
2 Revit UI API
Revit UI API
© 2014 Autodesk
Agenda Introduction to Revit Programming
UI Topics
Ribbon
User Selection
Task dialog
Events
Dynamic model update
© 2014 Autodesk
Introduction to Revit Programming
Ribbon API
How to add your own Ribbon buttons
Ribbon API Introduction to Revit Programming
Overview
© 2014 Autodesk
Ribbon API Overview Introduction to Revit Programming
Pull-down button
Split button
Radio Group
Combo box
© 2014 Autodesk
Ribbon API Classes Introduction to Revit Programming
RibbonPanel
A panel containing ribbon items or buttons
RibbonItem
A button, push or pull-down, ComboBox, TextBox, RadioButton, etc.
PushButton, PushButtonData
Manage push button information
PulldownButton, PulldownButtonData
Manage pull-down button information
SplitButton, SplitButtonData
Manage split button information
ComboBox, ComboBoxData
Manage combo box information
…
© 2014 Autodesk
Ribbon API Since Revit 2011~ Introduction to Revit Programming
Namespace
Autodesk.Revit.UI
Properties
RibbonItem.Visible
RibbonItem.LongDescription
RibbonItem.ToolTipImage
PushButton.AvailabilityClassName
© 2014 Autodesk
Lab - Ribbon API Introduction to Revit Programming
© 2014 Autodesk
Introduction to Revit Programming
User Selection
Point and object(s) selection using the API
User Selection Introduction to Revit Programming
Overview
IList<Element> hasPickSome =
choices.PickElementsByRectangle("Select by rectangle");
if (hasPickSome.Count > 0)
{
int newSelectionCount = choices.Elements.Size;
string prompt = string.Format("{0} elements added to Selection.",
newSelectionCount - selectionCount);
TaskDialog.Show("Revit", prompt);
}
© 2014 Autodesk
User Selection Introduction to Revit Programming
Overview
Selection Filter
ISelection Interface to help filter objects during selection
AllowElement()
AllowReference()
public void SelectPlanarFaces(Autodesk.Revit.DB.Document document)
{
UIDocument uidoc = new UIDocument(document);
ISelectionFilter selFilter = new PlanarFacesSelectionFilter();
IList<Reference> faces = uidoc.Selection.PickObjects(
ObjectType.Face, selFilter, "Select multiple planar faces");
}
© 2014 Autodesk
Lab - User Selection
Introduction to Revit Programming
Pick Sampler
© 2014 Autodesk
Lab - User Selection Introduction to Revit Programming
<CS>
XYZ pt1 = rvtUIDoc.Selection.PickPoint("Pick the first corner of walls");
XYZ pt2 = rvtUIDoc.Selection.PickPoint("Pick the second corner");
© 2014 Autodesk
Introduction to Revit Programming
Task Dialogs
Revit styled message boxes
Task Dialogs Introduction to Revit Programming
Overview
A modal dialog with set of controls
Revit style alternative to simple Windows message box.
Used when system needs to
Provide information
Ask a question
Allow users to select options to perform task
Overview
© 2014 Autodesk
Lab - Task Dialog Introduction to Revit Programming
Dialog Sampler
<CS>
// (0) create an instance of task dialog to set more options.
TaskDialog myDialog = new TaskDialog("Revit UI Labs - Task Dialog Options");
// (1) set the main area. these appear at the upper portion of the dialog.
myDialog.MainIcon = TaskDialogIcon.TaskDialogIconWarning;
// or TaskDialogIcon.TaskDialogIconNone.
myDialog.MainInstruction =
"Main instruction: This is Revit UI Lab 3 Task Dialog";
myDialog.MainContent = "Main content: You can add detailed description here.";
if (stepByStep) myDialog.Show();
</CS>
© 2014 Autodesk
Lab - Task Dialog Introduction to Revit Programming
<CS>
TaskDialog houseDialog = new TaskDialog("Revit UI Labs - Create House Dialog");
houseDialog.MainInstruction = "Create a house";
houseDialog.MainContent = "There are two options to create a house.";
houseDialog.AddCommandLink(TaskDialogCommandLinkId.CommandLink1, "Interactive",
"You will pick two corners of rectangular footprint of a house, and choose where you
want to add a front door.");
houseDialog.AddCommandLink(TaskDialogCommandLinkId.CommandLink2, "Automatic",
"This is will automatically place a house with a default settings.");
houseDialog.CommonButtons = TaskDialogCommonButtons.Cancel;
houseDialog.DefaultButton = TaskDialogResult.CommandLink1;
© 2014 Autodesk
Introduction to Revit Programming
Overview
Types :
Application level
Document level
Element level
© 2014 Autodesk
Events Introduction to Revit Programming
Overview
© 2014 Autodesk
Events Introduction to Revit Programming
EventHandler
public void UILabs_DocumentChanged(object
{
sender, DocumentChangedEventArgs args)
// Do something here
}
return Result.Succeeded;
}
© 2014 Autodesk
Lab - Events Introduction to Revit Programming
© 2014 Autodesk
Dynamic Model Update Overview
Introduction to Revit Programming
© 2014 Autodesk
Dynamic Model Update Introduction to Revit Programming
Updaters
Updaters :
Ability to implement a method that is informed of the scope of
changes
© 2014 Autodesk
Dynamic Model Update Introduction to Revit Programming
Add Trigger
Change of Scope - list of ElementIds or list of elements via ElementFilter.
Change
// Set of Type - addition, deletion and modification
the filter
ElementClassFilter filter = new ElementClassFilter( typeof( Wall ) );
// Add trigger
UpdaterRegistry.AddTrigger(updater.GetUpdaterId(),filter,
Element.GetChangeTypeGeometry());
© 2014 Autodesk
Lab - Dynamic Model Update Introduction to Revit Programming
© 2014 Autodesk
Introduction to Revit Programming
Conclusion
Where do we go next …
We have covered… Introduction to Revit Programming
UI Topics
Ribbon
User Selection
Task dialog
Events
Dynamic model update
© 2014 Autodesk
Learning More Introduction to Revit Programming
Discussion Groups
http://discussion.autodesk.com > Revit Architecture > Revit API
© 2014 Autodesk
Introduction to Revit Programming
Thank you!
© 2014 Autodesk
Introduction to Revit Programming
Autodesk is a registered trademark of Autodesk, Inc., and/or its subsidiaries and/or affiliates in the USA and/or other countries. All other brand names, product names, or trademarks belong
to their respective holders. Autodesk reserves the right to alter product and services offerings, and specifications and pricing at any time without notice, and is not responsible for
typographical or graphical errors that may appear in this document.