Message 1 of 15
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This code paints all columns with all the materials that start with "boundary"
But the display does not update
We know the surfaces are painted because if you manually paint a surface after running the macro, then the paint appears on other surfaces. And if you then run the macro a second time, then all the surfaces get painted.
I've tried all the trick - doc.regenerate, uidoc.RefreshActiveView, closing and opening the view & file, moving the columns after applying the paint, etc. The only thing that makes it work is manually painting a surface after running the macro
public void PaintStuff()
{
var doc = this.ActiveUIDocument.Document;
var uidoc = this.ActiveUIDocument;
var materials = new FilteredElementCollector(doc)
.OfCategory(BuiltInCategory.OST_Materials)
.Where(q => q.Name.ToLower().StartsWith("boundary"))
.ToList();
using (var t = new Transaction(doc, "test"))
{
t.Start();
foreach (var material in materials)
{
var columns = new FilteredElementCollector(doc, uidoc.ActiveView.Id)
.OfClass(typeof(FamilyInstance))
.OfCategory(BuiltInCategory.OST_Columns)
.ToList();
foreach (var column in columns)
{
solids = new List<Solid>();
GetSolids(column.get_Geometry(new Options()));
foreach (var solid in solids)
{
var faces = solid.Faces.Cast<Face>().ToList();
foreach (var face in faces)
{
doc.Paint(column.Id, face, material.Id);
}
}
}
}
t.Commit();
}
}
private static List<Solid> solids;
private void GetSolids(GeometryElement geomElem)
{
foreach (GeometryObject geomObj in geomElem)
{
Solid solid = geomObj as Solid;
if (null != solid)
{
solids.Add(solid);
continue;
}
GeometryInstance geomInst = geomObj as GeometryInstance;
if (null != geomInst)
{
GeometryElement transformedGeomElem = geomInst.GetInstanceGeometry(geomInst.Transform);
GetSolids(transformedGeomElem);
}
}
}
Solved! Go to Solution.