Apologies, I should have done a screenshot of my graph to give you context.
You can use a Dynamo Point for IN[1]
. .ToXyz()
in the script should convert the Vector.
Perhaps add this to the imports
clr.AddReference("ProtoGeometry")
from Autodesk.DesignScript.Geometry import *
Looking into this I think there is an easier way to get the vectors. If the forward vector is F(x,y,z) we can define the ‘right’ vector as R(-y,x,0) which is a 90 degree rotation in the xy plane of the F vector. Then the up vector is the cross product - if we have roll we can rotate with F as the axis
Main python script - I have added a helper function so that the script can accept Dynamo Point
or Vector
or a Revit XYZ
import sys, clr
clr.AddReference("ProtoGeometry")
from Autodesk.DesignScript.Geometry import Vector, Point
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import ViewOrientation3D
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
uidoc = uiapp.ActiveUIDocument
def check_vec(vec):
if isinstance(vec, (Vector, Point)):
return vec.ToXyz()
return vec
perspective = UnwrapElement(IN[0]) if IN[0] else doc.ActiveView
EyePosition = check_vec(IN[1])
UpDirection = check_vec(IN[2])
ForwardDirection = check_vec(IN[3])
TransactionManager.Instance.EnsureInTransaction(doc)
NewVO = ViewOrientation3D(EyePosition, UpDirection, ForwardDirection)
perspective.SetOrientation(NewVO)
uidoc.RefreshActiveView() # Comment out if not using active view
TransactionManager.Instance.TransactionTaskDone()
OUT = perspective
Rotation of the ‘Up’ vector by the roll angle using the ‘Forward’ vector as the axis
import clr
import math
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import XYZ, Transform
f = IN[0].ToXyz()
u = IN[1].ToXyz()
roll = math.radians(IN[2]) if IN[2] else 0
OUT = Transform.CreateRotation(f, roll).OfVector(u)