BUG - Display does not update after paint with API

BUG - Display does not update after paint with API

harrymattison
Advocate Advocate
899 Views
14 Replies
Message 1 of 15

BUG - Display does not update after paint with API

harrymattison
Advocate
Advocate

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);
        }
    }
}

 

0 Likes
Accepted solutions (1)
900 Views
14 Replies
Replies (14)
Message 2 of 15

TripleM-Dev.net
Advisor
Advisor

Hi,

 

You have the Material in a loop, so the columns would be repeatedly be painted

If the Material collector only retrieves one material, then use .First and only paint the columns once.

 

If after the run (paint by API-Fail, Paint with UI-Ok, paint with API-Ok)

Run it again but now pick another material, does that paint ok now. (maybe some initialize of the material of the geometry of the column...)

0 Likes
Message 3 of 15

harrymattison
Advocate
Advocate
The loop in the code is there to go along with some additional code (which
I removed for this sample) to export an image of the view after painting
with each material. The bug is unrelated to that loop. Thanks for the
suggestion.
0 Likes
Message 4 of 15

ricaun
Advisor
Advisor

You code is a little strange and after some play-around, looks like paint Columns is weird.

 

Paint FamilyInstance does not work with all categories, if you try to paint a Door or Window does not work, is not possible select the face and paint using the Revit UI.

 

Probably is a bug, or Columns should not be allow to be painted because is a FamilyInstance and you can open the family and paint inside.

 

I didn't find any other category family instance that can be painted using the Revit UI, Columns works for some reason.

 

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

0 Likes
Message 5 of 15

Sleepingfish_Kuo
Advocate
Advocate
GetSolids(column.get_Geometry(new Options()));

Element has different geometry in views.

Try replacing "new Options()" to an option relating to current view?

0 Likes
Message 6 of 15

harrymattison
Advocate
Advocate
Revit supports painting instances of column families. It just doesn’t work
via the API

https://help.autodesk.com/view/RVT/2025/ENU/?guid=GUID-8BAA7C07-D174-4F02-AA81-239FD33BE363


- You cannot apply materials to faces of component family instances
(except columns) in a project. You must apply the materials to faces of a
component family in the Family Editor.

0 Likes
Message 7 of 15

jeremy_tammik
Alumni
Alumni
Accepted solution

Dear Harry,

 

Thank you for your report, clear description and sample material.

 

Sorry to hear about this.

 

I logged the issue REVIT-233213 [API Paint column does not update display] with our development team for this on your behalf as it requires further exploration and possibly a modification to our software. Please make a note of this number for future reference.

   

You are welcome to request an update on the status of this issue or to provide additional information on it at any time quoting this change request number.

    

This issue is important to me. What can I do to help?

   

This issue needs to be assessed by our engineering team and prioritised against all other outstanding change requests. Any information that you can provide to influence this assessment will help. Please provide the following where possible:

    

  • Impact on your application and/or your development.
  • The number of users affected.
  • The potential revenue impact to you.
  • The potential revenue impact to Autodesk.
  • Realistic timescale over which a fix would help you.
  • In the case of a request for a new feature or a feature enhancement, please also provide detailed
  • Use cases for the workflows that this change would address.

   

This information is crucial. Our engineering team has limited resources and must focus their efforts on the highest impact items. We do understand that this will cause you delays and affect your development planning, and we appreciate your cooperation and patience.

   

Best regards,

   

Jeremy

    

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 8 of 15

rhanzlick
Advocate
Advocate

Skimming through the thread, not sure where you landed on this or how confident you are that it is actually a bug, but...

In your code above, between lines 21 and 22, you dont appear to actually store the solids retrieved by the GetSolids method. Also be careful in how GetInstanceGeometry is used.... Revit utilizes lazy generation and very often defers to SymbolGeometry unless your instance has cuts or something - leaving instance Geometry empty or even worse, maybe returning the SymbolGeometry in it's place without telling you.

Finally, you might try something like:

- https://www.revitapidocs.com/2016/5d9f248c-a1be-ac2e-1f4c-2219ed0fc5ae.htm

or

- https://www.revitapidocs.com/2016/22468e2c-9772-8478-0816-c9759aa43428.htm

Message 9 of 15

rhanzlick
Advocate
Advocate

As an edit, I didn’t previously see solids defined as a static list down below where your void method appended to it… I don’t see a reason to define that as static - just have the method return a list of solids directly.

e.g.

 

List<solid> solids = GetSolids(column.get_Geometry(new Options());

 

Unless “solids” is inside of a class where you need access at the type level (which you should avoid because Revit will very often and somewhat unpredictably regenerate and invalidate solids in-between transactions), you should reconsider declaring it as static. No need to declare anything as static unless you need access at the type level instead of the instance. Just my unsolicited 0.02.

0 Likes
Message 10 of 15

harrymattison
Advocate
Advocate

Jeremy - Thank you for reporting this bug to the development team. 

 

I appreciate all the other replies - my intention here was to pare down the larger program I had written into a smaller sample that reproduced the bug. If the goal was to teach best practices that would have been a different exercise. 

 

If your API code doesn't work but then you do something manually in the Revit interface and run the same API code again and see the expected result, then that is a Revit bug regardless of how tidy your code is.

Message 11 of 15

studio-a-int
Advocate
Advocate

We use a different code to paint geometry based on a desired category. A simple test is to change the Category of collected elements to be painted. In our code, using  BuiltInCategory.OST_Columns will not paint the faces (tested in Revit up to 2024), changing to BuiltInCategory.OST_StructuralColumns, code will execute and faces are painted. This is a simple indication that might be a bug, as pointed above.

Message 12 of 15

jeremy_tammik
Alumni
Alumni

Dear Harry,

   

Which Revit release build are you using?

  
The development team tested on the internal development build, and the paint command works fine using your Macro.

  

Cheers

  

Jeremy

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 13 of 15

harrymattison
Advocate
Advocate

Hi Jeremy - I used the attached file and also tried in 2023, 2024, 2025. Thanks Harry

Message 14 of 15

studio-a-int
Advocate
Advocate

We did a quick test: placed two identical Columns and ran our application. The faces of the Columns, are not painted. If we use the built in tool in Revit to paint (at least) one face of one of the Columns, then run our application, at that time that Column is painted on all the faces, but the other Column is not. So the code executes as expected once a Column is "accessed" by the Revit built in paint tool. This points out to something else. Test was done in Revit 2024.

Message 15 of 15

jeremy_tammik
Alumni
Alumni

Dear Harry,

 

Thank you for the sample file and your patience.

  .

The development team analysed the issue REVIT-233213 [API Paint column does not update display] and determined the need for a code fix.

  

The issue was closed and a new ticket REVIT-234209 [API Paint column does not update display] created to perform this work. Please make a note of this number for future reference.

  

Best regards,

  

Jeremy

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open