Hello @c.poupin
By adding an output of grid angle to your code i could make the process of setting the bubbles much more efficient
This is now the exact result i want:
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import *
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
if isinstance(IN[1], list):
gridList = UnwrapElement(IN[0])
viewList = UnwrapElement(IN[1])
angleList = UnwrapElement(IN[2])
else:
gridList = [UnwrapElement(IN[0])]
viewList = [UnwrapElement(IN[1])]
angleList = [UnwrapElement(IN[2])]
TransactionManager.Instance.EnsureInTransaction(doc)
for grids, angles, view in zip(gridList, angleList, viewList):
for grid, angle in zip(grids, angles):
if 121< angle <300:
grid.ShowBubbleInView(DatumEnds.End1,view)
grid.HideBubbleInView(DatumEnds.End0,view)
else:
grid.ShowBubbleInView(DatumEnds.End0,view)
grid.HideBubbleInView(DatumEnds.End1,view)
TransactionManager.Instance.TransactionTaskDone()
doc.Regenerate()
OUT = viewList
import clr
import math
import System
clr.AddReference('ProtoGeometry')
import Autodesk.DesignScript.Geometry as DSGeo
from Autodesk.DesignScript.Geometry import *
#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
#import transactionManager and DocumentManager (RevitServices is specific to Dynamo)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
uidoc = uiapp.ActiveUIDocument
app = uiapp.Application
sdkNumber = int(app.VersionNumber)
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
def createDatumLine(boundLines, grid):
gridLine = None
curveG = grid.Curve#.ToProtoType()
vectGrid = curveG.Direction
lstPtToLine = []
for lineBound in boundLines:
rayc = DB.Line.CreateUnbound(XYZ(curveG.Origin.X, curveG.Origin.Y, lineBound.GetEndPoint(0).Z) , vectGrid)
outInterR = clr.Reference[IntersectionResultArray]()
result = rayc.Intersect(lineBound, outInterR)
print(result)
if result == SetComparisonResult.Overlap:
interResult = outInterR.Value
lstPtToLine.append(interResult[0].XYZPoint)
print(lstPtToLine)
if len(lstPtToLine) == 2:
P1 = lstPtToLine[0].ToPoint()
P2 = lstPtToLine[1].ToPoint()
TransXYZ1 = Geometry.Translate(P1 ,0,0,0)
TransXYZ2 = Geometry.Translate(P2 ,0,0,0)
TransPoint1 = TransXYZ1.ToXyz()
TransPoint2 = TransXYZ2.ToXyz()
gridLine = Autodesk.Revit.DB.Line.CreateBound(TransPoint1, TransPoint2)
return gridLine
activView = UnwrapElement(IN[0])
lstInputViews = UnwrapElement(IN[0])
TransactionManager.Instance.EnsureInTransaction(doc)
for activView in lstInputViews:
#
activView.CropBoxVisible = True
doc.Regenerate()
#
cropBox = activView.CropBox
fecGrids = FilteredElementCollector(doc, activView.Id).OfClass(DatumPlane).ToElements()
cutOffset = fecGrids[0].GetCurvesInView(DatumExtentType.ViewSpecific, activView)[0].GetEndPoint(0).Z
fecGrids = [x for x in fecGrids if isinstance(x, DB.Grid)]
outLst = []
newGLineList = []
shpManager = activView.GetCropRegionShapeManager()
boundLines = shpManager.GetCropShape()[0]
if activView.ViewDirection.IsAlmostEqualTo(XYZ(0,0,1)):
# get Current Elevation of boundLines
currentZ = list(boundLines)[0].GetEndPoint(0).Z
# transform boundLines CurveLoop
tf = Transform.CreateTranslation( XYZ(0,0, cutOffset - currentZ))
boundLines = CurveLoop.CreateViaTransform(boundLines, tf)
for grid in fecGrids:
outLst.append(grid.Curve.ToProtoType())
newGLine = createDatumLine(boundLines, grid)
newGLineList.append(newGLine)
if newGLine is not None:
grid.SetCurveInView(DatumExtentType.ViewSpecific, activView, newGLine)
else:
for grid in fecGrids:
outLst.append(grid.Curve.ToProtoType())
newGLine = createDatumLine(boundLines, grid)
newGLineList.append(newGLine)
if newGLine is not None:
grid.SetCurveInView(DatumExtentType.ViewSpecific, activView, newGLine)
TransactionManager.Instance.TransactionTaskDone()
startpointList = []
endpointList = []
rotationAngleList = []
for newGLine in newGLineList:
startpointXYZ = newGLine.GetEndPoint(0)
endpointXYZ = newGLine.GetEndPoint(1)
startpoint = startpointXYZ.ToPoint()
endpoint = endpointXYZ.ToPoint()
startpointList.append(startpoint)
endpointList.append(endpoint)
vector = newGLine.Direction
rotationAngle = abs(math.degrees(vector.AngleOnPlaneTo(XYZ.BasisX, XYZ.BasisZ)))
rotationAngleList.append(rotationAngle)
OUT = lstInputViews, startpointList, endpointList, rotationAngleList