How to identify grids are 2D or 3D?

How to identify grids are 2D or 3D?

preeti.kumari9TBN6
Enthusiast Enthusiast
268 Views
1 Reply
Message 1 of 2

How to identify grids are 2D or 3D?

preeti.kumari9TBN6
Enthusiast
Enthusiast
public static void AnalyzeGridsInSheetViews(Document doc, List<ViewSheet> selectedSheets)
        {
            // Dictionary to store results
            Dictionary<string, List<string>> sheetGridSummary = new Dictionary<string, List<string>>();

            foreach (ViewSheet sheet in selectedSheets)
            {
                List<string> summaryList = new List<string>();

                // Collect all viewports on this sheet
                var viewports = new FilteredElementCollector(doc, sheet.Id)
                    .OfClass(typeof(Viewport))
                    .Cast<Viewport>()
                    .ToList();

                foreach (Viewport vp in viewports)
                {
                    View view = doc.GetElement(vp.ViewId) as View;
                    if (view == null) continue;

                    // Collect grids visible in the current view
                    var grids = new FilteredElementCollector(doc, view.Id)
                        .OfClass(typeof(Grid))
                        .Cast<Grid>()
                        .ToList();

                    int count2D = 0;
                    int count3D = 0;

                    foreach (Grid grid in grids)
                    {
                       var type= grid.GetType();
                        IList<Curve> viewCurves = grid.GetCurvesInView(DatumExtentType.ViewSpecific, view);
                        IList<Curve> modelCurves = grid.GetCurvesInView(DatumExtentType.Model, view);
                    if(viewCurves.Count>0 )
                        {
                           count2D++;
                        }
                        else
                        {
                            count3D++;
                        }

                        //if (extentData == null)
                        //    continue;

                        //bool is2D = extentData.IsViewSpecific;   // True if the grid is 2D in that view
                        //bool is3D = !extentData.IsViewSpecific;  // False means it’s 3D
                        //                                         //#endif

                        //if (is2D && !is3D)
                        //    count2D++;
                        //else if (is3D)
                        //    count3D++;
                    }

                    string summary = $"View: {view.Name} → 2D Grids: {count2D}, 3D Grids: {count3D}";
                    summaryList.Add(summary);
                }

                sheetGridSummary[sheet.Name] = summaryList;
            }

            // Print or log results
            foreach (var kvp in sheetGridSummary)
            {
                TaskDialog.Show("Grid Summary",
                    $"Sheet: {kvp.Key}\n" + string.Join("\n", kvp.Value));
            }
        }Bt for both data are coming modelCurves and viewCurves. I have read 2D grids are viewSpecific.
 
0 Likes
269 Views
1 Reply
Reply (1)
Message 2 of 2

ctm_mka
Collaborator
Collaborator

First, curious what your need for this type of info is. Second, they are both 3d and 2d, with the Caveat of the 2d being only when cropped by a view, or the user has changed it to 2d (by clicking on the 3d symbol). Third, i would look at the length of line between the model and view specific options as shown. Finally, dont forget about multi segment grids! each segment is a grid itself.

ctm_mka_0-1761596462453.pngctm_mka_2-1761596486472.png

 

 

 

 

 

0 Likes