diff --git a/changelog.org b/changelog.org index 29f4fd8..7554e39 100644 --- a/changelog.org +++ b/changelog.org @@ -865,3 +865,6 @@ only possible via PostableCommand **** =12:18= updated IncrementSheetNumbers command to handle different numbering format needed to update sheets numbered with a hyphen in third place, e.g. 35-501, 35-502 hopefully it won't get more complex than that, wish we just all followed the iso standard +[[https://chatgpt.com/share/677bcb3b-d8f8-800c-adc4-769b651e9791][chatgpt]] +**** =16:32= updated OpenViews command, added "Sheet Folder" column, remove redundant "View Type" +[[https://chatgpt.com/share/677c0771-806c-800c-833b-40733346649a][chatgpt]] \ No newline at end of file diff --git a/nohup.out b/nohup.out deleted file mode 100644 index e69de29..0000000 diff --git a/revit-scripts/OpenViews.cs b/revit-scripts/OpenViews.cs index 308af2b..ec7695c 100644 --- a/revit-scripts/OpenViews.cs +++ b/revit-scripts/OpenViews.cs @@ -8,31 +8,58 @@ [Regeneration(RegenerationOption.Manual)] public class OpenViews : IExternalCommand { + // A simple wrapper class to expose View properties and a custom parameter for the DataGrid + public class ViewInfo + { + public string Title { get; set; } + public string SheetFolder { get; set; } + // Keep a reference to the underlying Revit View so we can open it. + public View RevitView { get; set; } + } + public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; - // Get all views in the project - List views = new FilteredElementCollector(doc) + // Grab all non-template, non-browser views. + List allViews = new FilteredElementCollector(doc) .OfClass(typeof(View)) .Cast() .Where(v => !v.IsTemplate && v.Title != "Project Browser" && v.Title != "System Browser") .OrderBy(v => v.Title) // Sort views alphabetically by Title .ToList(); - List properties = new List { "Title", "ViewType" }; + // Convert each View to a ViewInfo, including the "Sheet Folder" parameter (if present). + List viewInfoList = allViews.Select(v => + { + // Attempt to read a parameter called "Sheet Folder" + Parameter sheetFolderParam = v.LookupParameter("Sheet Folder"); + string sheetFolderValue = sheetFolderParam?.AsString() ?? string.Empty; - // Determine the index of the currently active view in the sorted list + return new ViewInfo + { + Title = v.Title, + SheetFolder = sheetFolderValue, + RevitView = v + }; + }).ToList(); + + // Determine the index of the currently active view in the new list. ElementId currentViewId = uidoc.ActiveView.Id; - int selectedIndex = views.FindIndex(v => v.Id == currentViewId); + int selectedIndex = viewInfoList.FindIndex(v => v.RevitView.Id == currentViewId); - // Adjusted call to DataGrid to use a list with a single index for initial selection + // Create a single initial selection if we found a match. List initialSelectionIndices = selectedIndex >= 0 ? new List { selectedIndex } : new List(); - var selectedViews = CustomGUIs.DataGrid(views, properties, initialSelectionIndices); + // Specify which properties to show in the DataGrid: + List properties = new List { "Title", "SheetFolder" }; + + // Call your DataGrid, which presumably uses reflection to display columns for each property + var selectedItems = CustomGUIs.DataGrid(viewInfoList, properties, initialSelectionIndices); - selectedViews.ForEach(view => uidoc.RequestViewChange(view)); + // Request a view change for each selected item + selectedItems.ForEach(vInfo => uidoc.RequestViewChange(vInfo.RevitView)); return Result.Succeeded; }