Dynamo to calculate linear sum of walls by facing direction in rooms

New to dynamo,

I am trying to create arrays to store the sum of values of the lengths of a wall based on the room object boundaries orientation.

In vba I would search a 1d array struct (direction angle, sum of lengths) and if the angle didn’t exist, redid the array, add the new angle and resort the array.

These buckets would then be returned as an array for the linear feet of wall for the north, south, easT and west walls e.g. to populate a schedule.

Don’t want to use room book as it overpopulates parameters and is iffy at best.

Tried code blocks but the for each (x in AngleList) doesn’t want to parse.

Is there a definitive guide to dynamo code blocks & iron python, and lists somewhere? I can’t seem to find it anywhere. About to dump into vb.net to try that route as an application addin.

I can post sample files and my broken dynamo tomorrow if anyone can help.

Thnx,

Ron

Success!

Python Node:
<p style=“padding-left: 30px;”> <span style=“color: #75715e;”>##Gather sums of wall / room boundaries based on lengths and directions</span>
<span style=“font-weight: bold; color: #f92672;”>import</span> clr
clr.<span style=“font-weight: bold; color: #ffffff;”>AddReference</span>(<span style=“color: #e6db74;”>“RevitNodes”</span>)
clr.<span style=“font-weight: bold; color: #ffffff;”>AddReference</span>(<span style=“color: #e6db74;”>‘ProtoGeometry’</span>)
<span style=“font-weight: bold; color: #f92672;”>import</span> math
clr.<span style=“font-weight: bold; color: #ffffff;”>AddReference</span>(<span style=“color: #e6db74;”>‘RevitAPI’</span>)
clr.<span style=“font-weight: bold; color: #ffffff;”>AddReference</span>(<span style=“color: #e6db74;”>‘RevitAPIUI’</span>)
<span style=“font-weight: bold; color: #f92672;”>import</span> Revit
clr.<span style=“font-weight: bold; color: #ffffff;”>ImportExtensions</span>(Revit.GeometryConversion)
<span style=“font-weight: bold; color: #f92672;”>import</span> Autodesk

<span style=“font-weight: bold; color: #f92672;”>from</span> Autodesk.Revit.DB <span style=“font-weight: bold; color: #f92672;”>import</span> *

items = <span style=“font-weight: bold; color: #ffffff;”>UnwrapElement</span>(IN[<span style=“color: #ae81ff;”>0</span>])
elementlist = <span style=“font-weight: bold; color: #ffffff;”>list</span>()
curvelist = <span style=“font-weight: bold; color: #ffffff;”>list</span>()

SubAng=<span style=“color: #ae81ff;”>45</span> <span style=“color: #75715e;”>#Smallest division to consider</span>
SubDivs = <span style=“color: #ae81ff;”>360</span>/SubAng <span style=“color: #75715e;”>#Every subang degrees</span>
listGatherSums= [None] * SubDivs <span style=“color: #75715e;”>#List to gather sums of subangles</span>
<span style=“font-weight: bold; color: #f92672;”>for</span> item <span style=“font-weight: bold; color: #f92672;”>in</span> items:
doc = item.Document
calculator = <span style=“font-weight: bold; color: #ffffff;”>SpatialElementGeometryCalculator</span>(doc)
options = Autodesk.Revit.DB.<span style=“font-weight: bold; color: #ffffff;”>SpatialElementBoundaryOptions</span>()
<span style=“color: #75715e;”># get boundary location from area computation settings</span>
boundloc = Autodesk.Revit.DB.AreaVolumeSettings.<span style=“font-weight: bold; color: #ffffff;”>GetAreaVolumeSettings</span>(doc).<span style=“font-weight: bold; color: #ffffff;”>GetSpatialElementBoundaryLocation</span>(SpatialElementType.Room)
options.SpatialElementBoundaryLocation = boundloc
<span style=“color: #75715e;”>#method #1 - get boundary segments</span>
gather = [<span style=“color: #ae81ff;”>0</span>] * SubDivs <span style=“color: #75715e;”>#Unsigned long array of buckets for collecting values</span>
clist = <span style=“font-weight: bold; color: #ffffff;”>list</span>()

<span style=“color: #75715e;”>###########################################################################################</span>
<span style=“color: #75715e;”>#Room Level </span>
RmLvl = item.Level.Name
clist.<span style=“font-weight: bold; color: #ffffff;”>append</span>(RmLvl)
<span style=“color: #75715e;”>###########################################################################################</span>
<span style=“color: #75715e;”>#Room Name</span>
RMname = item.<span style=“font-weight: bold; color: #ffffff;”>get_Parameter</span>(<span style=“color: #e6db74;”>‘Name’</span>).<span style=“font-weight: bold; color: #ffffff;”>AsString</span>()
clist.<span style=“font-weight: bold; color: #ffffff;”>append</span>(RMname)
<span style=“color: #75715e;”>###########################################################################################</span>
<span style=“color: #75715e;”>##Boundary Lists and vectors around room </span>
<span style=“font-weight: bold; color: #f92672;”>for</span> boundarylist <span style=“font-weight: bold; color: #f92672;”>in</span> item.<span style=“font-weight: bold; color: #ffffff;”>GetBoundarySegments</span>(options):

<span style=“font-weight: bold; color: #f92672;”>del</span> listGatherSums[:] <span style=“color: #75715e;”>####Empty subangle gathering buckets</span>
listGatherSums = [<span style=“color: #ae81ff;”>0</span>] * SubDivs <span style=“color: #75715e;”>####Create new buckets</span>

<span style=“font-weight: bold; color: #f92672;”>for</span> boundary <span style=“font-weight: bold; color: #f92672;”>in</span> boundarylist: <span style=“color: #75715e;”>####Get boundary List</span>
lcurve=boundary.Curve.<span style=“font-weight: bold; color: #ffffff;”>ToProtoType</span>() <span style=“color: #75715e;”>####Convert boundary to ‘curve’ (even lines are curves)</span>
<span style=“font-weight: bold; color: #f92672;”>try</span>: <span style=“color: #75715e;”>###Try to catch errors - if ActualArc then it will tyrhow error to next level</span>
ang=math.<span style=“font-weight: bold; color: #ffffff;”>degrees</span>(math.<span style=“font-weight: bold; color: #ffffff;”>atan2</span>(lcurve.Direction.X,lcurve.Direction.Y)) <span style=“color: #75715e;”>##Math for angle in 360d</span>
<span style=“color: #75715e;”>#clist.append(str(ang)+", "+ str(lcurve.Length)) ##Append clist with angle and directions list</span>
listGatherSums[<span style=“font-weight: bold; color: #ffffff;”>int</span>(ang/SubAng)] = listGatherSums[<span style=“font-weight: bold; color: #ffffff;”>int</span>(ang/SubAng)] +lcurve.Length <span style=“color: #75715e;”>##Add vector to direction bucket- rounds down with INT, could use round function for nearest</span>
<span style=“font-weight: bold; color: #f92672;”>except</span>:
<span style=“color: #75715e;”>##clist.append(lcurve) ##Exception - curve - add to list in meaningful way</span>
listGatherSums.<span style=“font-weight: bold; color: #ffffff;”>append</span>(lcurve)
<span style=“color: #75715e;”>###End Try Except</span>
<span style=“color: #75715e;”>###End for boundary in boundarylist</span>
clist.<span style=“font-weight: bold; color: #ffffff;”>append</span> (<span style=“color: #e6db74;”>"Buckets: subangles "</span> + <span style=“font-weight: bold; color: #ffffff;”>str</span>(SubAng)) <span style=“color: #75715e;”>##Append lists after for boundary loop</span>
clist.<span style=“font-weight: bold; color: #ffffff;”>extend</span> (listGatherSums)
<span style=“color: #75715e;”>###End for boundarylist in item.GetBoundarySegments(options)</span>
curvelist.<span style=“font-weight: bold; color: #ffffff;”>append</span>(clist)
OUT = (curvelist)</p>