Product help with community knowledge

### Page statistics

2200 views4 edit(s)3083 characters(s) Page last modified 10:14, 3 Dec 2012 by lillian.smith

# Example 06b: Connect Two Point Arrays with Python

Note: you must have Python installed to use the Python script node.  See Installation and Getting Started.

Goal: Learn how to pass lists and data structures into the Python scripting node. Connect the dots between to sub-divided curves by passing in two collections of points and having a Python script create new line between each pair of points.

1. From Vasari 2.5, Click  > (Open).
2. Navigate to  C:\VasariWIP\2-5\Dynamo\Samples Open Mass with 2 Curves.rfa from theSamples directory.
3. Go to Add-ins tab and launch Dynamo
4. From the Dynamo File Menu, go to File/Samples/ 7. Connect Two Point Arrays. You should see this workspace appear:

Using a python script to make lines between two collections of points

1. Select the curves using the Curve By Selection Nodes in Dynamo
2. Press Run. You should see a set of lines created between the points

So what is happening here? Dynamo nodes are creating two collections of points, one list per selected curve.  The List node then takes those two lists and creates a new list around them, a list of lists.  This List is then passed into the IN port in the Python node. The python script then unpacks the lists and iterates through the elements to create new lines. A line is created between pairs of points.  Here is the Python script:

 import math   doc = __revit__.ActiveUIDocument.Document app = __revit__.Application   RefPointList1 = IN[0] RefPointList2 = IN[1] count = IN[2]   max = int(count)   #use for loop to connect two series of points #if count > len(RefPointList1): max = len(RefPointList1)   for i in range(0,max):     pt1 = RefPointList1[i]     pt2 = RefPointList2[i]     refptarr = ReferencePointArray()     refptarr.Append(pt1)     refptarr.Append(pt2)     crv = doc.FamilyCreate.NewCurveByPoints(refptarr)

Python script to connect two lists of points