1

I'm trying to get the grid extent types. its either gonna be "model" or "specificView"

with the code i have, I am able to get the Levels extent types but not the Grid extent types.

I've found these sources so far that have helped.

https://forum.dynamobim.com/t/switching-between-2d-and-3d-extent-levels-grid/10980/2

https://www.revitapidocs.com/2019/b3498ccf-1180-e0fd-502c-6c767f5b42cc.htm

https://disqus.com/home/discussion/revit-api-docs/setverticalextents_method_60/#edit-3254927585

This is the error im getting:

Exception thrown: 'Autodesk.Revit.Exceptions.ArgumentException' in RevitAPI.dll
Error StackTrace:    at Autodesk.Revit.DB.DatumPlane.GetDatumExtentTypeInView(DatumEnds datumEnd, View view)
   at ChangeGridExtentsTo2D.Command.Execute(ExternalCommandData commandData, String& message, ElementSet elements)
Error Data: System.Collections.ListDictionaryInternal
Error Source: RevitAPI
Error TargetSite: Autodesk.Revit.DB.DatumExtentType GetDatumExtentTypeInView(Autodesk.Revit.DB.DatumEnds, Autodesk.Revit.DB.View)

Here is my code so far:

            FilteredElementCollector colGrids = new FilteredElementCollector(doc)
                .WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_Grids)
                .OfClass(typeof(Grid));
            Debug.WriteLine("colGrids count: " + colGrids.GetElementCount()); //output is 3 which is correct


            FilteredElementCollector colLevels = new FilteredElementCollector(doc)
                .WhereElementIsNotElementType().OfCategory(BuiltInCategory.OST_Levels)
                .OfClass(typeof(Level));
            Debug.WriteLine("colLevels count: " + colLevels.GetElementCount()); // output is 7 which is correct


            using (Transaction tx = new Transaction(doc))
            {
                try
                {
                    tx.Start("Changing extends to 2d");

                    foreach (DatumPlane xLevels in colLevels)
                    {
                        //x.GetDatumExtentTypeInView(DatumEnds.End0, uidoc.ActiveView);

                        Debug.WriteLine(xLevels.Name + ": " + xLevels.GetDatumExtentTypeInView(DatumEnds.End0, uidoc.ActiveView));
                        Debug.WriteLine(xLevels.Name + ": " + xLevels.GetDatumExtentTypeInView(DatumEnds.End1, uidoc.ActiveView));
                    }

                    foreach (DatumPlane xGrids in colGrids)
                    {

                        Debug.WriteLine(xGrids.Name + ": " + xGrids.GetDatumExtentTypeInView(DatumEnds.End0, uidoc.ActiveView));

                    }
                    tx.Commit();
                }
                catch (Exception e)
                {
                    Debug.WriteLine("Error StackTrace: " + e.StackTrace);
                    Debug.WriteLine("Error Data: " + e.Data);
                    Debug.WriteLine("Error Source: " + e.Source);
                    Debug.WriteLine("Error TargetSite: " + e.TargetSite);

                    tx.RollBack();

                }
            }

PS - I am new to VS IDE so if anyone has any tips on getting more verbose errors like:

what line the error occurs on
the variable or function it crashed at
or anything like that

That would be a huge help

Cflux
  • 1,423
  • 3
  • 19
  • 39

1 Answers1

1

I suggest you work through some simple getting started tutorial on debugging in Visual Studio IDE.

In the debugger, you can step through the code line by line, examine the values of all the variables, and much more, thereby answering all your requests above in one fell swoop.

Jeremy Tammik
  • 7,333
  • 2
  • 12
  • 17
  • 1
    I got it working. When stuff fails, like for my android app in android studio, it tells me where and how it failed. Maybe VS gives me limited information in the stack trace because everything is always wrapped in a try-catch block. I don't have much experience with those. VS is still an unfamiliar IDE to me. A work in progress... Definitely need to watch more videos on it. – Cflux Jan 31 '20 at 02:21
  • Congratulations on making progress. – Jeremy Tammik Feb 01 '20 at 08:02