BuildingCoder.Creator.DrawFaceTriangleNormals C# (CSharp) Method

DrawFaceTriangleNormals() public method

public DrawFaceTriangleNormals ( Face f ) : void
f Face
return void
        public void DrawFaceTriangleNormals( Face f )
        {
            Mesh mesh = f.Triangulate();
              int n = mesh.NumTriangles;

              string s = "{0} face triangulation returns "
            + "mesh triangle{1} and normal vector{1}:";

              Debug.Print(
            s, n, Util.PluralSuffix( n ) );

              for( int i = 0; i < n; ++i )
              {
            MeshTriangle t = mesh.get_Triangle( i );

            XYZ p = ( t.get_Vertex( 0 )
              + t.get_Vertex( 1 )
              + t.get_Vertex( 2 ) ) / 3;

            XYZ v = t.get_Vertex( 1 )
              - t.get_Vertex( 0 );

            XYZ w = t.get_Vertex( 2 )
              - t.get_Vertex( 0 );

            XYZ normal = v.CrossProduct( w ).Normalize();

            Debug.Print(
              "{0} {1} --> {2}", i,
              Util.PointString( p ),
              Util.PointString( normal ) );

            CreateModelLine( _doc, p, p + normal );
              }
        }

Usage Example

        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication app   = commandData.Application;
            UIDocument    uidoc = app.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            List <Element> floors = new List <Element>();

            if (!Util.GetSelectedElementsOrAll(
                    floors, uidoc, typeof(Floor)))
            {
                Selection sel = uidoc.Selection;
                message = (0 < sel.GetElementIds().Count)
          ? "Please select some floor elements."
          : "No floor elements found.";
                return(Result.Failed);
            }

            List <Face> faces = new List <Face>();
            Options     opt   = app.Application.Create.NewGeometryOptions();

            foreach (Floor floor in floors)
            {
                GeometryElement geo = floor.get_Geometry(opt);
                //GeometryObjectArray objects = geo.Objects; // 2012
                //foreach( GeometryObject obj in objects ) // 2012
                foreach (GeometryObject obj in geo) // 2013
                {
                    Solid solid = obj as Solid;
                    if (solid != null)
                    {
                        GetSideFaces(faces, solid);
                    }
                }
            }

            int n = faces.Count;

            Debug.Print(
                "{0} side face{1} found.",
                n, Util.PluralSuffix(n));

            using (Transaction t = new Transaction(doc))
            {
                t.Start("Draw Face Triangle Normals");
                Creator creator = new Creator(doc);
                foreach (Face f in faces)
                {
                    creator.DrawFaceTriangleNormals(f);
                }
                t.Commit();
            }
            return(Result.Succeeded);
        }
All Usage Examples Of BuildingCoder.Creator::DrawFaceTriangleNormals