Code works for multiple views but my output only works for 1 view.
After hours of trying i ask for help again.
I don´t know how to deal with the sublists:
Working for only one view:
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(activView.RightDirection, XYZ.BasisZ)))
rotationAngleList.append(rotationAngle)
OUT = lstInputViews, rotationAngleList
One of my failed attempts:
startpointList = []
endpointList = []
rotationAngleList = []
for newGLines in newGLineList:
for newGLine in newGLines:
I got many differenht lists, for example sublists with too many items…but i can´t get the result i want Maybe i have to use this mysteriouse [x for x in y] thing i don´t understand.
I don´t think i have to zip lists together in this case?
Happy about any help thanks!
edit:
The problem has to be something even before, because newGLineList ist also only a list for 1 view.
Full code:
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(activView.RightDirection, XYZ.BasisZ)))
rotationAngleList.append(rotationAngle)
OUT = newGLineList