Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

printing set

Message 1 of 15
4509 Views, 14 Replies

printing set

Hi all,


How to add user selected sheet to printing set in revit api.



Mohamed Shafeer Ahamed

Message 2 of 15

Message 3 of 15

Dear wisp,


I want add view/sheet set from revit api.



mohamed shafeer ahamed



Message 4 of 15

I apologize for the confusion. I'll try to find the appropriate answer.
Message 5 of 15

Hi all,


UIApplication uiapp = commandData.Application;
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Document doc = uidoc.Document;
            Autodesk.Revit.UI.Selection.SelElementSet collection = uidoc.Selection.Elements;
            TaskDialog.Show("revit", "Number of selected elements: " + collection.Size.ToString());
            SelElementSet newSelectedElementSet = SelElementSet.Create();
            ViewSet bimutils = new ViewSet();
            foreach (Element e in collection)
                if (e is ViewSheet)
            if (0 != newSelectedElementSet.Size)
                TaskDialog.Show("revit", uidoc.Selection.Elements.Size.ToString() +
                        " sheets are selected!");
                TaskDialog.Show("revit", "No sheets have been selected!");

            foreach (ViewSheet m in new FilteredElementCollector(doc).OfClass(typeof(ViewSheet)).Cast<ViewSheet>())

below code is for user selected element set,



Autodesk.Revit.UI.Selection.SelElementSet collection = uidoc.Selection.Elements;

SelElementSet newSelectedElementSet = SelElementSet.Create();


I want add  above element set to below code for avoid  adding all the sheet to printing set.


foreach (ViewSheet m in new FilteredElementCollector(doc).OfClass(typeof(ViewSheet)).Cast<ViewSheet>())


Expecting ans from api experts.



Mohammed shafeer ahamed

Message 6 of 15

Message 7 of 15

Dear Wisp,


That is usefull but that macro will add all the sheets to set.i want to add user selected sheet to set .




Message 8 of 15
in reply to: Mohamed.ShafeerAhamed


                ViewSet vwSet = new ViewSet(); 
vwSet.insert(****** View/viewsheet of our choice *****)

#region oldviewsheetsetting ViewSheetSetting newviewSheetSetting = printManager2.ViewSheetSetting; IViewSheetSet vsheetset = newviewSheetSetting.CurrentViewSheetSet; bool needToCreateNewSet = true; FilteredElementCollector filteredElementCollectorSets = new FilteredElementCollector(doc); filteredElementCollectorSets.OfClass(typeof(ViewSheetSet)); foreach (Element e in filteredElementCollectorSets) { if (e is ViewSheetSet) { ViewSheetSet vSet = (ViewSheetSet)e; if (vSet.Name == "CUSTOM VIEWSET") { vSet.Views = vwSet; newviewSheetSetting.CurrentViewSheetSet = vSet; vsheetset.Views = vSet.Views; try { newviewSheetSetting.Save(); } catch { } printManager2.Apply(); needToCreateNewSet = false; } } } if (needToCreateNewSet == true) { newviewSheetSetting.CurrentViewSheetSet.Views = vwSet; vsheetset.Views = vwSet; try { newviewSheetSetting.SaveAs("CUSTOM VIEWSET"); } catch { } printManager2.Apply(); needToCreateNewSet = false; } #endregion

This has always worked for me. just make sure you delete the viewsheetsetting before the end of the program. You will have to prompt the user to select a sheet somehow. have you tried creating a windows form with the sheet names? and then matching the name selected with the sheets in the doc should work.



Message 9 of 15
in reply to: Anonymous



I think that's the point:


"have you tried creating a windows form with the sheet names?"


In his code, he seems to mix both SelectionSet and FilteredElementCollector, manual and procedural selection.

The point is that if one wants to select abtract Elements, he needs to make them selectable otherwise.




Rudolf Honke
Software Developer
Mensch und Maschine

Message 10 of 15

document = ThisComponent  'assigns the current document to the variable document
Sheets = document.Sheets  'get the container of all Sheets
Sheet = Sheets.getByName("Sheet2")   'get the sheet named Sheet2
Controller = document.getcurrentController

Message 11 of 15

Hi Mohamed,


Please take a look at the 2 following posts in our Autodesk Revit API blogs, a quick simple google search found them for me.


They might give you an idea to what you are tying to do.



Jaime Rosales D.
Sr. Developer Consultant
Twitter | AEC ADN DevBlog
Message 12 of 15

Dear Jaime,


may be your not getting my point , please kindly go through the attached images for your clarity.





Message 13 of 15

Dear Mohamed, 


I replied to your colleague Vinay, but for others I'm posting a possible Solution here. You guys can be the judge of that 🙂 


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 your Sheets tree in the Project Browser. 


How to use it: Select 1 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<ElementId> ids = sel.GetElementIds();
            FilteredElementCollector SSTP = 
                new FilteredElementCollector(doc, ids);
            ElementClassFilter WantedElements = 
                new ElementClassFilter(typeof(ViewSheet));
            List<Element> PrintElem = 
                SSTP.ToElements() as List<Element>;
            ViewSet myViewSet = new ViewSet();

            foreach (Element elements in PrintElem)
                 ViewSheet viewSheet = elements as 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 = 

             // set the views in this ViewSheetSetting 
             // to the newly created ViewSet
             viewSheetSetting.CurrentViewSheetSet.Views = 

             if (myViewSet.Size == 0)
                 TaskDialog.Show("Error", "No sheets selected");

             using (Transaction trans = 
                 new Transaction(doc, "Create ViewSet"))
                 // You can prompt the user to set their ViewSet name
                 string setName = "Jaime Test";
                     // Save the current view sheet 
                     // set to another view/sheet 
                     // set with the specified name.
                 // handle the exception that will 
                 // occur if there is already a 
                 // view/sheet set with this name
                 catch (Autodesk.Revit.Exceptions.
                         setName + " is already in use");
             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, I used some of the suggestions our forum contributors gave you and also checking RevitLookup tool gave me the idea on how to put it together.



Jaime Rosales D.
Sr. Developer Consultant
Twitter | AEC ADN DevBlog
Message 14 of 15

Dear Jaime Rosales,


Thanks for your suport, i have done with your previous post its working perfectly with me but is there any posibilities to remove existing setname before is its save same name.



Mohamed Shafeer

Message 15 of 15

Glad to hear that it worked as you were expecting. For your other question I can suggest to take a look at the ViewSheetSet Class. There is a method DeleteEntity there that might help you with what you are looking for. 


This class is a sub-class of Element, so you can get the elementId of the ViewSheetSet that you wish to delete and then call the Document.Delete Method (ElementId) to get rid of it.



Jaime Rosales D.
Sr. Developer Consultant
Twitter | AEC ADN DevBlog

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Customer Advisory Groups

Rail Community