Looking for help with HideBubbleInView and ShowBubbleInView

Looking for help with HideBubbleInView and ShowBubbleInView

jfranzR9VWK
Explorer Explorer
351 Views
3 Replies
Message 1 of 4

Looking for help with HideBubbleInView and ShowBubbleInView

jfranzR9VWK
Explorer
Explorer

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;
                }
            }
            
        }
        
    }

 

0 Likes
Accepted solutions (2)
352 Views
3 Replies
Replies (3)
Message 2 of 4

ctm_mka
Collaborator
Collaborator
Accepted solution

two things. First, possibly the actual issue, although i'm surprised Revit didn't yell at you for this when you tried to run it, but you don't appear to be committing your transaction. Second, as a reminder for your future endeavors, coordinate values are always internal coordinates, so detection of horizontal vs vertical needs to account for view rotation.

0 Likes
Message 3 of 4

jfranzR9VWK
Explorer
Explorer

Thanks for the help with that. Is there a coordinate to use that isn't dependent on the view angle?

0 Likes
Message 4 of 4

ctm_mka
Collaborator
Collaborator
Accepted solution

not really no. you have to account for it yourself. here's an example of how i deal with it:

View _activeView = _uidoc.ActiveView;
BoundingBoxXYZ crop = _activeView.CropBox;
XYZ viewX = crop.Transform.BasisX;
//angle of the view from 0
double viewRot = HorizAngle(XYZ.Zero, viewX);
//angle of the object from 0, plus the view rotation
 double ang = HorizAngle(startpt, endpt)) + viewRot;
 if (ang > Math.PI / 2 && ang <= 1.5 * Math.PI)
 {
	 //testing if angle is greater than 90 and less than or equal to 270
	 //adjust to your needs
 }

 public double HorizAngle(XYZ point1, XYZ point2)
 {
     //finds the angle from X axis, much better than Revit's angleto method, as it returns greater than 180 degrees.
     double testang = Math.Atan2(point2.Y - point1.Y, point2.X - point1.X);
     //normalize the angle to return 0 to 360 becuase atan2 returns -180 to 180
     testang = (testang % (Math.PI * 2) + (Math.PI * 2)) % (Math.PI * 2);
     return testang;
 }
0 Likes