Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.

Revit API Forum

Reply
Accepted Solution

printing set

675 Views, 14 Replies
10-07-2015 05:37 AM

Hi all,

 

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

 

Regards

Mohamed Shafeer Ahamed

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));
SSTP.WherePasses(WantedElements);
List<Element> PrintElem =
SSTP.ToElements() as List<Element>;
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, 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.

 

Cheers,

Post 2 of 15

Re: printing set

10-07-2015 06:00 AM in reply to: Mohamed.ShafeerAhamed
I hope this helps

http://www.revitzone.com/revit-fundamentals/179-sheet-sets
If I fully and clearly answered your question, please accept as the solution. Kudos well appreciated.

I am not an Autodesk Employee or an Autodesk Moderator.


Andrew Simon
Applications Engineer
AutoCAD Project X

Re: printing set

10-07-2015 07:22 AM in reply to: wisp

Dear wisp,

 

I want add view/sheet set from revit api.

 

Regards

mohamed shafeer ahamed

 

 

Post 4 of 15

Re: printing set

10-07-2015 12:04 PM in reply to: Mohamed.ShafeerAhamed
I apologize for the confusion. I'll try to find the appropriate answer.
If I fully and clearly answered your question, please accept as the solution. Kudos well appreciated.

I am not an Autodesk Employee or an Autodesk Moderator.


Andrew Simon
Applications Engineer
AutoCAD Project X

Re: printing set

10-07-2015 11:46 PM in reply to: wisp

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)
                {
                    newSelectedElementSet.Add(e);
                }
            }
            if (0 != newSelectedElementSet.Size)
            {
                TaskDialog.Show("revit", uidoc.Selection.Elements.Size.ToString() +
                        " sheets are selected!");
            }
            else
            {
                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.

 

Regards

Mohammed shafeer ahamed

Post 6 of 15

Re: printing set

10-08-2015 05:18 AM in reply to: Mohamed.ShafeerAhamed
This link sure looks interesting :)

https://boostyourbim.wordpress.com/2013/08/01/create-a-viewsheet-set/
If I fully and clearly answered your question, please accept as the solution. Kudos well appreciated.

I am not an Autodesk Employee or an Autodesk Moderator.


Andrew Simon
Applications Engineer
AutoCAD Project X

Re: printing set

10-08-2015 09:21 PM in reply to: wisp

Dear Wisp,

 

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

 

Regards

Shafeer

Post 8 of 15

Re: printing set

10-09-2015 04:04 AM 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.

 

 

Post 9 of 15

Re: printing set

10-09-2015 05:11 AM in reply to: Mendo123

Hi,

 

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.

 

 

Revitalizer


Don't forget to say 'thank you', it's just one click on the Kudos button.
Post 10 of 15

Re: printing set

10-09-2015 08:11 AM in reply to: Mohamed.ShafeerAhamed

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
Controller.setActiveSheet(Sheet)

If I fully and clearly answered your question, please accept as the solution. Kudos well appreciated.

I am not an Autodesk Employee or an Autodesk Moderator.


Andrew Simon
Applications Engineer
AutoCAD Project X
Post 11 of 15

Re: printing set

10-09-2015 09:26 AM in reply to: Mohamed.ShafeerAhamed

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. 

 

http://adndevblog.typepad.com/aec/2015/04/set-views-to-print-with-revitapi.html

http://thebuildingcoder.typepad.com/blog/2015/06/revit-2016-sp1-and-sheets-missing-from-print-dialog...

 

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

 

Cheers,



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

Re: printing set

10-11-2015 02:20 AM in reply to: rosalesduquej

Dear Jaime,

 

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

 

Regards

Shafeer

 

Post 13 of 15

Re: printing set

10-23-2015 11:22 AM in reply to: Mohamed.ShafeerAhamed

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));
            SSTP.WherePasses(WantedElements);
            List<Element> PrintElem = 
                SSTP.ToElements() as List<Element>;
            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, 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.

 

Cheers,



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

Re: printing set

10-25-2015 06:10 AM in reply to: rosalesduquej

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.

 

Regards

Mohamed Shafeer

Post 15 of 15

Re: printing set

10-26-2015 02:04 PM in reply to: Mohamed.ShafeerAhamed

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.

 

Cheers,



Jaime Rosales D.
Sr. Developer Consultant
Twitter | AEC ADN DevBlog
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post

Revit Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Revit helps you achieve greater speed, accuracy, and automation from concept to manufacturing.