im back 😉 so i somehow manage to get it to work, but for single polyline only, any idea? i supposed i need to group them by layer? just not sure how to do that 😕
Thanks.
public void Command(UIDocument uidoc, Document doc)
{
Reference cad = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element);
if (cad != null)
{
Element pickedelement = doc.GetElement(cad);
FloorType floorType = new FilteredElementCollector(doc)
.OfClass(typeof(FloorType))
.First<Element>(e => e.Name.Equals("FLoor")) as FloorType;
Level level = new FilteredElementCollector(doc)
.OfClass(typeof(Level))
.First<Element>(e => e.Name.Equals("Level 0")) as Level;
CurveArray curveArray = new CurveArray();
// Get geometry element of the selected element
Autodesk.Revit.DB.GeometryElement geoElement = pickedelement.get_Geometry(new Options());
// Get geometry object
foreach (GeometryObject geoObject in geoElement)
{
// Get the geometry instance which contains the geometry information
Autodesk.Revit.DB.GeometryInstance instance = geoObject as Autodesk.Revit.DB.GeometryInstance;
if (null != instance)
try
{
GeometryElement instanceGeometryElement = instance.GetInstanceGeometry();
foreach (GeometryObject geometryObject in instanceGeometryElement)
if (geometryObject.GetType() == typeof(Autodesk.Revit.DB.PolyLine))
{
List<PolyLine> polyLine = new List<PolyLine>();
PolyLine line = (PolyLine)geometryObject;
polyLine.Add(line);
foreach (PolyLine poly in polyLine)
{
IList<XYZ> ptsList = poly.GetCoordinates();
XYZ normal = XYZ.BasisZ;
int i;
for (i = 0; i <= ptsList.Count - 2; i++)
{
Line lines = (Line.CreateBound(ptsList[i], ptsList[i + 1]));
curveArray.Append(lines);
}
Floor floor = doc.Create.NewFloor(curveArray, floorType, level, false, normal);
}
}
}
catch (Exception ex)
{
//TaskDialog.Show("X", ex.ToString());
}
}
}
}
}
}