/// <summary> /// Finds all the views in the active document. /// </summary> /// <param name="doc">the active document</param> public static ViewSet GetAllViews (Document doc) { ViewSet allViews = new ViewSet(); FilteredElementCollector fec = new FilteredElementCollector(doc); ElementClassFilter elementsAreWanted = new ElementClassFilter(typeof(FloorType)); fec.WherePasses(elementsAreWanted); List<Element> elements = fec.ToElements() as List<Element>; foreach (Element element in elements) { Autodesk.Revit.DB.View view = element as Autodesk.Revit.DB.View; if (null == view) { continue; } else { ElementType objType = doc.GetElement(view.GetTypeId()) as ElementType; if (null == objType || objType.Name.Equals("Drawing Sheet")) { continue; } else { allViews.Insert(view); } } } return allViews; }
/// <summary> /// 获取文档下的所有视图 /// </summary> /// <param name="doc"></param> /// <returns></returns> public static ViewSet GetAllViews(Document doc) { ViewSet views = new ViewSet(); FilteredElementCollector collector = new FilteredElementCollector(doc); FilteredElementIterator it = collector.OfClass(typeof(View)).GetElementIterator(); it.Reset(); while (it.MoveNext()) { View view = it.Current as View3D; if (null != view && !view.IsTemplate && view.CanBePrinted) { views.Insert(view); } else if (null == view) { View view2D = it.Current as View; if (view2D.ViewType == ViewType.FloorPlan | view2D.ViewType == ViewType.CeilingPlan | view2D.ViewType == ViewType.AreaPlan | view2D.ViewType == ViewType.Elevation | view2D.ViewType == ViewType.Section) { views.Insert(view2D); } } } return(views); }
/// <summary> /// Collect the parameters and export /// </summary> /// <returns></returns> public override bool Export() { base.Export(); bool exported = false; //parameter : ViewSet views ViewSet views = new ViewSet(); if (m_currentViewOnly) { views.Insert(m_activeDoc.ActiveView); } else { views = m_selectViewsData.SelectedViews; } ICollection <ElementId> viewIds = new List <ElementId>(); foreach (View view in views) { viewIds.Add(view.Id); } //parameter : DXFExportOptions dxfExportOptions SATExportOptions satExportOptions = new SATExportOptions(); //Export exported = m_activeDoc.Export(m_exportFolder, m_exportFileName, viewIds, satExportOptions); return(exported); }
/// <summary> /// Get all printable views and sheets /// </summary> private void GetAllPrintableViews() { FilteredElementCollector collector = new FilteredElementCollector(m_commandData.Application.ActiveUIDocument.Document); FilteredElementIterator itor = collector.OfClass(typeof(View)).GetElementIterator(); itor.Reset(); m_printableViews.Clear(); m_printableSheets.Clear(); while (itor.MoveNext()) { View view = itor.Current as View; // skip view templates because they're invisible in project browser, invalid for print if (null == view || view.IsTemplate || !view.CanBePrinted) { continue; } else if (view.ViewType == Autodesk.Revit.DB.ViewType.DrawingSheet) { m_printableSheets.Insert(view); } else { m_printableViews.Insert(view); } } }
/// <summary> /// Finds all the views in the active document. /// </summary> /// <param name="doc">the active document</param> public static ViewSet GetAllViews(Document doc) { ViewSet allViews = new ViewSet(); FilteredElementCollector fec = new FilteredElementCollector(doc); ElementClassFilter elementsAreWanted = new ElementClassFilter(typeof(FloorType)); fec.WherePasses(elementsAreWanted); List <Element> elements = fec.ToElements() as List <Element>; foreach (Element element in elements) { Autodesk.Revit.DB.View view = element as Autodesk.Revit.DB.View; if (null == view) { continue; } else { ElementType objType = doc.GetElement(view.GetTypeId()) as ElementType; if (null == objType || objType.Name.Equals("Drawing Sheet")) { continue; } else { allViews.Insert(view); } } } return(allViews); }
GetAvailableViewsToExport(Document doc) { ViewSet viewSet = new ViewSet(); // TBD: using a filter iterator will only give you the base class View, not derived classes // like View3D or ViewDrafting. /*ElementFilterIterator viewIter = m_revitApp.ActiveUIDocument.Document.GetElements(typeof(Autodesk.Revit.DB.View)); * while (viewIter.MoveNext()) { * Autodesk.Revit.DB.View tmpView = (Autodesk.Revit.DB.View)viewIter.Current; * if (tmpView.CanBePrinted) * viewSet.Insert((Autodesk.Revit.DB.View)viewIter.Current); * }*/ FilteredElementCollector fec = new FilteredElementCollector(doc); ElementClassFilter elementsAreWanted = new ElementClassFilter(typeof(View)); fec.WherePasses(elementsAreWanted); List <Element> elements = fec.ToElements() as List <Element>; foreach (Element element in elements) { Autodesk.Revit.DB.View tmpView = element as Autodesk.Revit.DB.View; if ((tmpView != null) && tmpView.CanBePrinted) { viewSet.Insert(tmpView); } } return(viewSet); }
/// <summary> /// Collect the parameters and export /// </summary> /// <returns></returns> public override bool Export() { base.Export(); bool exported = false; //parameter : ViewSet views ViewSet views = new ViewSet(); if (m_currentViewOnly) { views.Insert(m_activeDoc.ActiveView); } else { views = m_selectViewsData.SelectedViews; } //parameter : DWGExportOptions dwgExportOptions DGNExportOptions dgnExportOptions = new DGNExportOptions(); dgnExportOptions.LayerMapping = m_exportLayerMapping; dgnExportOptions.TemplateFile = m_templateFile; //Export exported = m_activeDoc.Export(m_exportFolder, m_exportFileName, views, dgnExportOptions); return(exported); }
/// <summary> /// Retrieve the checked view from tree view. /// </summary> public void SelectViews() { ////Add the receivedCreatedViews to the set of views to be added to a sheet //foreach (Autodesk.Revit.DB.View v in receivedCreatedViews) //{ // m_selectedViews.Insert(v); //} ArrayList names = new ArrayList(); foreach (TreeNode t in AllViewsNames.Nodes) { foreach (TreeNode n in t.Nodes) { if (n.Checked && 0 == n.Nodes.Count) { names.Add(n.Text); } } } foreach (Autodesk.Revit.DB.View v in m_allViews) { foreach (string s in names) { if (s.Equals(v.Name)) { m_selectedViews.Insert(v); break; } } } }
/// <summary> /// Finds all the views in the active document. /// </summary> /// <param name="doc">the active document</param> private void GetAllViews(Document doc) { FilteredElementCollector collector = new FilteredElementCollector(doc); FilteredElementIterator itor = collector.OfClass(typeof(Autodesk.Revit.DB.View)).GetElementIterator(); itor.Reset(); while (itor.MoveNext()) { Autodesk.Revit.DB.View view = itor.Current as Autodesk.Revit.DB.View; // skip view templates because they're invisible in project browser if (null == view || view.IsTemplate) { continue; } else { ElementType objType = doc.GetElement(view.GetTypeId()) as ElementType; if (null == objType || objType.Name.Equals("Schedule") || objType.Name.Equals("Drawing Sheet")) { continue; } else { m_allViews.Insert(view); AssortViews(view.Name, objType.Name); } } } }
/// <summary> /// Collect the parameters and export /// </summary> /// <returns></returns> public override bool Export() { base.Export(); bool exported = false; //parameter : ViewSet views ViewSet views = new ViewSet(); if (m_currentViewOnly) { views.Insert(m_activeDoc.ActiveView); } else { views = m_selectViewsData.SelectedViews; } //parameter : DXFExportOptions dxfExportOptions SATExportOptions satExportOptions = new SATExportOptions(); //Export exported = m_activeDoc.Export(m_exportFolder, m_exportFileName, views, satExportOptions); return(exported); }
/// <summary> /// Retrieve the checked view from tree view. /// </summary> public void SelectViews() { ArrayList names = new ArrayList(); foreach (TreeNode t in AllViewsNames.Nodes) { foreach (TreeNode n in t.Nodes) { if (n.Checked && 0 == n.Nodes.Count) { names.Add(n.Text); } } } foreach (Autodesk.Revit.DB.View v in m_allViews) { foreach (string s in names) { if (s.Equals(v.Name)) { m_selectedViews.Insert(v); break; } } } }
Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; //Reference r; //ElementInLinkSelectionFilter<View> filter = new ElementInLinkSelectionFilter<View>(doc); //r = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.PointOnElement); //Element e = doc.GetElement(r); ICollection <ElementId> elt = uidoc.Selection.GetElementIds(); ViewSheet a, b; //ViewSet b=new ViewSet(); /* * foreach (ElementId i in elt) * { * b.Insert(doc.GetElement(i) as ViewSheet); * } * DWFXExportOptions options = new DWFXExportOptions(); * options.MergedViews = true; * String dir = doc.PathName.Substring(0, doc.PathName.Length - doc.Title.Length - 4); */ using (Transaction tr = new Transaction(doc, "SheetNumberChanging")) { tr.Start(); StringBuilder info = new StringBuilder(); ViewSet sheets = new ViewSet(); foreach (ElementId t in elt) { ViewSheet sheet = doc.GetElement(t) as ViewSheet; sheets.Insert(sheet); } List <ViewSheet> mySheets = elt.Select(x => doc.GetElement(x) as ViewSheet).ToList(); List <ViewSheet> sortedElements = mySheets.OrderBy(x => x.SheetNumber).ToList(); a = sortedElements.ElementAt(0); b = sortedElements.ElementAt(1); string firstSheet = a.get_Parameter(BuiltInParameter.SHEET_NUMBER).AsString(); string secondSheet = b.get_Parameter(BuiltInParameter.SHEET_NUMBER).AsString(); a.get_Parameter(BuiltInParameter.SHEET_NUMBER).Set("-99"); b.get_Parameter(BuiltInParameter.SHEET_NUMBER).Set(firstSheet); a.get_Parameter(BuiltInParameter.SHEET_NUMBER).Set(secondSheet); //doc.Export(dir, "MyExportBitch"+b.Size.ToString(), b, options); tr.Commit(); } return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; try { PrintManager pm = doc.PrintManager; Selection selection = uidoc.Selection; ICollection <ElementId> ids = selection.GetElementIds(); FilteredElementCollector collector = new FilteredElementCollector(doc, ids); ElementClassFilter wantedElements = new ElementClassFilter(typeof(ViewSheet)); collector.WherePasses(wantedElements); List <Element> printElems = collector.ToElements() as List <Element>; ViewSet viewSet = new ViewSet(); foreach (Element e in printElems) { ViewSheet viewSheet = e as ViewSheet; viewSet.Insert(viewSheet); } pm.SelectNewPrintDriver("Microsoft Print to PDF"); pm.PrintRange = PrintRange.Select; ViewSheetSetting vss = pm.ViewSheetSetting; vss.CurrentViewSheetSet.Views = viewSet; using (Transaction trans = new Transaction(doc, "Print ViewSet")) { trans.Start(); string setName = "Temp"; vss.SaveAs(setName); pm.PrintSetup.CurrentPrintSetting.PrintParameters.PageOrientation = PageOrientationType.Landscape; pm.PrintSetup.CurrentPrintSetting.PrintParameters.PaperPlacement = PaperPlacementType.Center; pm.PrintSetup.CurrentPrintSetting.PrintParameters.ZoomType = ZoomType.Zoom; pm.PrintSetup.CurrentPrintSetting.PrintParameters.Zoom = 100; // pm.Apply(); //pm.PrintSetup.Save(); pm.CombinedFile = true; pm.SubmitPrint(); //vss.Delete(); trans.Commit(); } return(Result.Succeeded); } catch (Exception e) { message = e.Message; return(Result.Failed); } }
/// <summary> /// export a 3d view in a document to a fbx file /// </summary> /// <param name="doc">The model document</param> /// <param name="view">The 3D view will be exported</param> /// <param name="folder">result file container folder</param> /// <param name="fileName">result file without extension</param> /// <returns>true if success, false otherwise</returns> public static bool Export(Document doc, View3D view, string folder, string fileName) { try { ViewSet set = new ViewSet(); set.Insert(view); return(doc.Export(folder, fileName, set, new FBXExportOptions())); } catch (Exception) { return(false); } }
SetSelectViewsFromNames(ArrayList viewNames) { foreach (Autodesk.Revit.DB.View v in m_allViews) { foreach (string s in viewNames) { if (s.Equals(v.Name)) { m_selectedViews.Insert(v); break; } } } }
/// <summary> /// Export FBX format /// </summary> /// <returns></returns> public override bool Export() { base.Export(); bool exported = false; //parameter : ViewSet views ViewSet views = new ViewSet(); views.Insert(m_activeDoc.ActiveView); FBXExportOptions options = new FBXExportOptions(); exported = m_activeDoc.Export(m_exportFolder, m_exportFileName, views, options); return exported; }
private void PrintViewSheet(ViewSheet viewSheet, string sheetSize, PrintSetting printSetting, string filePath) { // creates view set ViewSet viewSet = new ViewSet(); viewSet.Insert(viewSheet); PrintManager printManager = this.Doc.PrintManager; printManager.PrintRange = PrintRange.Select; printManager.Apply(); // make new view set current ViewSheetSetting viewSheetSetting = printManager.ViewSheetSetting; viewSheetSetting.CurrentViewSheetSet.Views = viewSet; // set printer printManager.SelectNewPrintDriver(this._PrinterName); printManager.Apply(); // set file path printManager.CombinedFile = true; printManager.PrintToFileName = filePath; printManager.Apply(); // set print setting this.Transaction.Start(); PrintSetup printSetup = printManager.PrintSetup; printSetup.CurrentPrintSetting = printSetting; printManager.Apply(); this.Transaction.Commit(); List<Element> viewSets = new List<Element>(new FilteredElementCollector(this.Doc) .OfClass(typeof(ViewSheetSet)) .ToElements()); foreach (Element element in viewSets) { if (element.Name == "tempSetName") { this.Transaction.Start(); this.Doc.Delete(element.Id); this.Transaction.Commit(); } } // save settings and submit print this.Transaction.Start(); viewSheetSetting.SaveAs("tempSetName"); printManager.Apply(); printManager.SubmitPrint(); viewSheetSetting.Delete(); this.Transaction.Commit(); }
public IExternalCommand.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Document curDoc = commandData.Application.ActiveDocument; DWF2DExportOptions options = new DWF2DExportOptions(); ViewSet viewSet = new ViewSet(); viewSet.Insert(curDoc.ActiveView); if (curDoc.Export("C:\\", "abc.dwf", viewSet, options) == false) { message = "Export current view to DWF file failed."; return IExternalCommand.Result.Failed; } return IExternalCommand.Result.Succeeded; }
private void exportFBX() { /* https://forums.autodesk.com/t5/revit-api-forum/how-to-export-with-all-categories-of-3d-view-of-rvt-file-to-fbx/m-p/7112555 * UIApplication uiApp = commandData.Application; * Document doc = uiApp.ActiveUIDocument.Document; * * ViewSet viewSet = new ViewSet(); * viewSet.Insert(doc.ActiveViewSet); * doc.Export("C:/......PATH......", "nameFBXExportedFile", viewSet, new FBXExportOptions()); */ ViewSet viewSet = new ViewSet(); viewSet.Insert(view); dbdoc.Export("f:/revit/temp", "lesson2.fbx", viewSet, new FBXExportOptions()); }
/// <summary> /// Generate sheet in active document. /// </summary> /// <param name="doc">the currently active document</param> public void GenerateSheet(Document doc, Autodesk.Revit.DB.View m_selectedView) { if (null == doc) { throw new ArgumentNullException("doc"); } ViewSheet sheet = ViewSheet.Create(doc, m_TitleBlocks.Id); ViewSet m_selectedViews = new ViewSet(); sheet.Name = get_str(); m_selectedViews.Insert(m_selectedView); PlaceViews(m_selectedViews, sheet); }
/// <summary> /// Export FBX format /// </summary> /// <returns></returns> public override bool Export() { base.Export(); bool exported = false; //parameter : ViewSet views ViewSet views = new ViewSet(); views.Insert(m_activeDoc.ActiveView); FBXExportOptions options = new FBXExportOptions(); exported = m_activeDoc.Export(m_exportFolder, m_exportFileName, views, options); return(exported); }
/// <summary> /// Collect the parameters and export /// </summary> /// <returns></returns> public override bool Export() { Transaction transaction = new Transaction(m_activeDoc, "Export_To_DWF"); transaction.Start(); bool exported = false; base.Export(); //parameter : ViewSet views ViewSet views = new ViewSet(); if (m_currentViewOnly) { views.Insert(m_activeDoc.ActiveView); } else { views = m_selectViewsData.SelectedViews; } // Export DWFx if (m_exportFormat == ExportFormat.DWFx) { DWFXExportOptions options = new DWFXExportOptions(); options.ExportObjectData = m_exportObjectData; options.ExportingAreas = m_exportAreas; options.MergedViews = m_exportMergeFiles; options.ImageFormat = m_dwfImageFormat; options.ImageQuality = m_dwfImageQuality; exported = m_activeDoc.Export(m_exportFolder, m_exportFileName, views, options); } // Export DWF else { DWFExportOptions options = new DWFExportOptions(); options.ExportObjectData = m_exportObjectData; options.ExportingAreas = m_exportAreas; options.MergedViews = m_exportMergeFiles; options.ImageFormat = m_dwfImageFormat; options.ImageQuality = m_dwfImageQuality; exported = m_activeDoc.Export(m_exportFolder, m_exportFileName, views, options); } transaction.Commit(); return(exported); }
/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) { // Filter all printable views in current document and print them, // the print will raise events registered in controlled application. // After run this external command please refer to log files under folder of this assembly. Document document = commandData.Application.ActiveUIDocument.Document; try { List <Autodesk.Revit.DB.Element> viewElems = new List <Autodesk.Revit.DB.Element>(); FilteredElementCollector collector = new FilteredElementCollector(document); viewElems.AddRange(collector.OfClass(typeof(View)).ToElements()); // // Filter all printable views ViewSet printableViews = new ViewSet(); foreach (View view in viewElems) { // skip view templates because they're invalid for print if (!view.IsTemplate && view.CanBePrinted) { printableViews.Insert(view); } } // // Print to file to folder of assembly String assemblyPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); PrintManager pm = document.PrintManager; pm.PrintToFile = true; pm.PrintToFileName = assemblyPath + "\\PrintOut.prn"; pm.Apply(); // // Print views now to raise events: document.Print(printableViews); } catch (Exception ex) { message = ex.Message; return(Autodesk.Revit.UI.Result.Failed); } // // return succeed by default return(Autodesk.Revit.UI.Result.Succeeded); }
/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) { // Filter all printable views in current document and print them, // the print will raise events registered in controlled application. // After run this external command please refer to log files under folder of this assembly. Document document = commandData.Application.ActiveUIDocument.Document; try { List<Autodesk.Revit.DB.Element> viewElems = new List<Autodesk.Revit.DB.Element>(); FilteredElementCollector collector = new FilteredElementCollector(document); viewElems.AddRange(collector.OfClass(typeof(View)).ToElements()); // // Filter all printable views ViewSet printableViews = new ViewSet(); foreach (View view in viewElems) { // skip view templates because they're invalid for print if (!view.IsTemplate && view.CanBePrinted) { printableViews.Insert(view); } } // // Print to file to folder of assembly String assemblyPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); PrintManager pm = document.PrintManager; pm.PrintToFile = true; pm.PrintToFileName = assemblyPath + "\\PrintOut.prn"; pm.Apply(); // // Print views now to raise events: document.Print(printableViews); } catch(Exception ex) { message = ex.Message; return Autodesk.Revit.UI.Result.Failed; } // // return succeed by default return Autodesk.Revit.UI.Result.Succeeded; }
//load all views and return them in a viewset. skips all templates, use GetAllViewTemplates for this public ViewSet GetAllViews() { //find all views IEnumerable <View> views = new FilteredElementCollector(doc) .OfClass(typeof(View)) .Cast <View>() .Where(b => !b.IsTemplate && b.ViewType != ViewType.DrawingSheet); //add all the views into a ViewSet ViewSet allViews = new ViewSet(); foreach (View v in views) { allViews.Insert(v); } //return the ViewSet return(allViews); }
public void ChangeCurrentViewSheetSet(List <string> names) { ViewSet selectedViews = new ViewSet(); if (null != names && 0 < names.Count) { foreach (Autodesk.Revit.DB.View view in m_viewSheetSetting.AvailableViews) { if (names.Contains(view.ViewType.ToString() + ": " + view.ViewName)) { selectedViews.Insert(view); } } } IViewSheetSet viewSheetSet = m_viewSheetSetting.CurrentViewSheetSet; viewSheetSet.Views = selectedViews; Save(); }
ExportTo3dDwf() { // get output dir to save DWFs to System.Windows.Forms.FolderBrowserDialog dbox = new System.Windows.Forms.FolderBrowserDialog(); dbox.Description = "Folder to save exported DWF files to"; dbox.ShowNewFolderButton = true; try { if (dbox.ShowDialog() == DialogResult.OK) { ViewSet viewsToExport = Utils.View.GetAvailableViewsToExport(m_revitApp.ActiveUIDocument.Document); /// filter out only 3d views ViewSet views3dToExport = new ViewSet(); foreach (Autodesk.Revit.DB.View view in viewsToExport) { if (view.ViewType == ViewType.ThreeD) { views3dToExport.Insert(view); } } if (views3dToExport.Size == 0) { throw new Exception("No files exported. Make sure you have atleast one 3d view."); } DWFExportOptions opts = new DWFExportOptions(); /// export now m_revitApp.ActiveUIDocument.Document.Export(dbox.SelectedPath, "", views3dToExport, opts); /// feedback to user MessageBox.Show("Done exporting to 3d Dwf!!"); } } catch (Exception e) { MessageBox.Show(e.Message); } }
/// <summary> /// print the specified ViewType. /// </summary> public void Print(ViewType viewType) { try { Autodesk.Revit.DB.View view = null; // Create a view set to contain all view of designated type ViewSet views = m_doc.Application.Create.NewViewSet(); // Create a filter to filtrate the View Element. ElementClassFilter fileterView = new ElementClassFilter(typeof(VIEW)); FilteredElementCollector collector = new FilteredElementCollector(m_doc); collector.WherePasses(fileterView); IList <Element> arrayView = collector.ToElements(); // filtrate the designated type views. foreach (Element ee in arrayView) { view = ee as VIEW; if ((null != view) && (viewType == view.ViewType) && view.IsTemplate == false) { views.Insert(view); } } // print if (!views.IsEmpty) { m_doc.Print(views); } else { MessageBox.Show("No " + viewType.ToString() + " view to be printed!", "QuickPrint"); } } catch (Exception ee) { MessageBox.Show(ee.Message); } }
public Result RunRemotely(Document document) { FilteredElementCollector collector = new FilteredElementCollector(document); collector.OfClass(typeof(ViewSheet)); ViewSet set = new ViewSet(); foreach (View view in collector) { set.Insert(view); } DWFXExportOptions options = new DWFXExportOptions(); options.MergedViews = true; options.ImageQuality = DWFImageQuality.High; options.ExportObjectData = true; document.Export(@"C:\RRBTest\", "TestExport.dwfx", set, options); return(Result.Succeeded); }
GetAvailableViewsToExport (Document doc) { ViewSet viewSet = new ViewSet(); // TBD: using a filter iterator will only give you the base class View, not derived classes // like View3D or ViewDrafting. /*ElementFilterIterator viewIter = m_revitApp.ActiveUIDocument.Document.GetElements(typeof(Autodesk.Revit.DB.View)); while (viewIter.MoveNext()) { Autodesk.Revit.DB.View tmpView = (Autodesk.Revit.DB.View)viewIter.Current; if (tmpView.CanBePrinted) viewSet.Insert((Autodesk.Revit.DB.View)viewIter.Current); }*/ FilteredElementCollector fec = new FilteredElementCollector(doc); ElementClassFilter elementsAreWanted = new ElementClassFilter(typeof(View)); fec.WherePasses(elementsAreWanted); List<Element> elements = fec.ToElements() as List<Element>; foreach (Element element in elements) { Autodesk.Revit.DB.View tmpView = element as Autodesk.Revit.DB.View; if ((tmpView != null) && tmpView.CanBePrinted) { viewSet.Insert(tmpView); } } return viewSet; }
/// <summary> /// Get all the views to be displayed /// </summary> private void GetViews() { FilteredElementCollector collector = new FilteredElementCollector(m_activeDoc); FilteredElementIterator itor = collector.OfClass(typeof(View)).GetElementIterator(); itor.Reset(); ViewSet views = new ViewSet(); ViewSet floorPlans = new ViewSet(); ViewSet ceilingPlans = new ViewSet(); ViewSet engineeringPlans = new ViewSet(); while (itor.MoveNext()) { View view = itor.Current as View; // skip view templates because they're invalid for import/export if (view == null || view.IsTemplate) { continue; } else if (view.ViewType == Autodesk.Revit.DB.ViewType.FloorPlan) { floorPlans.Insert(view); } else if (view.ViewType == Autodesk.Revit.DB.ViewType.CeilingPlan) { ceilingPlans.Insert(view); } else if (view.ViewType == Autodesk.Revit.DB.ViewType.EngineeringPlan) { engineeringPlans.Insert(view); } } foreach (View floorPlan in floorPlans) { foreach (View ceilingPlan in ceilingPlans) { if (floorPlan.Name == ceilingPlan.Name) { views.Insert(floorPlan); } } } foreach (View engineeringPlan in engineeringPlans) { if (engineeringPlan.Name == engineeringPlan.GenLevel.Name) { views.Insert(engineeringPlan); } } View activeView = m_activeDoc.ActiveView; Autodesk.Revit.DB.ViewType viewType = activeView.ViewType; if (viewType == Autodesk.Revit.DB.ViewType.FloorPlan || viewType == Autodesk.Revit.DB.ViewType.CeilingPlan) { m_views.Insert(activeView); foreach (View view in views) { if (view.GenLevel.Elevation < activeView.GenLevel.Elevation) { m_views.Insert(view); } } } else if (viewType == Autodesk.Revit.DB.ViewType.EngineeringPlan) { if (views.Contains(activeView)) { m_views.Insert(activeView); } foreach (View view in views) { if (view.GenLevel.Elevation < activeView.GenLevel.Elevation) { m_views.Insert(view); } } } else//Get view of the lowest elevation { int i = 0; double elevation = 0; View viewLowestElevation = null; foreach (View view in views) { if (i == 0) { elevation = view.GenLevel.Elevation; viewLowestElevation = view; } else { if (view.GenLevel.Elevation <= elevation) { elevation = view.GenLevel.Elevation; viewLowestElevation = view; } } i++; } m_views.Insert(viewLowestElevation); } }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Autodesk.Revit.ApplicationServices.Application app = uiapp.Application; Document doc = uidoc.Document; ElementId eId = new ElementId(-2003100); //Collect Schedules from active document foreach (ViewSchedule vSched in new FilteredElementCollector(doc) .OfClass(typeof(ViewSchedule)) .Cast<ViewSchedule>() .Where(q => !q.IsTitleblockRevisionSchedule && !q.IsInternalKeynoteSchedule)) { if (vSched.Definition.CategoryId == eId) { nameSchedule.Add(vSched.Name); } } //Instantiate Form MainWindow mWindow = new MainWindow(); mWindow.ShowDialog(); //Error handling if(dialogResult == false) { GarbageCollect(); return Result.Failed; } if(MainWindow.selectedName == null) { TaskDialog.Show("Error", "No schedule was selected!"); GarbageCollect(); return Result.Failed; } //get ElementId of selected schedule var viewId = doc.ActiveView.Id; foreach (ViewSchedule vSched2 in new FilteredElementCollector(doc) .OfClass(typeof(ViewSchedule)) .Cast<ViewSchedule>() .Where(q => !q.IsTitleblockRevisionSchedule && !q.IsInternalKeynoteSchedule)) { if (vSched2.Name == MainWindow.selectedName) { viewId = vSched2.Id; } } //Get sheets from selected schedule, catch error for invalid schedules ViewSet vs = new ViewSet(); try { foreach (ViewSheet vSh in new FilteredElementCollector(doc, viewId)) { //Ignore dummy sheets if(vSh.CanBePrinted == true) { vs.Insert(vSh); } } } catch (System.InvalidCastException) { TaskDialog.Show("Error","Cannot use '" + MainWindow.selectedName + "'" + Environment.NewLine + "'" + MainWindow.selectedName + "' is not a sheet index."); GarbageCollect(); return Result.Failed; } // Save ViewSet with sheets from selected schedule using provided name using (Transaction tx = new Transaction(doc)) { tx.Start("SaveSet"); PrintManager printManager = doc.PrintManager; printManager.PrintRange = PrintRange.Select; ViewSheetSetting viewSheetSetting = printManager.ViewSheetSetting; viewSheetSetting.CurrentViewSheetSet.Views = vs; try { viewSheetSetting.SaveAs(MainWindow.setName); } catch (Autodesk.Revit.Exceptions.InvalidOperationException) { TaskDialog.Show("Error", "The name '" + MainWindow.setName + "' is already in use!" + Environment.NewLine + "Pick a different name."); GarbageCollect(); return Result.Failed; } tx.Commit(); } TaskDialog.Show("View Set", vs.Size + " sheets added to '" + MainWindow.setName + "'"); GarbageCollect(); return Result.Succeeded; }
private bool ExportFBX(DesignAutomationData data) { if (data == null) { return(false); } Application app = data.RevitApp; if (app == null) { return(false); } string modelPath = data.FilePath; if (string.IsNullOrWhiteSpace(modelPath)) { return(false); } var doc = data.RevitDoc; if (doc == null) { return(false); } using (var collector = new FilteredElementCollector(doc)) { LogTrace("Collecting 3D views..."); var exportPath = Path.Combine(Directory.GetCurrentDirectory(), "exported"); if (!Directory.Exists(exportPath)) { try { Directory.CreateDirectory(exportPath); } catch (Exception ex) { this.PrintError(ex); return(false); } } LogTrace(string.Format("Export Path: {0}", exportPath)); var veiwIds = collector.WhereElementIsNotElementType() .OfClass(typeof(View3D)) .WhereElementIsNotElementType() .Cast <View3D>() .Where(v => !v.IsTemplate) .Select(v => v.Id); if (veiwIds == null || veiwIds.Count() <= 0) { LogTrace("No 3D views to be exported..."); return(false); } LogTrace("Starting the export task..."); try { foreach (var viewId in veiwIds) { var exportOpts = new FBXExportOptions(); exportOpts.StopOnError = true; exportOpts.WithoutBoundaryEdges = true; var view = doc.GetElement(viewId) as View3D; var name = view.Name; name = name.Replace("{", "_").Replace("}", "_").ReplaceInvalidFileNameChars(); var filename = string.Format("{0}.fbx", name); LogTrace(string.Format("Exporting {0}...", filename)); var viewSet = new ViewSet(); viewSet.Insert(view); doc.Export(exportPath, filename, viewSet, exportOpts); } } catch (Autodesk.Revit.Exceptions.InvalidPathArgumentException ex) { this.PrintError(ex); return(false); } catch (Autodesk.Revit.Exceptions.ArgumentException ex) { this.PrintError(ex); return(false); } catch (Autodesk.Revit.Exceptions.InvalidOperationException ex) { this.PrintError(ex); return(false); } catch (Exception ex) { this.PrintError(ex); return(false); } } return(true); }
/// <summary> /// Collect the parameters and export /// </summary> /// <returns></returns> public override bool Export() { Transaction transaction = new Transaction(m_activeDoc, "Export_To_DWF"); transaction.Start(); bool exported = false; base.Export(); //parameter : ViewSet views ViewSet views = new ViewSet(); if (m_currentViewOnly) { views.Insert(m_activeDoc.ActiveView); } else { views = m_selectViewsData.SelectedViews; } // Export DWFx if (m_exportFormat == ExportFormat.DWFx) { DWFXExportOptions options = new DWFXExportOptions(); options.ExportObjectData = m_exportObjectData; options.ExportingAreas = m_exportAreas; options.MergedViews = m_exportMergeFiles; options.ImageFormat = m_dwfImageFormat; options.ImageQuality = m_dwfImageQuality; exported = m_activeDoc.Export(m_exportFolder, m_exportFileName, views, options); } // Export DWF else { DWFExportOptions options = new DWFExportOptions(); options.ExportObjectData = m_exportObjectData; options.ExportingAreas = m_exportAreas; options.MergedViews = m_exportMergeFiles; options.ImageFormat = m_dwfImageFormat; options.ImageQuality = m_dwfImageQuality; exported = m_activeDoc.Export(m_exportFolder, m_exportFileName, views, options); } transaction.Commit(); return exported; }
public void ChangeCurrentViewSheetSet(List<string> names) { ViewSet selectedViews = new ViewSet(); if (null != names && 0 < names.Count) { foreach (Autodesk.Revit.DB.View view in m_viewSheetSetting.AvailableViews) { if (names.Contains(view.ViewType.ToString() + ": " + view.ViewName)) { selectedViews.Insert(view); } } } IViewSheetSet viewSheetSet = m_viewSheetSetting.CurrentViewSheetSet; viewSheetSet.Views = selectedViews; Save(); }
private string ExportToFbx() { try { double building_width = 0; double building_length = 0; ElementCategoryFilter eleFilter;//the class varies from Autodesk.Revit.DB? y FilteredElementCollector collector;//the class varies from Autodesk.Revit.DB? y IList<Element> filteredObject;// the interface of System.Collections.Generic? y where did it state it is the interface? in .net lib string semanticInfo = "";//store all semantic information string commentParameter = "";//store the comment parameter in left column revit //get ground objects //read semantic information from revit file //for floor eleFilter = new ElementCategoryFilter(BuiltInCategory.OST_Floors);// get all floor objects in revit project collector = new FilteredElementCollector(uidoc.Document);//the same way to get objects in revit filteredObject = collector.WherePasses(eleFilter).WhereElementIsNotElementType().ToElements();// the same way to get objects in revit //we create filter instance and all objects instance. then we pass filter into all objects to get filteredbojects. foreach (Element e in filteredObject)//go throught each item/objects in revit model { commentParameter = GetParameterInformation(e.Parameters, uidoc.Document, "Comments"); string level = GetParameterInformation(e.Parameters, uidoc.Document, "Level"); if (level.ToLower() == "level 0") { CalculateArea(e.Parameters, uidoc.Document, ref building_width, ref building_length); if (building_width > 100 || building_length > 100) { TaskDialog.Show("Error", "W: " + building_width + ", L: " + building_length + ". Size is too big for our application."); return "Size Error."; } } if (commentParameter == "emergency") semanticInfo += e.Id + "-emergency,"+level+"\n";// explain this please. put id and emergency into the whole semantic information list with different line. else semanticInfo += e.Id + "-ground," + level + "\n"; } //for stairs eleFilter = new ElementCategoryFilter(BuiltInCategory.OST_Stairs); collector = new FilteredElementCollector(uidoc.Document); filteredObject = collector.WherePasses(eleFilter).WhereElementIsNotElementType().ToElements(); foreach (Element e in filteredObject) { semanticInfo += e.Id + "-stair\n"; } //get obstacle objects///for walls eleFilter = new ElementCategoryFilter(BuiltInCategory.OST_Walls);//I get all walls collector = new FilteredElementCollector(uidoc.Document); filteredObject = collector.WherePasses(eleFilter).WhereElementIsNotElementType().ToElements(); foreach (Element e in filteredObject)//I loop each wall. I want to check the COMMENT property of each wall { /*//this block is used to get Comment property in revit commentParameter = "";//this parameter store Comment property value foreach (Parameter para in e.Parameters)//loop each property { try { commentParameter = GetParameterInformation(para, uidoc.Document).ToLower(); if (commentParameter == "wood") break; } catch (Exception ex) { //cannot get info, we know it and we don't need to write it } } //if it is wood, we set wood to the semantic file, otherwise it is obstable (brick) if (commentParameter == "wood") semanticInfo += e.Id + "-wood\n"; //else if (status == "somethingelse") //content += e.Id + "-somethingelse\n"; else*/ semanticInfo += e.Id + "-obstacle\n"; } //for doors eleFilter = new ElementCategoryFilter(BuiltInCategory.OST_Doors); collector = new FilteredElementCollector(uidoc.Document); filteredObject = collector.WherePasses(eleFilter).WhereElementIsNotElementType().ToElements(); foreach (Element e in filteredObject) { commentParameter = GetParameterInformation(e.Parameters, uidoc.Document, "Comments"); if (commentParameter == "closed") semanticInfo += e.Id + "-obstacle\n"; else if (commentParameter == "opened") semanticInfo += e.Id + "-openeddoor\n"; else semanticInfo += e.Id + "-openeddoor\n"; // else mean the default status??? yes SetParameter(e.Parameters, "Comments", "test"); } string path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); CreateTempFolder(path + "\\revitfbx\\"); //output //System.IO.Directory.CreateDirectory("revitfbx"); System.IO.File.Delete(path + "\\revitfbx\\building.fbx"); System.IO.File.Delete(path + "\\revitfbx\\semantic.txt"); //we write new fbx //////////////////////////// ViewSet views = new ViewSet(); views.Insert(uidoc.ActiveView); FBXExportOptions exportoption = new FBXExportOptions(); //here, revit forces us to use a folder. I forgot that. so we have to use a folder. uidoc.Document.Export(path + "\\revitfbx", "building.fbx", views, exportoption);//generate fbx file ///////////////////////////// //we write new semantic Utility.WriteFile(path + "\\revitfbx\\semantic.txt", semanticInfo, false); //send semantic and 3d fbx model to PHP server NameValueCollection paras = new NameValueCollection(); paras.Add("sid", selectedSid); paras.Add("act", "ClientSendModelFile"); string web = client.UploadFileEx(path + "\\revitfbx\\building.fbx", AppConst.SERVER_DOMAIN + AppConst.SERVER_PATH, "building", null, paras); if (web.Trim() != "") return "Unknown error"; paras = new NameValueCollection(); paras.Add("sid", selectedSid); paras.Add("act", "ClientSendSemanticFile"); client.UploadFileEx(path + "\\revitfbx\\semantic.txt", AppConst.SERVER_DOMAIN + AppConst.SERVER_PATH, "semantic", null, paras); return "done"; } /////////////////////////// catch (Exception ex) { TaskDialog.Show("Error", ex.Message); return ex.Message; } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; Selection selection = uidoc.Selection; PrintManager pm = doc.PrintManager; pm.PrintRange = PrintRange.Select; ViewSheetSetting vss = pm.ViewSheetSetting; ICollection <ElementId> id; FilteredElementCollector collector; ElementClassFilter wantedElements; PaperSizeSet paperSize = pm.PaperSizes; List <Element> printElemes = null; using (Transaction trans = new Transaction(doc, "Print ViewSet")) { try { id = selection.GetElementIds(); collector = new FilteredElementCollector(doc, id); wantedElements = new ElementClassFilter(typeof(ViewSheet)); collector.WherePasses(wantedElements); printElemes = collector.ToElements() as List <Element>; } catch (Autodesk.Revit.Exceptions.ApplicationException e) { TaskDialog.Show("Error!", e.Message); return(Result.Cancelled); } catch (Exception e) { TaskDialog.Show("Error!", e.Message); } ViewSet viewSet = new ViewSet(); foreach (var elem in printElemes) { ViewSheet viewSheet = elem as ViewSheet; viewSet.Insert(viewSheet); } trans.Start(); try { vss.CurrentViewSheetSet.Views = viewSet; vss.Save(); pm.SelectNewPrintDriver("Microsoft Print to PDF"); pm.Apply(); //pm.PrintSetup.Save(); pm.PrintSetup.CurrentPrintSetting.PrintParameters.PageOrientation = PageOrientationType.Landscape; pm.PrintSetup.CurrentPrintSetting.PrintParameters.PaperPlacement = PaperPlacementType.Center; pm.PrintSetup.CurrentPrintSetting.PrintParameters.ZoomType = ZoomType.Zoom; pm.PrintSetup.CurrentPrintSetting.PrintParameters.Zoom = 100; pm.CombinedFile = true; //pm.PrintToFile = true; //pm.PrintToFileName = @"C:\Users\Lenovo\Desktop\file.pdf"; pm.Apply(); //pm.PrintSetup.Save(); pm.SubmitPrint(); } catch (Exception e) { message = e.Message; return(Result.Failed); } trans.Commit(); // return Result.Succeeded; } return(Result.Succeeded); }
public void ExportTo3dDwf() { // get output dir to save DWFs to System.Windows.Forms.FolderBrowserDialog dbox = new System.Windows.Forms.FolderBrowserDialog(); dbox.Description = "Folder to save exported DWF files to"; dbox.ShowNewFolderButton = true; try { if (dbox.ShowDialog() == DialogResult.OK) { ViewSet viewsToExport = Utils.View.GetAvailableViewsToExport(m_revitApp.ActiveUIDocument.Document); /// filter out only 3d views ViewSet views3dToExport = new ViewSet(); foreach (Autodesk.Revit.DB.View view in viewsToExport) { if (view.ViewType == ViewType.ThreeD) { views3dToExport.Insert(view); } } if (views3dToExport.Size == 0) throw new Exception("No files exported. Make sure you have atleast one 3d view."); DWFExportOptions opts = new DWFExportOptions(); /// export now m_revitApp.ActiveUIDocument.Document.Export(dbox.SelectedPath, "", views3dToExport, opts); /// feedback to user MessageBox.Show("Done exporting to 3d Dwf!!"); } } catch (Exception e) { MessageBox.Show(e.Message); } }
/// <summary> /// Get all the views to be displayed /// </summary> private void GetViews() { FilteredElementCollector collector = new FilteredElementCollector(m_activeDoc); FilteredElementIterator itor = collector.OfClass(typeof(View)).GetElementIterator(); itor.Reset(); ViewSet views = new ViewSet(); ViewSet floorPlans = new ViewSet(); ViewSet ceilingPlans = new ViewSet(); ViewSet engineeringPlans = new ViewSet(); while (itor.MoveNext()) { View view = itor.Current as View; // skip view templates because they're invalid for import/export if (view == null || view.IsTemplate) { continue; } else if (view.ViewType == Autodesk.Revit.DB.ViewType.FloorPlan) { floorPlans.Insert(view); } else if (view.ViewType == Autodesk.Revit.DB.ViewType.CeilingPlan) { ceilingPlans.Insert(view); } else if (view.ViewType == Autodesk.Revit.DB.ViewType.EngineeringPlan) { engineeringPlans.Insert(view); } } foreach (View floorPlan in floorPlans) { foreach (View ceilingPlan in ceilingPlans) { if (floorPlan.ViewName == ceilingPlan.ViewName) { views.Insert(floorPlan); } } } foreach (View engineeringPlan in engineeringPlans) { if (engineeringPlan.ViewName == engineeringPlan.GenLevel.Name) { views.Insert(engineeringPlan); } } View activeView = m_activeDoc.ActiveView; Autodesk.Revit.DB.ViewType viewType = activeView.ViewType; if (viewType == Autodesk.Revit.DB.ViewType.FloorPlan || viewType == Autodesk.Revit.DB.ViewType.CeilingPlan) { m_views.Insert(activeView); foreach (View view in views) { if (view.GenLevel.Elevation < activeView.GenLevel.Elevation) { m_views.Insert(view); } } } else if (viewType == Autodesk.Revit.DB.ViewType.EngineeringPlan) { if (views.Contains(activeView)) { m_views.Insert(activeView); } foreach (View view in views) { if (view.GenLevel.Elevation < activeView.GenLevel.Elevation) { m_views.Insert(view); } } } else//Get view of the lowest elevation { int i = 0; double elevation = 0; View viewLowestElevation = null; foreach (View view in views) { if (i == 0) { elevation = view.GenLevel.Elevation; viewLowestElevation = view; } else { if (view.GenLevel.Elevation <= elevation) { elevation = view.GenLevel.Elevation; viewLowestElevation = view; } } i++; } m_views.Insert(viewLowestElevation); } }
/// <summary> /// Collect the parameters and export /// </summary> /// <returns></returns> public override bool Export() { base.Export(); bool exported = false; //parameter : ViewSet views ViewSet views = new ViewSet(); if (m_currentViewOnly) { views.Insert(m_activeDoc.ActiveView); } else { views = m_selectViewsData.SelectedViews; } //parameter : DWGExportOptions dwgExportOptions DGNExportOptions dgnExportOptions = new DGNExportOptions(); dgnExportOptions.LayerMapping = m_exportLayerMapping; dgnExportOptions.TemplateFile = m_templateFile; //Export exported = m_activeDoc.Export(m_exportFolder, m_exportFileName, views, dgnExportOptions); return exported; }
/// <summary> /// Add the Level 1 (type = Floor Plan) view to a newly created sheet. /// </summary> public void ViewToNewSheetHardwired() { Revit.Document doc = m_revitApp.ActiveUIDocument.Document; // Collect all available views ViewSet allViews = Utils.View.GetAllViews( doc ); // Collection of views that have been added to existing sheets. ViewSet usedViews = new ViewSet(); // Collect all the existing sheets. It would be nice to have some API to do this. Revit.ElementSet allSheets = Utils.View.GetAllSheets( doc ); // Create a new sheet ViewSheet sheet = ViewSheet.Create( doc, new FilteredElementCollector( doc ).OfClass( typeof( FamilySymbol ) ).OfCategory( BuiltInCategory.OST_TitleBlocks ).Cast<FamilySymbol>().LastOrDefault().Id ); Random rnd = new Random(); String name = "RevitLookup_Sheet" + rnd.Next().ToString(); sheet.Name = name; foreach( ViewSheet viewSheet in allSheets ) { // jeremy migrated from Revit 2014 to 2015: // 'Autodesk.Revit.DB.ViewSheet.Views' is obsolete: 'This property is obsolete in Revit 2015. Use GetAllPlacedViews() instead.' //foreach( Autodesk.Revit.DB.View usedView in viewSheet.Views ) foreach( ElementId id in viewSheet.GetAllPlacedViews() ) { Autodesk.Revit.DB.View usedView = doc.GetElement( id ) as Autodesk.Revit.DB.View; usedViews.Insert( usedView ); } } // Note: The application does not allow the addition of a view to a new sheet if that view has already been added to // an existing sheet. I realized this when a programmatic attempt to do so resulted in an exception being thrown. // So running this hardwired test a second time would result in an exception (As "Level 1 (FloorPlan) would have already been added)". // The workaround that has been used here is that first all the available sheets and their added views are gathered. // Before adding a view it is compared with the used views. arj - 1/17/07 // foreach( Autodesk.Revit.DB.View view in allViews ) { // Has been hardwired for the following view. if( ( view.ViewName == "Level 1" ) && ( view.ViewType == ViewType.FloorPlan ) ) { UV point = view.Outline.Max; // Display notification message if view is already being used. foreach( Autodesk.Revit.DB.View usedView in usedViews ) { if( ( usedView.ViewName == view.ViewName ) && ( usedView.ViewType == view.ViewType ) ) { MessageBox.Show( "View already added to an existing sheet", "RevitLookup Test", MessageBoxButtons.OK, MessageBoxIcon.Information ); return; } } Viewport.Create( view.Document, sheet.Id, view.Id, new XYZ( point.U, point.V, 0 ) ); } } }
/// <summary> /// Collect the parameters and export /// </summary> /// <returns></returns> public override bool Export() { base.Export(); bool exported = false; //parameter : ViewSet views ViewSet views = new ViewSet(); if (m_currentViewOnly) { views.Insert(m_activeDoc.ActiveView); } else { views = m_selectViewsData.SelectedViews; } //parameter : DXFExportOptions dxfExportOptions SATExportOptions satExportOptions = new SATExportOptions(); //Export exported = m_activeDoc.Export(m_exportFolder, m_exportFileName, views, satExportOptions); return exported; }
private void btnCreate_Click(object sender, EventArgs e) { string prop = cbRevisions.SelectedItem.ToString(); int selectedSequence = RevisionSequenceNumber(prop); ViewSet set = new ViewSet(); foreach (ViewSheet vss in viewSheets) { IList <ElementId> revisionIds = vss.GetAllRevisionIds(); foreach (ElementId i in revisionIds) { Element elem = myRevitDoc.GetElement(i); Revision r = elem as Revision; int sequenceNumber = r.SequenceNumber; string num = vss.GetRevisionNumberOnSheet(i); string date = r.RevisionDate; if (rbSequence.Checked) { if (selectedSequence == sequenceNumber) { set.Insert(vss); } } else if (rbNumber.Checked) { if (num == prop) { set.Insert(vss); } } else { if (date == prop) { set.Insert(vss); } } } } PrintManager print = myRevitDoc.PrintManager; print.PrintRange = PrintRange.Select; ViewSheetSetting viewSheetSetting = print.ViewSheetSetting; viewSheetSetting.CurrentViewSheetSet.Views = set; Transaction trans = new Transaction(myRevitDoc, "Create Sheet Set"); trans.Start(); try { viewSheetSetting.SaveAs(prop); TaskDialog dialog = new TaskDialog("Create Sheet Set"); dialog.MainInstruction = prop + " was created successfully"; trans.Commit(); dialog.Show(); } catch (Exception ex) { TaskDialog dialog = new TaskDialog("Create Sheet Set"); dialog.MainInstruction = "Failed to create " + prop; dialog.MainContent = ex.Message; trans.RollBack(); dialog.Show(); } }
/// <summary> /// Collect the parameters and export /// </summary> /// <returns></returns> public override bool Export() { base.Export(); bool exported = false; //parameter : ViewSet views ViewSet views = new ViewSet(); if (m_currentViewOnly) { views.Insert(m_activeDoc.ActiveView); } else { views = m_selectViewsData.SelectedViews; } ICollection<ElementId> viewIds = new List<ElementId>(); foreach (View view in views) { viewIds.Add(view.Id); } //parameter : DXFExportOptions dxfExportOptions SATExportOptions satExportOptions = new SATExportOptions(); //Export exported = m_activeDoc.Export(m_exportFolder, m_exportFileName, viewIds, satExportOptions); return exported; }
public SheetsOSSRequest(UIApplication uiApp, String text) { MainUI uiForm = BARevitTools.Application.thisApp.newMainUi; RVTDocument doc = uiApp.ActiveUIDocument.Document; DataGridView dgv = uiForm.sheetsOSSDataGridView; //Collect the view sheets and view sheet sets var viewSheets = new FilteredElementCollector(doc).OfClass(typeof(ViewSheet)).ToElements(); var viewSheetSets = new FilteredElementCollector(doc).OfClass(typeof(ViewSheetSet)).ToElements(); Dictionary <string, Autodesk.Revit.DB.ViewSheet> viewSheetDict = new Dictionary <string, Autodesk.Revit.DB.ViewSheet>(); Dictionary <string, ViewSheetSet> viewSheetSetDict = new Dictionary <string, ViewSheetSet>(); List <int> viewSheetIds = new List <int>(); List <string> viewSheetSetNames = new List <string>(); //Add the sheets to the dictionary and list foreach (ViewSheet viewSheet in viewSheets) { if (!viewSheet.IsPlaceholder) { try { viewSheetDict.Add(viewSheet.Name, viewSheet); viewSheetIds.Add(viewSheet.Id.IntegerValue); } catch { MessageBox.Show(viewSheet.IsPlaceholder.ToString()); } } } //Add the view sheet sets to the dictionary and list foreach (ViewSheetSet viewSheetSet in viewSheetSets) { viewSheetSetDict.Add(viewSheetSet.Name, viewSheetSet); viewSheetSetNames.Add(viewSheetSet.Name); } //Get the PrintManager and set its PrintRange to Select, then assign it the VeiwSheetSetting PrintManager printManager = doc.PrintManager; printManager.PrintRange = PrintRange.Select; ViewSheetSetting viewSheetSetting = printManager.ViewSheetSetting; //Start a transaction Transaction t1 = new Transaction(doc, "UpdateViewSheetSets"); t1.Start(); foreach (DataGridViewColumn column in dgv.Columns) { //Go through the columns, but only grab those that have an index greater than 2, which correspond to the sheet set names if (column.Index > 2) { //Make a new ViewSet ViewSet newViewSet = new ViewSet(); viewSheetSetting.CurrentViewSheetSet.Views = newViewSet; //Foreach row, if the column has a checked checkbox, insert the sheet from the dictionary matching the sheet number into the ViewSet foreach (DataGridViewRow row in dgv.Rows) { if (row.Cells[column.Index].Value.ToString() == "True") { newViewSet.Insert(viewSheetDict[row.Cells[1].Value.ToString()]); } } //If the viewSheetSetNames contains the column name, indicating the SheetSet already exists, delete it, then save a new one with the same name if (viewSheetSetNames.Contains(column.Name)) { ElementId vssId = viewSheetSetDict[column.Name].Id; doc.Delete(vssId); viewSheetSetting.SaveAs(column.Name); } else { //If the SheetSet does not already exist, just save it viewSheetSetting.SaveAs(column.Name); } } } t1.Commit(); //Re-invoke the creation of the MainUI's controls for the OSS tool so the table updates with new data from the previous run uiForm.SheetsOSSButton_Click(null, null); }