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..
Solved! Go to Solution.
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..
Solved! Go to Solution.
Solved by jeremytammik. Go to Solution.
Solved by Revitalizer. Go to 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
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
Thanks a lot Revitalizer,
It is working...
Thanks a lot Revitalizer,
It is working...
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
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
Can't find what you're looking for? Ask the community or share your knowledge.