Creating a point and a vector from str read from text file


#1

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


#2

I believe that this may be easier with OOTB nodes.


#3

Hi Jacob,

I had spotted that an OOTB node could create the view. I couldn’t locate an OOTB node to tell me the origin and view direction for part1.

I’ve reworked the second script to simply read the text file and output floats for creating the point and vector with OOTB nodes.

Next problem, our files are linked by shared coordinates, so my first attempt did successfully create a view, it was wildly misaligned. I’ve attempted to write into the text file the survey point and then create a vector two point between survey points in the differing files to adjust for this.

Again its wildly different. Anyway will have to pick this up later.

Here is the current state of progress …

SetViewOrientation_OOTB.dyn (17.4 KB)
GetViewOrientation001.dyn (8.8 KB)


#4

Look into the View.Plane node as I believe it has enough to get you there.