Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have been attempting to convert something that I wrote in pyRevit into c# code that will hide all grid bubbles. Currently I have set it to hide all of them, but it will move them to a specific side in the future. The formatting might be a little different bit different because I'm using the Nice3point templates, but most of it should be the same. The code works fine in python. I suspect that I might be using show and hide wrong, but as far as I can tell this is how it's used in the samples.
public override void Execute()
{
Document doc = Application.ActiveUIDocument.Document;
Result r = Result.Failed;
Autodesk.Revit.DB.View view = doc.ActiveView;
var grids = new FilteredElementCollector(doc, doc.ActiveView.Id).OfCategory(BuiltInCategory.OST_Grids).WhereElementIsNotElementType().ToList();
Console.WriteLine(grids.Count + " grids in list");
foreach (Element element in grids)
{
//treat elements as grids
Grid grid = element as Grid;
Console.WriteLine(grid.Name);
using (Transaction transaction = new Transaction(doc, "Fix bubbles"))
{
//get endpoints for grids
XYZ start = grid.Curve.GetEndPoint(0);
XYZ end = grid.Curve.GetEndPoint(1);
transaction.Start();
try
{
//if horizontal
if (start.Y == end.Y)
{
Console.WriteLine("hit if horizontal");
grid.HideBubbleInView(DatumEnds.End1, view);
grid.HideBubbleInView(DatumEnds.End0, view);
}
//if vertical
else if (start.X == end.X)
{
Console.WriteLine("hit if vertical");
grid.HideBubbleInView(DatumEnds.End0, view);
grid.HideBubbleInView(DatumEnds.End1, view);
}
}
catch (Exception e)
{
return;
}
}
}
}
Solved! Go to Solution.