Using Dynamo, passing XYZs to Vector.ByTwoPoints


#1

Hi,

I have the need to generate XYZs in Python to create a vector. If you see the attached image, my python script is passing a XYZ into Start and a 0,0,0 point into End of Vector.ByTwoPoints which is returning null. What do I need to do in my code to make this work?

<span style=“color: #f92672; font-weight: bold;”>import</span> clr

<span style=“color: #75715e;”># Import RevitAPI</span>
clr.<span style=“color: #ffffff; font-weight: bold;”>AddReference</span>(<span style=“color: #e6db74;”>“RevitAPI”</span>)
<span style=“color: #f92672; font-weight: bold;”>import</span> Autodesk
<span style=“color: #f92672; font-weight: bold;”>from</span> Autodesk.Revit.DB <span style=“color: #f92672; font-weight: bold;”>import</span> *

<span style=“color: #75715e;”># Import DocumentManager and TransactionManager</span>
clr.<span style=“color: #ffffff; font-weight: bold;”>AddReference</span>(<span style=“color: #e6db74;”>“RevitServices”</span>)
<span style=“color: #f92672; font-weight: bold;”>import</span> RevitServices
<span style=“color: #f92672; font-weight: bold;”>from</span> RevitServices.Persistence <span style=“color: #f92672; font-weight: bold;”>import</span> DocumentManager
<span style=“color: #f92672; font-weight: bold;”>from</span> RevitServices.Transactions <span style=“color: #f92672; font-weight: bold;”>import</span> TransactionManager

<span style=“color: #75715e;”># Import ToDSType(bool) extension method</span>
clr.<span style=“color: #ffffff; font-weight: bold;”>AddReference</span>(<span style=“color: #e6db74;”>“RevitNodes”</span>)
<span style=“color: #f92672; font-weight: bold;”>import</span> Revit
clr.<span style=“color: #ffffff; font-weight: bold;”>ImportExtensions</span>(Revit.Elements)

doc = DocumentManager.Instance.CurrentDBDocument
app = DocumentManager.Instance.CurrentUIApplication.Application

<span style=“color: #75715e;”>#The inputs to this node will be stored as a list in the IN variable.</span>
num = IN[<span style=“color: #ae81ff;”>0</span>]
xyz = IN[<span style=“color: #ae81ff;”>1</span>]

pt = <span style=“color: #ffffff; font-weight: bold;”>XYZ</span>(xyz[<span style=“color: #ae81ff;”>0</span>][<span style=“color: #ae81ff;”>0</span>],xyz[<span style=“color: #ae81ff;”>0</span>][<span style=“color: #ae81ff;”>1</span>],num)

<span style=“color: #75715e;”>#Assign your output to the OUT variable</span>
OUT = pt

 

Thanks,

Dan


#2

Sorry for the messy message, can’t seem to clean it up. I attached the code to this reply.

Thanks again,

Dan


#3

Inside the python node you need to use Point.ByCoordinates(x,y,z) instead of Revit’s XYZ method