1

I write a program that forms a divided surface using a reference to the face of the shape. But when applied to walls (the search string with category selection is highlighted below), the program does nothing. How do I apply this program to all walls in a project only?

   public class Command : IExternalCommand
    {
        public Result Execute(
          ExternalCommandData commandData,
          ref string message,
          ElementSet elements)
        {
            UIApplication app = commandData.Application;
            Document doc = app.ActiveUIDocument.Document;

            Autodesk.Revit.Creation.Application creApp
              = app.Application.Create;

            try
            {
                FilteredElementCollector forms = new FilteredElementCollector(doc);
                forms.OfCategory(BuiltInCategory.OST_CurtainGridsWall); // !!problem string!!

                using (Transaction tx = new Transaction(doc))
                {
                    tx.Start("Create Devided Surface");

                    foreach (Form form in forms)
                    {
                        FamilyItemFactory factory = doc.FamilyCreate;
                        Options options = creApp.NewGeometryOptions();
                        options.ComputeReferences = true;
                        options.View = doc.ActiveView;
                        GeometryElement element = form.get_Geometry(options);

                        foreach (GeometryObject geoObject in element) // 2013
                        {
                            Solid solid = geoObject as Solid;
                            foreach (Face face in solid.Faces)
                            {
                                if (face.Reference != null)
                                {
                                    if (null != face)
                                    {

                                    }
                                }
                            }
                        }
                    }
                    tx.Commit();
                }

                return Result.Succeeded;
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return Result.Failed;
            }
        }
    }
All In
  • 89
  • 1
  • 6

1 Answers1

1

If you need to find all walls in current document, just change BuiltInCategory.OST_CurtainGridsWall to BuiltInCategory.OST_Walls, and cast elements to Autodesk.Revit.DB.Wall, like this:

UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
var walls = new FilteredElementCollector(doc)
    .OfCategory(BuiltInCategory.OST_Walls)
    .WhereElementIsNotElementType()
    .Cast<Autodesk.Revit.DB.Wall>
    .ToList();

If you need walls from all documents in project you will need to get all linked documents first (linked documents should be loaded to project, or you cannot find them), like this:

UIApplication app = commandData.Application;
var doc = app.ActiveUIDocument.Document;
List<Autodesk.Revit.DB.Document> linkedDocs = new Autodesk.Revit.DB.FilteredElementCollector(doc)
                .OfClass(typeof(Autodesk.Revit.DB.RevitLinkInstance))
                .Cast<Autodesk.Revit.DB.RevitLinkInstance>()
                .Select(x => x.GetLinkDocument())
                .ToList();

Then, for each document, repeat the receiving of the walls.

Kliment Nechaev
  • 480
  • 1
  • 6
  • 13