This past Saturday the last day of October could only mean one thing, trick or treaters around the street and crazy Halloween parades overcrowding 6th Avenue in NYC. Unfortunately, this year I was not able to join and get dressed up as previous years since I moved to a new place, so we can say my Halloween costume for this year was an Apartment Mover. I still got the chance to see some of this years customs on the Streets of NYC and thankfully I ran into my favorite movie characters of all time, yes you guessed it right, Star Wars costumes. Check out this nice picture of a family of three where the youngest Storm Tropper took his duty very seriously and gave me a violation ticket because I was not wearing any custom that day.
Back to Revit API. This past week I had the chance to work on a case, where a developer was trying to find a way to create a custom ViewSet in order to print the Sheets he selected from the Project Browser tab.
Question: I’m working on one addin that will allow me to select the sheets I want to include in my custom Viewset in order to print them. I have attached all files for reference. Looking for solutions from Revit API experts.
Answer: I see that your question was posted in the Revit API forum as well (See link here). Where other API developers have done very good suggestions. Even creating your own Windows Form to add the selected sheets so you can create the ViewSet you desire to Print.
Response Developer:The suggestions we received in the forum are correct, but we are trying to do in other manner as mentioned in the attachment. One more clarification to you we are not trying to do this in a Windows form. I want add the ones I select to the printing set.
Final Answer: Thank you for your explanation. So if this does not give you Joy, I don't know what it will :). Here I'm providing you a function that creates your own custom ViewSet to be ready to Print, which will include the Sheets you select from the Sheets tree in the Project Browser.
How to use it: Select one or more Sheets using CTRL key to add more and then run your plugin. After the ViewSet gets created you can open the Print Dialog in order to check that what you selected has been included in the View/Sheet Set.
I will suggest to add some tweaks to the code in order to make it more personalized for your use. But for right now. I hope you are happy with what I'm providing you.
public void SelectedSheetsToPrint
(UIDocument uidoc, Document doc)
{
// Let's get the Sheets you Selected
Selection sel = uidoc.Selection;
ICollection ids = sel.GetElementIds();
FilteredElementCollector SSTP =
new FilteredElementCollector(doc, ids);
ElementClassFilter WantedElements =
new ElementClassFilter(typeof(ViewSheet));
SSTP.WherePasses(WantedElements);
List PrintElem =
SSTP.ToElements() as List;
ViewSet myViewSet = new ViewSet();
foreach (Element elements in PrintElem)
{
ViewSheet viewSheet = elements as ViewSheet;
myViewSet.Insert(viewSheet);
}
// 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 sheets selected");
return;
}
using (Transaction trans =
new Transaction(doc, "Create ViewSet"))
{
trans.Start();
// You can prompt the user to set their ViewSet name
string setName = "Jaime Test";
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 name
catch (Autodesk.Revit.Exceptions.
InvalidOperationException)
{
TaskDialog.Show("Error",
setName + " is already in use");
trans.RollBack();
return;
}
trans.Commit();
}
TaskDialog.Show("View Set", myViewSet.Size +
" sheets added to the Set and are ready to Print");
}
Please let me know how it goes, and once again thank you for your patience and collaboration.
By the way, the code could have been created by you, by checking some of the suggestions our forum contributors gave you and also checking RevitLookup tool.
Happy coding and enjoy :).
Response Developer: Dear Jaime Thanks a lot on this for your ton of support you provided, The solution works as we wanted.
Another happy customer and It was fun small project to work on.
Thank you for reading until next time.