DirectShape from floor faces

DirectShape from floor faces

desdinova
Advocate Advocate
1,864 Views
4 Replies
Message 1 of 5

DirectShape from floor faces

desdinova
Advocate
Advocate

 

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

            IList<Reference> references = uidoc.Selection.PickObjects(Autodesk.Revit.UI.Selection.ObjectType.Face);

            IList<IList<IList<XYZ>>> all = new List<IList<IList<XYZ>>>();

            foreach (Reference reference in references)
            {
                Face face = doc.GetElement(reference).GetGeometryObjectFromReference(reference) as Face;

                IList<IList<XYZ>> loopVertices = new List<IList<XYZ>>();

                PlanarFace planarFace = face as PlanarFace;

                if(!planarFace.FaceNormal.IsAlmostEqualTo(XYZ.BasisZ))
                {
                    EdgeArrayArray edgeArrayArray = planarFace.EdgeLoops;

                    foreach (EdgeArray ea in edgeArrayArray)
                    {
                        IList<XYZ> loops = new List<XYZ>();

                        foreach (Edge e in ea)
                        {
                            Curve c = e.AsCurve();
                            loops.Add(c.GetEndPoint(0));
                        }

                        loopVertices.Add(loops);
                    }
                }
                all.Add(loopVertices);
            }

            CreateTessellatedShape(doc, all, ElementId.InvalidElementId);

            return Result.Succeeded;
        }
public void CreateTessellatedShape(Document doc, IList<IList<IList<XYZ>>> all, ElementId materialId)
        {
            TessellatedShapeBuilder builder = new TessellatedShapeBuilder();

            builder.OpenConnectedFaceSet(true);

            foreach (IList<IList<XYZ>> loopVertices in all)
            {
                TessellatedFace tessellatedFace = new TessellatedFace(loopVertices, materialId);

                if (builder.DoesFaceHaveEnoughLoopsAndVertices(tessellatedFace))
                {
                    builder.AddFace(tessellatedFace);
                }
            }

            builder.CloseConnectedFaceSet();
            builder.Target = TessellatedShapeBuilderTarget.AnyGeometry;
            builder.Fallback = TessellatedShapeBuilderFallback.Mesh;
            builder.Build();

            TessellatedShapeBuilderResult result = builder.GetBuildResult();

            using (Transaction t = new Transaction(doc, "Create tessellated direct shape"))
            {
                t.Start();
                DirectShape ds = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_Floors));
                ds.ApplicationId = "Application id";
                ds.ApplicationDataId = "Geometry object id";
                ds.SetShape(result.GetGeometricalObjects());
                t.Commit();
            }
        }

 

Hello friends,

I want to create one direct shape from selected floor faces

The bottom face of floor is ok but side faces are not created properly 

How can I solve this

Thanks in advance..

0 Likes
Accepted solutions (2)
1,865 Views
4 Replies
Replies (4)
Message 2 of 5

Revitalizer
Advisor
Advisor
Accepted solution

Hi,

 

replace

 

Curve c = e.AsCurve();

 

by

 

Curve c = e.AsCurveFollowingFace();

 

I think the reason for the error is that you just get duplicate vertices by using e.AsCurve() since the direction of the edges is not as you expect.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 3 of 5

Revitalizer
Advisor
Advisor

Hi,

 

see also here:

http://thebuildingcoder.typepad.com/blog/2010/01/face-edges.html

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 4 of 5

desdinova
Advocate
Advocate

Thanks a lot Revitalizer,

It is working...

 

0 Likes
Message 5 of 5

jeremytammik
Autodesk
Autodesk
Accepted solution

If you want to create direct shapes from anything at all, you might want to check out the flattener:

 

http://thebuildingcoder.typepad.com/blog/2015/11/flatten-all-elements-to-directshape.html

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder