Skip to content

Commit

Permalink
updated OpenViews command, added "Sheet Folder" column, remove redund…
Browse files Browse the repository at this point in the history
…ant "View Type"
  • Loading branch information
baleti committed Jan 6, 2025
1 parent 4a40856 commit 4b66f62
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
3 changes: 3 additions & 0 deletions changelog.org
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Empty file removed nohup.out
Empty file.
43 changes: 35 additions & 8 deletions revit-scripts/OpenViews.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<View> views = new FilteredElementCollector(doc)
// Grab all non-template, non-browser views.
List<View> allViews = new FilteredElementCollector(doc)
.OfClass(typeof(View))
.Cast<View>()
.Where(v => !v.IsTemplate && v.Title != "Project Browser" && v.Title != "System Browser")
.OrderBy(v => v.Title) // Sort views alphabetically by Title
.ToList();

List<string> properties = new List<string> { "Title", "ViewType" };
// Convert each View to a ViewInfo, including the "Sheet Folder" parameter (if present).
List<ViewInfo> 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<int> initialSelectionIndices = selectedIndex >= 0 ? new List<int> { selectedIndex } : new List<int>();

var selectedViews = CustomGUIs.DataGrid<View>(views, properties, initialSelectionIndices);
// Specify which properties to show in the DataGrid:
List<string> properties = new List<string> { "Title", "SheetFolder" };

// Call your DataGrid, which presumably uses reflection to display columns for each property
var selectedItems = CustomGUIs.DataGrid<ViewInfo>(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;
}
Expand Down

0 comments on commit 4b66f62

Please sign in to comment.