Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Hiding bubble by the closest line

diogo.vieiraBCKUL
Contributor

Hiding bubble by the closest line

diogo.vieiraBCKUL
Contributor
Contributor

I need to hide a bubble by the selected close line. But how is it possible to do? I know that DatumEnds.End0 can actually help with that. But how do I connect the selected line to the bubble side?

diogovieiraBCKUL_0-1633522139341.png

A- Selected line of the user
B- Bubble that is suppose to get hidden

 

 

0 Likes
Reply
334 Views
4 Replies
Replies (4)

RPTHOMAS108
Mentor
Mentor

There are multiple ways, two that I can think of:

 

1) If you create a Transform with Basis.X aligned with line direction, Z remains as Z (for plans) and Y is cross product of Z and X then you can use Tranform.OfPoint on each grid end. For example shown one resulting Y ord will be positive and one negative but the smallest absolute value will point to the nearest end.

 

2) Curve.Intersect(Curve, IntersectionResultArray) will give you an intersection result. This contains the intersection parameter on each curve (how near to one end or other). You also get XYZPoint which you can use XYZ.DistanceTo(XYZ) to find which end of grid is nearest.

 

 

0 Likes

diogo.vieiraBCKUL
Contributor
Contributor
I ended up finding an answer, in case, someone ever needs, here is the link: https://forums.autodesk.com/t5/revit-api-forum/how-to-know-true-datumends-end0-is-left-or-right-in-v...
0 Likes

diogo.vieiraBCKUL
Contributor
Contributor
Your second option looks lowkey helpful, will give it a try.
0 Likes

diogo.vieiraBCKUL
Contributor
Contributor

If everyone ever needs, here is the code: 

 

 

 

 

try  
			{  
				IList < Reference > rList =   PickDesiredGrids ( uidoc )  ;  
				Reference reference =   PickLine ( uidoc )  ;

				var refPlane = doc . GetElement ( reference . ElementId )   as ReferencePlane ;

				XYZ sp = refPlane . BubbleEnd ;  
				XYZ ep = refPlane . FreeEnd ;  
				Curve c = Line . CreateBound ( sp , ep )  ;

				foreach   (  var item in rList )  
				{  
					using   ( Transaction trans =   new   Transaction  ( doc ,   "Hide Bubble"  )  )  
					{  
						trans . Start (  )  ;

						Grid grid = doc . GetElement ( item . ElementId )   as Grid ;  
						Curve gridLine = grid . Curve ;

						XYZ spg = gridLine . GetEndPoint (  0  )  ;  
						XYZ epg = gridLine . GetEndPoint (  1  )  ;

						SetComparisonResult scr = gridLine . Intersect ( c ,   out IntersectionResultArray intersectionResultArray )  ;  

						XYZ point = intersectionResultArray . get_Item (  0  )  . XYZPoint ;

						if   ( spg . DistanceTo ( point )   > epg . DistanceTo ( point )  )  
						{  
							grid . HideBubbleInView ( DatumEnds . End0 , doc . ActiveView )  ;  
						}  
						else  
						{  
							grid . HideBubbleInView ( DatumEnds . End1 , doc . ActiveView )  ;  
						}

						trans . Commit (  )  ;  
					}  
				}  
			}  
			catch   ( Exception e )  
			{  
				TaskDialog . Show (  "o"  , e . Message )  ;  
			}

 

 

 

 

Thanks a lot to  @RPTHOMAS108 for giving me some ideas to start doing it!

0 Likes