Hi all,
How to add user selected sheet to printing set in revit api.
Regards
Mohamed Shafeer Ahamed
Solved! Go to Solution.
Solved by rosalesduquej. Go to Solution.
Dear wisp,
I want add view/sheet set from revit api.
Regards
mohamed shafeer ahamed
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
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
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.
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
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)
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
They might give you an idea to what you are tying to do.
Cheers,
Dear Jaime,
may be your not getting my point , please kindly go through the attached images for your clarity.
Regards
Shafeer
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,
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
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,
Can't find what you're looking for? Ask the community or share your knowledge.