Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Incorrect face normal

13 REPLIES 13
SOLVED
Reply
Message 1 of 14
gb1982
3675 Views, 13 Replies

Incorrect face normal

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. test.png

Attached is my project for your erfernce.

13 REPLIES 13
Message 2 of 14
dragos.turmac
in reply to: gb1982

Hi @gb1982,

It seems that one beam is bound to 标高2 as working plane, and the other one is unbound. Is this intended? This binding can influence the position of the FamilyInstance in WCS.

 



Turmac Dragos
Pr. SW. Engineer
Message 3 of 14
gb1982
in reply to: gb1982

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!

Message 4 of 14
dragos.turmac
in reply to: gb1982

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.



Turmac Dragos
Pr. SW. Engineer
Message 5 of 14
Revitalizer
in reply to: gb1982

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




Rudolf Honke
Software Developer
Mensch und Maschine





Message 6 of 14
Revitalizer
in reply to: gb1982

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




Rudolf Honke
Software Developer
Mensch und Maschine





Message 7 of 14
gb1982
in reply to: 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;
                }
            }

 

test.png

 

"there are six sides having FaceNormal values as expected" you mean the left face's normal of the right beam is (-1,0,0)?

Message 8 of 14
Revitalizer
in reply to: gb1982

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




Rudolf Honke
Software Developer
Mensch und Maschine





Message 9 of 14
gb1982
in reply to: 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...test.png

Message 10 of 14
Revitalizer
in reply to: gb1982

Hi,

 

when getting the solids and their faces, I draw the normals as ModelLines, starting at the faces' center points:

Normals.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

All right, this way.

 

When I pick a face, I get this result with the left one:

 

NormalsPickedLeft.png

But I get this when picking the right one:

 

NormalsPickedRight.png

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:

 

NormalsPickedRightAllSides.png

Strange. No idea.

 

 

Revitalizer

 

 




Rudolf Honke
Software Developer
Mensch und Maschine





Message 11 of 14
gb1982
in reply to: 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? ...

Message 12 of 14
Revitalizer
in reply to: gb1982

Hi,

 

I think only The Factory itself can answer the "why" question.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 13 of 14
FAIR59
in reply to: gb1982

Your comment on coping is the last piece of the puzzle.
When a familyinstance is

  • cut,
  • joined
  • coped
  • and apparently has been coped

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));
}
Message 14 of 14
gb1982
in reply to: FAIR59

Classic! Thank you all so much!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community