#Copyright (c) mostafa el ayoubi
#Data-Shapes www.data-shapes.net 2016 elayoub.mostafa@gmail.com
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import*
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
import System
from System.Collections.Generic import*
doc = DocumentManager.Instance.CurrentDBDocument
def tolist(input):
if isinstance(input,list):
return input
else:
return [input]
#Document UI Units
try:
UIunit = Document.GetUnits(doc).GetFormatOptions(UnitType.UT_Length).DisplayUnits
except:
UIunit = Document.GetUnits(doc).GetFormatOptions(SpecTypeId.Length).GetUnitTypeId()
#Inputs : Points, Direction, 3D View
if isinstance(IN[0],list):
points = [XYZ(UnitUtils.ConvertToInternalUnits(i.X,UIunit),UnitUtils.ConvertToInternalUnits(i.Y,UIunit),UnitUtils.ConvertToInternalUnits(i.Z,UIunit)) for i in IN[0]]
else:
points = [XYZ(UnitUtils.ConvertToInternalUnits(IN[0].X,UIunit),UnitUtils.ConvertToInternalUnits(IN[0].Y,UIunit),UnitUtils.ConvertToInternalUnits(IN[0].Z,UIunit))]
direction = XYZ(IN[1].X,IN[1].Y,IN[1].Z)
view = UnwrapElement(IN[2])
ex = []
pts = []
elems = []
categories = tolist(IN[3])
catfilters = []
for i in categories:
catfilters.append(ElementCategoryFilter(System.Enum.ToObject(BuiltInCategory, int(str(i.Id)))))
catfilterlist = List[ElementFilter](catfilters)
filter = LogicalOrFilter(catfilterlist)
ri = ReferenceIntersector(filter,FindReferenceTarget.All,view)
ri.FindReferencesInRevitLinks = True
for p in points:
ref = ri.FindNearest(p,direction)
if ref == None:
pts.append(None)
elems.append(None)
else:
refel = ref.GetReference()
linkinstance = doc.GetElement(refel.ElementId)
try:
elem = linkinstance.GetLinkDocument().GetElement(refel.LinkedElementId)
elems.append(elem)
refp = ref.GetReference().GlobalPoint
pts.append(Point.ByCoordinates(UnitUtils.ConvertFromInternalUnits(refp.X,UIunit),UnitUtils.ConvertFromInternalUnits(refp.Y,UIunit),UnitUtils.ConvertFromInternalUnits(refp.Z,UIunit)))
except:
if not IN[4]:
elems.append(linkinstance)
refp = ref.GetReference().GlobalPoint
pts.append(Point.ByCoordinates(UnitUtils.ConvertFromInternalUnits(refp.X,UIunit),UnitUtils.ConvertFromInternalUnits(refp.Y,UIunit),UnitUtils.ConvertFromInternalUnits(refp.Z,UIunit)))
else:
pts.append(None) #missing
elems.append(None) #missing
OUT = pts , elems
Has anyone noticed that raybounce from datashape will sometimes export points and elements lesser than the input elements?
I’ve modified the node and add the last two code (which have #missing), which the original code is pass
Then my number of output list = input now.
I hope it helps