Revit API - 网格和标高 - GetDatumExtent PlaInView - 网格问题
Revit API - Grids & Levels - GetDatumExtentTypeInView - issue with grids
我正在尝试获取网格范围类型。它要么是 "model" 要么是 "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
那将是一个巨大的帮助
我建议您完成一些简单的入门工作 tutorial on debugging in Visual Studio IDE。
在调试器中,您可以逐行调试代码,检查所有变量的值,等等,从而一举满足您的上述所有要求。
我正在尝试获取网格范围类型。它要么是 "model" 要么是 "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
那将是一个巨大的帮助
我建议您完成一些简单的入门工作 tutorial on debugging in Visual Studio IDE。
在调试器中,您可以逐行调试代码,检查所有变量的值,等等,从而一举满足您的上述所有要求。