rotate family with dynamo
Below is a quick overview of a method to create an array of family instances on a curve and rotate them to always be perpendicular to host curve.
You will need to download a few packages to get it to work.
- Family Transform – extracts Transformation Matrix from family instances. Used to determine angle for rotation.
- Angle Between Vectors – calculates angle in radians between two vectors. used to determine angle for rotation.
- Element to ID’s – extracts family instance ID. Used with Rotate Family component.
- Rotate Family – rotates Revit family instance by a given angle (radians) around given axis (line).
There is also a component that I am calling "compare to 90, *1 or *(-1)". What I am doing there is to compare an angle to 90 degrees and if that angle is smaller it gets multiplied by 1 but if its larger i am multiplying it by -1. I am doing this to compensate for the fact that some tangents on a curve are either in the "negative" or "positive" based on whether a curve is concave or convex. However when measuring an angle between curve tangent and any other angle revit will always give you the smallest angle and never in negative degrees. Here’s a python code for that node. I am not publishing it since it’s a bit of a rough/specific application for this example thus not very useful to others:
| # Default imports | |
| import clr | |
| clr.AddReference('RevitAPI') | |
| clr.AddReference('RevitAPIUI') | |
| from Autodesk.Revit.DB import * | |
| import Autodesk | |
| import sys | |
| path = r'C:\Autodesk\Dynamo\Core' | |
| exec_path = r'C:\Autodesk\Dynamo\Core\dll' | |
| sys.path.append(path) | |
| sys.path.append(exec_path) | |
| clr.AddReference('LibGNet') | |
| from Autodesk.LibG import * | |
| #The input to this node will be stored in the IN0...INX variable(s). | |
| dataEnteringNode = IN0 | |
| lst_1 = IN0 | |
| lst_2 = IN1 | |
| result = [] | |
| for i, j in zip(lst_1, lst_2): | |
| if i <= 1.5707966327: | |
| result.append(j * 1) | |
| else: | |
| result.append(j * (-1)) | |
| #Assign your output to the OUT variable | |
| OUT = result |