/// <summary> /// Metodo per l'apertura della VIEW SCELTA /// </summary> public void SingleOpenView(UIApplication uiapp, string viewName) { UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; FilteredElementCollector viewCollector = new FilteredElementCollector(doc); viewCollector.OfClass(typeof(Autodesk.Revit.DB.View)); //string[] elevations = new string[] { "Exterior", "Interior", "Left", "Right" }; // Cambia il valore booleano per attestare che la richiesta della view è singola _single = true; foreach (Autodesk.Revit.DB.View viewElement in viewCollector) { if (viewElement.Name == viewName) { uidoc.RequestViewChange(viewElement); _imageViewed = viewElement.Name; // Chiama la Form modelessForm = App.thisApp.RetriveForm(); // Mostra nella combobox la vista attiva modelessForm.AssignValueComboBox(); // Salvo ed esco uidoc.SaveAndClose(); } } }
private void IterateViews() { //Non working attempt to retrieve "Project View" //Project Browser is an internal view, which can not be set as active view programmatically. IList <UIView> views = ActiveUIDocument.GetOpenUIViews(); string viewIds = "view count: " + views.Count.ToString() + "\n\r"; for (int i = 0; i < views.Count; i++) { UIView view = views[i]; viewIds += view.ViewId.ToString(); viewIds += view.ToString(); viewIds += "\n\r"; } TaskDialog.Show("Revit", viewIds); UIApplication application = this; UIDocument uidoc = application.ActiveUIDocument; Document document = application.ActiveUIDocument.Document; FilteredElementCollector viewCollector = new FilteredElementCollector(document); viewCollector.OfClass(typeof(Autodesk.Revit.DB.View)); TaskDialog.Show("Revit", viewCollector.Count().ToString()); TaskDialog.Show("Revit", "BEFORE : " + ActiveUIDocument.Document.ActiveView.Name + "Cat:" + ActiveUIDocument.Document.ActiveView.ViewType); foreach (Element viewElement in viewCollector) { Autodesk.Revit.DB.View view = (Autodesk.Revit.DB.View)viewElement; if (view.ViewType == ViewType.ProjectBrowser) { // uidoc.ActiveView = view; uidoc.RequestViewChange(view); } //Do something... } // internal static List<Autodesk.Revit.DB.View> SheetsAndView() // { // Document doc = DocumentManager.Instance.CurrentDBDocument; // FilteredElementCollector collector = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Views); // List<Autodesk.Revit.DB.View> viewList = collector.ToElements() as List<Autodesk.Revit.DB.View>; // // return viewList; // } // // UIDocument uiDoc = ActiveUIDocument; //// UIView view = uiDoc.GetOpenUIViews().FirstOrDefault(item => item.ViewId.ToString() == "Project View"); // UIView view = uiDoc.GetOpenUIViews().FirstOrDefault(item => TaskDialog.Show("Revit", item.ViewId.ToString())); }
private void OpenView(object sender, RoutedEventArgs e) { Button item = sender as Button; if (item != null) { String stairIdString = item.Tag.ToString().Split(null)[1]; String viewIdString = item.Tag.ToString().Split(null)[0]; UIDocument document = application.ActiveUIDocument; document.Selection.SetElementIds(new List <ElementId>() { new ElementId(int.Parse(stairIdString)) }); document.RequestViewChange(document.Document.GetElement(new ElementId(int.Parse(viewIdString))) as View); } }
// The main Execute method (inherited from IExternalCommand) must be public public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { //Connect to revit UIApplication uiapp = commandData.Application; Application application = uiapp.Application; Document doc = uiapp.ActiveUIDocument.Document; UIDocument uidoc = uiapp.ActiveUIDocument; string currentSection = "Hasn't started running yet"; try { TaskDialog.Show("Revit", Method()); } catch (Exception e) { //Show error TaskDialog.Show($"Error, at {currentSection}:", e.Message); return(Result.Failed); } return(Result.Succeeded); //--------------------------------------------------------------------------------------------------------- string Method() { FilteredElementCollector viewcollector = new FilteredElementCollector(doc); ICollection <Element> viewcollection = viewcollector.OfClass(typeof(ViewPlan)).ToElements(); string levels = ""; View active = uidoc.ActiveView; ElementId levelId = null; uidoc.RequestViewChange(); Parameter level = active.LookupParameter("Associated Level"); levels = level.AsString(); return(levels); } void ShowResults() { TaskDialog.Show("Revit", "Hello World"); } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; //List<View> views = new List<View>(); List <UIView> views = uidoc.GetOpenUIViews() as List <UIView>; if (views.Count > 1) { View view = doc.GetElement(views[1].ViewId) as View; uidoc.RequestViewChange(view); } else { ; } return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Application app = commandData.Application.Application; Document doc = commandData.Application.ActiveUIDocument.Document; UIDocument uidoc = commandData.Application.ActiveUIDocument; ElementId sheetId = null; if (doc.ActiveView is ViewSheet) { message = "Active view can not be a sheet!"; return(Result.Failed); } List <ElementId> sheedIds = new List <ElementId>(); foreach (UIView uiview in uidoc.GetOpenUIViews()) { if (doc.GetElement(uiview.ViewId) is ViewSheet) { sheedIds.Add(uiview.ViewId); } } if (sheedIds.Count == 0) { message = "No sheets are open, or a viewport is activated."; return(Result.Failed); } int selectedSheet = 0; if (sheedIds.Count > 1) { List <string> sheetNames = new List <string>(); foreach (ElementId id in sheedIds) { Element e = doc.GetElement(id); sheetNames.Add(e.Name); } WindowSelectSheet dialog = new WindowSelectSheet(sheetNames); dialog.ShowDialog(); if (dialog.DialogResult.HasValue && dialog.DialogResult.Value) { selectedSheet = dialog.comboSheet.SelectedIndex; } else { return(Result.Cancelled); } } sheetId = sheedIds[selectedSheet]; if (Viewport.CanAddViewToSheet(doc, sheetId, doc.ActiveView.Id)) { using (Transaction t1 = new Transaction(doc, "Add active view to opened sheet")) { t1.Start(); Viewport.Create(doc, sheetId, doc.ActiveView.Id, new XYZ(0, 0, 0)); t1.Commit(); } } else { message = "Active view can not be added to sheet. Maybe it is on a sheet already?"; return(Result.Failed); } uidoc.RequestViewChange(doc.GetElement(sheetId) as View); return(Result.Succeeded); }
/// <summary> /// Metodo per l'apertura della view /// </summary> private void OpenView(UIApplication uiapp) { UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; Autodesk.Revit.DB.View viewActive = doc.ActiveView; FilteredElementCollector viewCollector = new FilteredElementCollector(doc); viewCollector.OfClass(typeof(Autodesk.Revit.DB.View)); //string[] elevations = new string[] { "Exterior", "Interior", "Left", "Right" }; // Cambia il valore booleano per attestare che la richiesta della view è multipla _single = false; // Cambia la lingua del name in Inglese string nameViewActive = viewActive.Name; if (nameViewActive == "Exterior" || nameViewActive == "Arrière" || nameViewActive == "Extérieur" || nameViewActive == "Esteriore") { nameViewActive = "Exterior"; } else if (nameViewActive == "Interior" || nameViewActive == "Avant" || nameViewActive == "Intérieur" || nameViewActive == "Interiore") { nameViewActive = "Interior"; } else if (nameViewActive == "Left" || nameViewActive == "Gauche" || nameViewActive == "Sinistra") { nameViewActive = "Left"; } else if (nameViewActive == "Right" || nameViewActive == "Droite" || nameViewActive == "Destra") { nameViewActive = "Right"; } // Verifica se il file si apre su Exterior e nel caso salta direttamente all'esportazione dell'immagine if (nameViewActive == "Exterior" && _imageViewed == "") { _imageViewed = nameViewActive; // Chiama la Form modelessForm = App.thisApp.RetriveForm(); // Mostra nella combobox la vista attiva modelessForm.AssignValueComboBox(); // Salvo ed esco uidoc.SaveAndClose(); } foreach (Autodesk.Revit.DB.View viewElement in viewCollector) { var name = viewElement.Name; // Cambia la lingua del name in Inglese if (name == "Exterior" || name == "Arrière" || name == "Extérieur" || name == "Esteriore") { name = "Exterior"; } else if (name == "Interior" || name == "Avant" || name == "Intérieur" || name == "Interiore") { name = "Interior"; } else if (name == "Left" || name == "Gauche" || name == "Sinistra") { name = "Left"; } else if (name == "Right" || name == "Droite" || name == "Destra") { name = "Right"; } switch (name) { case "Exterior": if (nameViewActive != "Exterior" && nameViewActive != "Interior" && nameViewActive != "Left" && nameViewActive != "Right") { uidoc.RequestViewChange(viewElement); _imageViewed = name; // Chiama la Form modelessForm = App.thisApp.RetriveForm(); // Mostra nella combobox la vista attiva modelessForm.AssignValueComboBox(); // Salvo ed esco uidoc.SaveAndClose(); } break; case "Interior": if (nameViewActive != "Interior" && nameViewActive != "Left" && nameViewActive != "Right") { uidoc.RequestViewChange(viewElement); _imageViewed = name; // Chiama la Form modelessForm = App.thisApp.RetriveForm(); // Mostra nella combobox la vista attiva modelessForm.AssignValueComboBox(); // Salvo ed esco uidoc.SaveAndClose(); } break; case "Left": if (nameViewActive != "Left" && nameViewActive != "Right") { uidoc.RequestViewChange(viewElement); _imageViewed = name; // Chiama la Form modelessForm = App.thisApp.RetriveForm(); // Mostra nella combobox la vista attiva modelessForm.AssignValueComboBox(); // Salvo ed esco uidoc.SaveAndClose(); } break; case "Right": if (nameViewActive != "Right") { uidoc.RequestViewChange(viewElement); _imageViewed = name; // Chiama la Form modelessForm = App.thisApp.RetriveForm(); // Mostra nella combobox la vista attiva modelessForm.AssignValueComboBox(); // Salvo ed esco uidoc.SaveAndClose(); } break; } } }