Convert Autodesk.Revit.DB.PlanarFace

Been asked before, but it seems that I don’t get it working …

I have a list of 5 Autodesk.Revit.DB.PlanarFace which I want to check if they are parallel to eachother.

So it seems to me I have to convert the term PlanarFace to something I can use in Dynamo?
If so: ToProtoType / ToRevitType aren’t working …

If it is just to check if they are parallel, would be enough by comparing their FaceNormal vectors? Converting to Dynamo surface geometry is quite an expensive task.

Okay @alvpickmans , I for sure don’t want to make the script “heavy” if not needed!

So sticking with python… that rises the next question: how do I compare the FaceNormal?

PlanarFace.Normal … PlanarFace object has no attribute Normal …?

You need to use PlanarFace.FaceNormal property, which gives you the XYZ normal vector for that face.

As far as I remember, two vectors are parallel if their dot product equals to 1. Revit XYZ vectors have the DotProduct method which you can use to compare them.

@alvpickmans, thanks. FaceNormal: check.

DotProduct: doens’t seem to be recognized?

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

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

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

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# INPUT ELEMENTS FROM REVIT

a = IN[0]
b = []
for n in a:
	b.append(n.FaceNormal)

c = DotProduct(b)

OUT = b,c

So: IN is a list of planarfaces. …

Can you share your code and test file?

@alvpickmans I just ninja’d you

without trying this myself, I assume DotProduct method will need to be called from a XYZ vector instance and compared to another vector in order to perform the calculation.

v1 = #vector 1
v2 = #vector 2

dotProduct = v1.DotProduct(v2)

Depending on your final goal, the code will be implemented on different ways…could you provide a Revit test file and waht you want to achieve? :slight_smile:

Alternatively you can go old fashioned and calculate the dotproduct using standard mathematical constructs:
(Thanks to: https://stackoverflow.com/questions/35208160/dot-product-in-python-without-numpy)

def dot(v1, v2):
return sum(x*y for x,y in zip(v1,v2))

p = dot([1,2,3], [4,5,6])

@Jonathan.Olesen, can’t use * with vectors :confused:

@alvpickmans, yes I agree that is how it is used. So I guess since I have a list with vectors I have to cross check each value with that list.

a = IN[0]

b = a[0].DotProduct(a[1])

OUT = b

but this is only for one

a = IN[0]

b = combinations(a)

OUT = b

???

Hi @3Pinter I don’t see why my method cannot be used with vectors?
image

V1 = IN[0]
V2 = IN[1]

def dot(v1,v2):
return sum(x*y for x,y in zip(v1,v2))

p = dot([V1.X,V1.Y,V1.Z],[V2.X,V2.Y,V2.Z])

OUT = p

@Jonathan.Olesen @alvpickmans

Because I have to check whether the vectors are parralel. So the list I have (5 planes) have 2 sets of parallels. Those I want as a list.

So I believe I would have to:

a = IN[0]
def dot(v1, v2):
	return sum(x*y for x,y in zip(v1,v2))

p = dot(a,a)

OUT = p

where a = a list:
[0] (-1, 0, 0)
[1] (0, 0, 1)
[2] (1,0,0)
[3] (0.0,-1)
[4] (0,-1,0)

Makes sense? Or am I making no sense at all?

I mean a list a 5 means 15 unique combinations.
(00,01,02,03,04,11,12,13,14,22,23,24,33,34,44)

a = IN[0]

b = []
stepcounter = 0
for step1 in a:	
	for i in range(len(a)):		
		b.append(step1.DotProduct(a[i]))

OUT = b

This gives me ALL the possible combinations (including doubles) … now I have to reduce the loop…

So what you wish is to get the output of the 15 unique combinations?
like so:
image

@Jonathan.Olesen you ninja’d me. Ill have a look at it.

1 Like

ok. 15 unique combintions done. But shouldn’t it be:
List:
[0]
—[0] 0
—[1] -1
—[2] 0
—[3] 0
[1]
etcetc

So I can get a list which vector is parallel to which other vector in that list.

Like so:
image
image

The first “1” is the list compared to itself, this can be avoided using “x+1” instead of “x” in the second loop.

thanks, will look at it. Yeah comparing itself … I added the IsParralel.pop(0) already, but your suggestion is more solid!

Not sure if it helps since you wanna go python, but surface.normalatparameter and vector.almostequalto should do the trick with nodes.