I’ve been creating a family that contains several parts that need to be placed seperately, I managed to streamline a lot of that using Sastrugi’s pick points on worklplane (thanks a ton for that one @Ewan_Opie) as well as using this great python script which creates pop up window from which you can get data (I’m still having projects in Revit 2017 so making use of a more advanced Dynamo Player isn’t really an option).
Anyway, with placing the parts I’ve ran into one problem: the angle of the family. I’ve already tested it with angles I put in manually and it has worked out just fine using ‘FamilyInstance.SetRotation’ and some other calculations. It would however be a whole lot easier if I could just find the angle of the current view. If it’s even possible, it would help me out quite a lot.
This python will give you an XYZ that can be used for vectors. Basically it is a vector from the target of the active view to ‘you’, so in a plan view, it would be a vector (0,0,1), and in a 3d view it will be based on the angle you are looking at.
# Enable Python support and load DesignScript library
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
# The inputs to this node will be stored as a list in the IN variables.
direct = doc.ActiveView.ViewDirection
pt = Point.ByCoordinates(direct.X, direct.Y, direct.Z)
OUT = pt
First time trying this and using the iterators but this seemed to work:
# Enable Python support and load DesignScript library
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
# The inputs to this node will be stored as a list in the IN variables.
activeview = doc.ActiveView
cropmanager = activeview.GetCropRegionShapeManager()
shape = cropmanager.GetCropShape()[0]
iter = shape.GetCurveLoopIterator()
lines = []
while iter.MoveNext():
curve = iter.Current
ept = curve.GetEndPoint(0)
spt = curve.GetEndPoint(1)
dynEPT = Point.ByCoordinates(ept.X, ept.Y, ept.Z)
dynSPT = Point.ByCoordinates(spt.X, spt.Y, spt.Z)
newline = Line.ByStartPointEndPoint(dynEPT, dynSPT)
lines.append(newline)
OUT = lines
I am leaving the office for the night so I can’t help any more until tomorrow.
Looks good. If you wanted to simplify it further, instead of creating points, then lines, then vectors, and finally an X and y value, just take ept.X - spt.X and ept.Y - spt.Y to get the X and y values.
It works just fine now but I have a continueing question still.
The python scripts picks out the cropbox very effectively, but there will also be cases where the cropbox won’t be there, in which case I get a null output.
Changing the null output into 0 works fine in all those cases and I can easily do that via Dynamo (angle==null?0:angle). I do however still get a warning in that case. Is there a good way to get that done within the python node to avoid a warning?