# Normal vector Revit API

**URL:** <https://forum.dynamobim.com/t/normal-vector-revit-api/89582>\
**Category:** Developers\
**Tags:** revit, python\
**Created:** [May 14, 2023, 1:46pm UTC](https://forum.dynamobim.com/t/normal-vector-revit-api/89582 "2023-05-14T13:46:10Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![REDO10](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@REDO10](https://forum.dynamobim.com/u/REDO10)\
**Post date:** [May 14, 2023, 1:46pm UTC](https://forum.dynamobim.com/t/normal-vector-revit-api/89582/1 "2023-05-14T13:46:10Z")

</div>

Hi All,

How to get Normal curve with Revit API if I have the following code?

```auto
St_pt = XYZ(2,2,0)
End_pt = XYZ(2,2,5)
line = Line.CreateBound(St_pt , End_pt )

```

Thanks.

---

<div class="post-metadata">

**Author:** ![GavinNicholls](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/gavinnicholls/32/190442_2.png) [@GavinNicholls](https://forum.dynamobim.com/u/GavinNicholls)\
**Post date:** [May 14, 2023, 2:39pm UTC](https://forum.dynamobim.com/t/normal-vector-revit-api/89582/2 "2023-05-14T14:39:00Z")

</div>

You can use the ComputeDerivatives method from the Curve class, then interrogate the second derivative of the tangent vector by assessing the BasisY of the returned Transform object.

> **[ComputeDerivatives Method](https://www.revitapidocs.com/2015/93092a44-85f1-15be-a618-817c763f8994.htm)**
>
> Online Documentation for Autodesk's Revit API: 2015, 2016, 2017, 2017.1, 2018

---

<div class="post-metadata">

**Author:** ![christian.stan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/christian.stan/32/166296_2.png) [@christian.stan](https://forum.dynamobim.com/u/christian.stan)\
**Post date:** [May 14, 2023, 3:29pm UTC](https://forum.dynamobim.com/t/normal-vector-revit-api/89582/3 "2023-05-14T15:29:35Z")

</div>

Hello,  
here is what i tried  
Dynamo makes our job easier all the same

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/0/e0744785eb98bd298a07b1333867a02665d06377.png)

```auto
import sys
import clr
clr.AddReference("RevitAPI")
import Autodesk 
from Autodesk.Revit.DB import *
St_pt = XYZ(2,2,0)
End_pt = XYZ(2,2,5)
vec_a=XYZ(2,2,0)
line = Line.CreateBound(St_pt , End_pt)
a=XYZ(line.ComputeDerivatives(0.0,True))
vec_tang=a.BasisX
vec_norm=a.BasisY
vec_binorm=a.BasisZ
d=line.Direction
my_dico={"Point Revit-->":St_pt,
"Vector Revit-->":vec_a
,"Line Revit-->":line,
"vec_tang-->":vec_tang,
"vec_norm-->":vec_norm,
"vec_binorm-->":vec_binorm,
"line_direction-->":d}
OUT = my_dico

```

Cordially  
christian.stan

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [May 14, 2023, 6:27pm UTC](https://forum.dynamobim.com/t/normal-vector-revit-api/89582/4 "2023-05-14T18:27:25Z")

</div>

Lines don’t have plane, so it’s not works correctly with `ComputeDerivatives()` (return a Zero Vector)

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/d/a/da5bfbd4089097b0c11ea4b7cadada14b9f2bb38.png)

a solution with the crossproduct (with BasisZ vector)

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/9/d/9d04af9672c8c0f24c12e8f812dcd63010d4994b.png)

```auto
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import Autodesk.DesignScript.Geometry as DS 

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

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion) 

st_pt = XYZ(2,2,0)
end_pt = XYZ(5,9,1)

line = Line.CreateBound(st_pt , end_pt)
vectorL = line.Direction
vectorN = vectorL.CrossProduct(XYZ.BasisZ)

OUT = line.ToProtoType(), vectorN.ToVector()

```

---

<div class="post-metadata">

**Author:** ![REDO10](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@REDO10](https://forum.dynamobim.com/u/REDO10)\
**Post date:** [May 14, 2023, 6:38pm UTC](https://forum.dynamobim.com/t/normal-vector-revit-api/89582/5 "2023-05-14T18:38:39Z")

</div>

@christian.stan

I’ve run your script and I got this error!!??

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/8/a8146100d23379b7636e49a435a21adf24344032.png)

Thanks.

---

<div class="post-metadata">

**Author:** ![christian.stan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/christian.stan/32/166296_2.png) [@christian.stan](https://forum.dynamobim.com/u/christian.stan)\
**Post date:** [May 14, 2023, 6:43pm UTC](https://forum.dynamobim.com/t/normal-vector-revit-api/89582/6 "2023-05-14T18:43:43Z")

</div>

hello, I have to read the small lines with a rested head, I think the 2nd script is more correct than the first, even if not adapted to the lines

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/c/0c91c9d9c4efb188c19dd9e012301b945874bcd0.png)

```auto
import sys
import clr
clr.AddReference("RevitAPI")
import Autodesk 
from Autodesk.Revit.DB import *
St_pt= XYZ(1,1,1)
End_pt= XYZ(5,5,5)

line = Line.CreateBound(St_pt,End_pt)
a=line.ComputeDerivatives(0.0,True)
vec_tang=a.BasisX
vec_norm=a.BasisY
vec_binorm=a.BasisZ
d=line.Direction
my_dico={"Point Revit-->":St_pt,
"Line Revit-->":line,
"vec_tang-->":vec_tang,
"vec_norm-->":vec_norm,
"vec_binorm-->":vec_binorm,
"line_direction-->":d}
OUT = my_dico,a.Origin

```

Cordially  
christian.stan

---

<div class="post-metadata">

**Author:** ![REDO10](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@REDO10](https://forum.dynamobim.com/u/REDO10)\
**Post date:** [May 14, 2023, 7:02pm UTC](https://forum.dynamobim.com/t/normal-vector-revit-api/89582/7 "2023-05-14T19:02:48Z")

</div>

@c.poupin

We can’t got a normal vector if the curve is straight??

```auto
st_pt = XYZ(2,2,0)
end_pt = XYZ(2,2,5)

line = Line.CreateBound(st_pt , end_pt)
vectorL = line.Direction
vectorN = vectorL.CrossProduct(XYZ.BasisZ)

OUT = vectorN

```

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/1/11334daac48b41b6c5659564571a83b17ea46180.png)

So how the normal vector is obtained in the case of straight rebar? (ex: column rebar)

Thanks.

---

<div class="post-metadata">

**Author:** ![christian.stan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/christian.stan/32/166296_2.png) [@christian.stan](https://forum.dynamobim.com/u/christian.stan)\
**Post date:** [May 14, 2023, 7:18pm UTC](https://forum.dynamobim.com/t/normal-vector-revit-api/89582/8 "2023-05-14T19:18:46Z")

</div>

it seems to me that as your direction vector is in fact your tangent vector as you make a cross product of vector Z and itself is carried by vector Z, they are therefore collinear this is how you demonstrate from my old memories of math, you have to select another XYZ.BasisX or Y will do I think, I’m testing…  
edit:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/e/1e6e2b22ccdbf537e628ec3fc5ce623f7d60f515.png)

Cordially  
christian.stan

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [May 14, 2023, 7:25pm UTC](https://forum.dynamobim.com/t/normal-vector-revit-api/89582/9 "2023-05-14T19:25:55Z")

</div>

the Normal of a vertical line could be any vector based on the XY plane

---

<div class="post-metadata">

**Author:** ![REDO10](https://avatars.discourse-cdn.com/v4/letter/r/7cd45c/32.png) [@REDO10](https://forum.dynamobim.com/u/REDO10)\
**Post date:** [May 14, 2023, 7:32pm UTC](https://forum.dynamobim.com/t/normal-vector-revit-api/89582/10 "2023-05-14T19:32:49Z")

</div>

@c.poupin

> [@c.poupin](#):
>
> the Normal of a vertical line could be any vector based on the XY plane

but how we can extract it from the curve itself if ths Cross Product give 0 ??

Thanks.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [May 14, 2023, 8:32pm UTC](https://forum.dynamobim.com/t/normal-vector-revit-api/89582/11 "2023-05-14T20:32:50Z")

</div>

There isn’t a consistent normal for a line; as @c.poupin noted, it could be anything without a Z component, and the Tangent would be any vector perpendicular to that.

> [@REDO10](#):
>
> So how the normal vector is obtained in the case of straight rebar? (ex: column rebar)

Gather the normal from the work plane which defined the element, it’s sketch, or the host.

---

<div class="post-metadata">

**Author:** ![christian.stan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/christian.stan/32/166296_2.png) [@christian.stan](https://forum.dynamobim.com/u/christian.stan)\
**Post date:** [May 14, 2023, 8:50pm UTC](https://forum.dynamobim.com/t/normal-vector-revit-api/89582/12 "2023-05-14T20:50:34Z")

</div>

I think that as dynamo provides one, it is possible via the api  
looking at the dynamo nodes or maybe using them

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/e/0efdd322421bcf4634fab84c6d620502b0e2fd22.png)  
edit:but it’s true that when you have a face it’s better to define a normal  
Cordially  
christian.stan

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [May 14, 2023, 11:17pm UTC](https://forum.dynamobim.com/t/normal-vector-revit-api/89582/13 "2023-05-14T23:17:58Z")

</div>

Yeah - the Dynamo geometry engine makes some assumptions about what the normal is; however that geometry library isn’t in the Revit API, and the assumed normal os often incorrect (in particular with vertical curves).

---

<div class="post-metadata">

**Author:** ![Thomas\_Mahon](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/thomas_mahon/32/64209_2.png) [@Thomas\_Mahon](https://forum.dynamobim.com/u/Thomas_Mahon)\
**Post date:** [May 15, 2023, 5:31am UTC](https://forum.dynamobim.com/t/normal-vector-revit-api/89582/14 "2023-05-15T05:31:42Z")

</div>

Line has a Direction property so:

```auto
St_pt = XYZ(2,2,0)
End_pt = XYZ(2,2,5)
line = Line.CreateBound(St_pt , End_pt )
direction = line.Direction.Normalize();

```

For a more general purpose use, i.e. any curve, do what’s being suggested above:

1. Compute the derivatives.
2. Get the `BasisX` of the returned transform.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [May 15, 2023, 6:13am UTC](https://forum.dynamobim.com/t/normal-vector-revit-api/89582/15 "2023-05-15T06:13:56Z")

</div>

> [@Thomas\_Mahon](#):
>
> `line.Direction`

Wouldn’t this be the tangent, not the normal?

---

<div class="post-metadata">

**Author:** ![Thomas\_Mahon](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/thomas_mahon/32/64209_2.png) [@Thomas\_Mahon](https://forum.dynamobim.com/u/Thomas_Mahon)\
**Post date:** [May 15, 2023, 6:28am UTC](https://forum.dynamobim.com/t/normal-vector-revit-api/89582/16 "2023-05-15T06:28:55Z")

</div>

Yep, I made the wrong assumption re the OP! @c.poupin is the solution in that case: @REDO10 you need to know your up-vector (or plane normal) to be able to compute a normal from a line.

---

<div class="post-metadata">

**Author:** ![Organon](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/organon/32/161404_2.png) [@Organon](https://forum.dynamobim.com/u/Organon)\
**Post date:** [May 15, 2023, 2:24pm UTC](https://forum.dynamobim.com/t/normal-vector-revit-api/89582/17 "2023-05-15T14:24:20Z")

</div>

Hello,

1.- Create a plane: CreateByNormalAndOrigin(CurveDirection, Origin)  
2.- Get the XVec property of the plane.  
3.- Get the cross product: XVec.CrossProduct(CurveDirection)

Regards,
