Note: you must have Python installed to use the Python script node. See Installation and Getting Started.
Goal: Learn about Python scripting and the Python Script node. Learn how to pass information into that node, have the python script create some elements and then pass execution back to Dynamo.
This example covers how to user the Python Script Node in Dynamo. Don’t worry if you are not a programmer! Learning how to program in Python is the basis for another class, we will just be covering the highlights here. The Python Scripting Node requires IronPython to be installed on the machine.
A Python Script Node can take in input from other Dynamo nodes
Sine Wave plotted by the Python Script Node inside Dynamo
| #derived from Nathan Miller's example #http://theprovingground.wikidot.com/...-api-py-curves
import math
doc = __revit__.ActiveUIDocument.Document app = __revit__.Application
beginPoint = IN[0] endPoint = IN[1] lineRefPointArray = ReferencePointArray() lineRefPointArray.Append(beginPoint) lineRefPointArray.Append(endPoint) crv = doc.FamilyCreate.NewCurveByPoints(lineRefPointArray) crvRef = crv.GeometryCurve refptarr = ReferencePointArray()
#use for loop to create a series of points steps = 20 for i in range(0,steps+1): pt = crvRef.Evaluate(float(i)/steps,1) # returns and XYZ x = pt.X y = pt.Y z = pt.Z + math.sin(i)*steps myXYZ = XYZ(x,y,z) refPt = doc.FamilyCreate.NewReferencePoint(myXYZ) refptarr.Append(refPt) crv2 = doc.FamilyCreate.NewCurveByPoints(refptarr)
|
Python script to make a sine wave between two points
Using Python script to make a sine wave along a curve
| #derived from Nathan Miller's example #http://theprovingground.wikidot.com/...-api-py-curves
import math
doc = __revit__.ActiveUIDocument.Document app = __revit__.Application
crv = IN crvRef = crv.GeometryCurve refptarr = ReferencePointArray()
#use for loop to create a series of points steps = 20 for i in range(0,steps+1): pt = crvRef.Evaluate(float(i)/steps,1) # returns and XYZ x = pt.X y = pt.Y z = pt.Z + math.sin(i)*steps myXYZ = XYZ(x,y,z) refPt = doc.FamilyCreate.NewReferencePoint(myXYZ) refptarr.Append(refPt) crv2 = doc.FamilyCreate.NewCurveByPoints(refptarr)crv2 = doc.FamilyCreate.NewCurveByPoints(refptarr)
|
Python script to make a sine wave along a curve