P.S. The apps need to be submitted to Autodesk by September 14, so small/medium sized utilities will be a better fit than big projects like an FBX Importer
SAuBIM Version 2.0, an add-in for updating your occupant load tags with the click of a button, is now available. Boost Your BIM partnered with The Revit Kid to create this new version that uses the Revit API to integrate with Revit 2013 and Revit 2014.
Here is how to prompt the user to click twice and use those points to create a new dependent view cropped to the rectangle formed by those points.
publicvoid MakeViewAndSheetWith2Clicks()
{
Document doc = this.ActiveUIDocument.Document;
UIDocument uidoc = new UIDocument(doc);
// prompt user to pick two points
XYZ lowLeftPickPoint = uidoc.Selection.PickPoint("Pick lower left corner");
XYZ upRightPickPoint = uidoc.Selection.PickPoint("Pick upper right corner");
// create a new BoundingBoxXYZ & set its Min and Max to the XYZ points selected by the user
BoundingBoxXYZ bboxFromPicks = new BoundingBoxXYZ();
bboxFromPicks.Min = lowLeftPickPoint;
bboxFromPicks.Max = upRightPickPoint;
// Find a titleblock in the project, or use InvalidElementId to create a sheet with no titleblock
ElementId titleblockId = ElementId.InvalidElementId;
FamilySymbol titleBlockSymbol = doc.TitleBlocks.Cast<FamilySymbol>().FirstOrDefault();
if (titleBlockSymbol != null)
titleblockId = titleBlockSymbol.Id;
ViewSheet sheet = null;
using (Transaction t = new Transaction(doc,"crop"))
{
t.Start();
// duplicate the active view
ElementId newViewId = doc.ActiveView.Duplicate(ViewDuplicateOption.AsDependent);
View newView = doc.GetElement(newViewId) as View;
// set the crop box of the new view to the bounding box created from the two picked points
newView.CropBox = bboxFromPicks;
// Create the new sheet
sheet = ViewSheet.Create(doc, titleblockId);
newView.Name = sheet.Name + "-" + sheet.SheetNumber;
newView.Scale = 10;
// Create the viewport to put the new view on the new sheet at (0,0,0)
Viewport.Create(doc, sheet.Id, newViewId, XYZ.Zero);
t.Commit();
}
// make the new sheet the active view
uidoc.ActiveView = sheet;
}
publicvoid CreateSheetSet()
{
Document doc = this.ActiveUIDocument.Document;
// create a new ViewSet - add views to it that match the desired criteria
ViewSet myViewSet = new ViewSet();
string match = "S";
foreach (ViewSheet vs innew FilteredElementCollector(doc).OfClass(typeof(ViewSheet)).Cast<ViewSheet>()
.Where(q => q.SheetNumber.Contains(match)))
{
myViewSet.Insert(vs);
}
// get the PrintManger from the current document
PrintManager printManager = doc.PrintManager;
// set this PrintManager to use the "Selected Views/Sheets" option
printManager.PrintRange = PrintRange.Select;
// get the ViewSheetSetting which manages the view/sheet set information of current document
ViewSheetSetting viewSheetSetting = printManager.ViewSheetSetting;
// set the views in this ViewSheetSetting to the newly created ViewSet
viewSheetSetting.CurrentViewSheetSet.Views = myViewSet;
if (myViewSet.Size == 0)
{
TaskDialog.Show("Error", "No sheet numbers contain '" + match + "'.");
return;
}
using (Transaction t = new Transaction(doc,"Create ViewSet"))
{
t.Start();
string setName = "'" + match +"' Sheets";
try
{
// Save the current view sheet set to another view/sheet set with the specified name.
viewSheetSetting.SaveAs(setName);
}
// handle the exception that will occur if there is already a view/sheet set with this namecatch (Autodesk.Revit.Exceptions.InvalidOperationException)
{
TaskDialog.Show("Error", setName + " is already in use");
t.RollBack();
return;
}
t.Commit();
}
TaskDialog.Show("View Set", myViewSet.Size + " sheets added to set");
}