I created two beams through different codes. Their FamilySymbols are the same. But their left faces' (marked as red in pic)normal are different!
The face normal of the left beam is the same as I expected(-1,0,0).
The face normal of the right beam is wriong to me and I don't konw why.
Attached is my project for your erfernce.
Solved! Go to Solution.
Solved by FAIR59. Go to Solution.
Hi dragos.turmac, Thanks for your quick response!
Bounding to a working plane is not my intention.
For the both beams I used Instance = Doc.Create.NewFamilyInstance(line, FamilySymbol, Level, StructuralType.Beam) to create them.
How can i avoid bounding to a working plane when creaing? Why and how working plane influence the FamilyInstance? If I can't change the way of creating the right beam how can i get the correct face normal like the left beam? Thanks!
You can try passing null for Level. Unfortunately it's not explicitly mentioned in the documentation, but the Level parameter is optional.
The beam, after all, it is a family; like every family, it has a local coordinate system. If you bind it to a plane, than it's LCS is might no longer be identical to WCS; it's local Z axis will correspond to the Z axis of the reference plane.
What you are seeing is the beam's face normal in LCS, that's why they differ even if they point in the same WCS direction.
Hi,
in the RevitAPI.chm it says:
PlanarFace.FaceNormal property
This property is the "face normal" vector, and thus should return a vector consistently pointing out of the solid that this face is a boundary for (if it is a part of a solid).
There is also this method:
Face.ComputeNormal()
It will always be oriented to point out of a solid that contains the face.
So the answer is already given in the documentation.
Revitalizer
Hi,
I've downloaded your sample file and investigated the FaceNormals.
For each of the two Elements, there are six sides having FaceNormal values as expected, all pointing outwards (making my previous post obsolete).
May it be that you compare the faces by index, meaning the first face in the left element's face list is compared to the first face in the second one's face list ?
The geometry objects are not returned in order but randomized.
As far as I can see, there is no problem at all.
Revitalizer
Hi dragos.turmac,
I passed null for Level and the right beam was bound to no working plane this time. But both beams' faces' normal are the same as previous.
New rvt file is atteched for your reference.
Hi Revitalizer,
I understand your points and thank you. Below is my test code to calculate the face normal and snapshot of the result. I was not using index to get the face.
Reference refFace = null; while (true) { try { refFace = sel.PickObject(ObjectType.Face, "select a face"); Element selectedElement = Doc.GetElement(refFace); GeometryObject selectedGeoObject = selectedElement.GetGeometryObjectFromReference(refFace); Face selectedFace = selectedGeoObject as Face; PlanarFace selectedPlanarFace = selectedFace as PlanarFace; BoundingBoxUV box = selectedFace.GetBoundingBox(); UV faceCenter = (box.Max + box.Min) / 2; XYZ computedFaceNormal = selectedFace.ComputeNormal(faceCenter).Normalize(); XYZ faceNormal = selectedPlanarFace.FaceNormal; MessageBox.Show($"computedFaceNormal: {computedFaceNormal.ToString()}, faceNormal: {faceNormal.ToString()}"); } catch (Autodesk.Revit.Exceptions.OperationCanceledException e) { return Result.Cancelled; } }
"there are six sides having FaceNormal values as expected" you mean the left face's normal of the right beam is (-1,0,0)?
Hi,
yes, I've just read the solid's faces via RevitLookup.
For both of the elements, there were six PlanarFaces, each with perfect FaceNormal values.
May it be that the selection function itself returns a false face ?
Seems to be the front face instead of the displayed lateral one.
Revitalizer
Hi,
MessageBox.Show($"computedFaceNormal: {computedFaceNormal.ToString()}, faceNormal: {faceNormal.ToString()}, Area: {selectedFace.Area.ToString()}");
I tested it again. The area are correct, but the face normal...
Hi,
when getting the solids and their faces, I draw the normals as ModelLines, starting at the faces' center points:
All right, this way.
When I pick a face, I get this result with the left one:
But I get this when picking the right one:
What does it mean ?
In fact, the face returned is not transformed to the project context, the solid resides around the 0/0/0 project origin.
I've drawn the faces' boundaries, too:
Strange. No idea.
Revitalizer
Hi,
I did further investigation. I found that I've added coping on the left beam before. So when I adding coping on the right one it works right! Why? ...
Hi,
I think only The Factory itself can answer the "why" question.
Revitalizer
Your comment on coping is the last piece of the puzzle.
When a familyinstance is
Revit has to calculate the solids of the instance "in situ" as it will be different from the solids from the family definition. So the normal of the face will be relative to the project.
In all (??) other cases Revit treats the solids as "instances" of the solids from the family definition. And by some Revit-logic, when asked for Face.ComputeNormal() it gives the normal relative to the family. Quirkier still it gives the Face.Origin in project coordinates.
So with familyinstances that are not cut, joined or coped, you need to transform the faceNormal to project coordinates.
As you have a reference to the face you can easily test for this condition:
refFace.ConvertToStableRepresentation(doc).Contains("INSTANCE")
So add this to your code:
if (refFace.ConvertToStableRepresentation(doc).Contains("INSTANCE")) { Transform trans = (selectedElement as FamilyInstance).GetTransform(); computedFaceNormal = trans.OfVector(computedFaceNormal); faceNormal =trans.OfVector( faceNormal)); }