Hi all,
I am wanting to orientate two 2d views between files. I have two scripts, one which will get the origin and view direction of the source view and write these to a text file
Then a second script which reads the information and sets the origin and view direction in the second file.
My issue is trying to generate the point and vector in the second script. I am getting the exception below when trying to us ToVector or the equivalent for ToPoint
Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File "<string>", line 22, in <module>
AttributeError: 'type' object has no attribute 'Create'
Could someone please help to construct this point and vector.
Also as a side note, i found that the ViewOrientation3D.ForwardPosition appears to be the reverse vector of View3D.ViewDirection. I have stumbled across this and was a bit surprised, was wondering if my view would be reversed, but I’ll cross that bridge when i get to it. I imagine using the same functions in both get and set scripts would be most sensible, I’ll normalise them later on if it causes an issue, but creating the points and vectors is issue number one.
Script 1: Get View Orientation
clr.AddReference(“RevitServices”)
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
active_view = doc.ActiveView
text_file = open("Q:\USER\Jean-Paul Teal\Dynamo\ViewOrientation\ViewOrientation.txt", "w")
orientation = active_view.GetOrientation()
eye_pos = orientation.EyePosition
forward_vector = orientation.ForwardDirection
text_file.write(str(eye_pos))
text_file.write("/")
text_file.write(str(forward_vector))
text_file.close()
#Assign your output to the OUT variable.
OUT = [eye_pos, forward_vector]
Script 2 : Set View
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
active_view = doc.ActiveView
text_file = open("Q:\USER\Jean-Paul Teal\Dynamo\ViewOrientation\ViewOrientation.txt", "r")
info = text_file.readline()
text_file.close()
info = info.split("/")
eye_pos = info[0]
view_origin = Point.Create(eye_pos)
#view_direction = info[1]
#view_direction.ToVector()
TransactionManager.Instance.EnsureInTransaction(doc)
#active_view.Origin(eye_pos)
#active_view.ViewDirection(view_direction)
TransactionManager.Instance.TransactionTaskDone()
OUT = view_origin
Thank you all