Get Z vector from a curve - python

Hi,

can anyone help me isolate the Z vector in this python script?

This outputs the element curve of in my case a duct.

If i can get the Z Vector or Z values of start and end points i should be able to isolate any vertical ducts.

import clr

#Import Revit Nodes
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference ("DSCoreNodes")
import DSCore
from DSCore import *

doc = DocumentManager.Instance.CurrentDBDocument
elements = UnwrapElement(IN[0])

curves = list()
vertical = list()
spoint = list()
epoint = list()

for element in elements:
	loc = element.Location
	if loc.ToString() == 'Autodesk.Revit.DB.LocationCurve':
		curvepoints = (loc.Curve.GetEndPoint(0).ToPoint(),loc.Curve.GetEndPoint(1).ToPoint())
		curves.append(loc.Curve.ToProtoType())

OUT = curves
#OUT = vertical

any help would be much appreciated!

Thanks,

You can get a Z value of a point easily before you convert it to Dynamo geometry. Like so:

p = curve.GetEndPoint(0)
z = p.Z

However you can check verticality by using a cross product against a global Z vector:

isVertical = XYZ(0,0,1).CrossProduct(curve.GetEndPoint(1)-curve.GetEndPoint(0)).IsAlmostEqualTo(XYZ(0,0,0))
1 Like