Revit API - Сетки и уровни - GetDatumExtentTypeInView - проблема с сетками - PullRequest
0 голосов
/ 30 января 2020

Я пытаюсь получить типы экстентов сетки. Это будет либо «модель», либо «specificView»

с кодом, который у меня есть, я могу получить типы экстентов уровней, но не типы экстентов сетки.

До сих пор я нашел эти источники, которые помогли.

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

Это ошибка, которую я получаю:

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)

Вот мой код:

            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 - Я новичок в VS IDE, так что если у кого-нибудь есть какие-либо советы по получению более подробных ошибок, таких как:

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

Это было бы огромной помощью

1 Ответ

1 голос
/ 30 января 2020

Я предлагаю вам пройти через простое учебное пособие по началу работы по отладке в IDE Visual Studio .

В отладчике вы можете шаг за шагом проходить код, проверяя значения все переменные и многое другое, тем самым отвечая на все ваши запросы выше одним махом oop.

...