Message 1 of 5
Create Floor from Wall
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Tengo este script,que funciona en el revit 2021.Pero al cambiar al Revit 2022,cambia el metodo de creacion del suelo.
Alguna idea de como solucionarlo?
Aqui esta el script
I have this script, it works in revit 2021, but when switching to revit 2022, it changes the method of creating the floor.
Any idea how to fix it?
Here is the script
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
Result result = Result.Succeeded;
//Get UIDocument and Document
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
//Initialize wall selection filter
WallSelectionFilter wallSelection = new WallSelectionFilter();
//Select the walls
IList<Reference> references = uidoc.Selection.PickObjects(Autodesk.Revit.UI.Selection.ObjectType.Element, wallSelection);
if (references != null && references.Count > 0)
{
//Initialize the curves list
List<Curve> wallCurves = new List<Curve>();
//Initialize the offsets list
List<double> offsets = new List<double>();
//Initialize the levels ids list
List<ElementId> levelsIds = new List<ElementId>();
foreach (var refer in references)
{
Wall wall = (Wall)doc.GetElement(refer);
if (wall != null)
{
//Add the wall curve to the curves list
wallCurves.Add((wall.Location as LocationCurve).Curve);
//Add the wall curve to the curve list
offsets.Add(wall.Width / 2.0);
//Add the wall curve to the curves list
levelsIds.Add(wall.LevelId);
}
if (levelsIds.All(lvl => lvl == levelsIds[0]))
{
CurveLoop ccu = CurveLoop.Create(wallCurves);
//Create floor curve loop
CurveLoop ccud = CurveLoop.CreateViaOffset(ccu, offsets,new XYZ(0, 0, 1));
//Initialize the curve array
CurveArray curveArray = new CurveArray();
//Append the floor curves to the curve array
foreach (Curve c in ccud)
{
curveArray.Append(c);
}
//Get the level to model the floor
Level level = doc.GetElement(levelsIds[0]) as Level;
string floorTypeName = "Generic 300mm";
//Collect the floor type to be used
FloorType floorType = new FilteredElementCollector(doc).OfClass(typeof(FloorType))
.First(e => e.Name.Equals(floorTypeName)) as FloorType;
using (Transaction tx = new Transaction(doc, "Wall to Floor"))
{
tx.Start();
try
{
//Create the floor
doc.Create.NewFloor(curveArray, floorType, level, false);// Revit API 2021
Floor.Create(doc, new List<CurveLoop> { ccud }, floorType.Id, level.Id);// Revit API 2022
//Commintchange to the model
tx.Commit();
}
catch (Exception e)
{
//Asign the error message to the user
message = e.Message;
//Roll back the model changes
tx.RollBack();
//Asign the result to failed
result = Result.Failed;
}
}
}
else
result = Result.Failed;
}
}
else
result = Result.Failed;
return result;
}