Detail Lines not updating until engaged in model space

Detail Lines not updating until engaged in model space

normnoe
Participant Participant
391 Views
2 Replies
Message 1 of 3

Detail Lines not updating until engaged in model space

normnoe
Participant
Participant

I'm changing the line color of a detail line type within a transaction.  The change works correctly, but visually the lines do not change color until engaged in the model space.  Does anybody know why this occurs? Very simple code...

 

public static void ToggleColor(Document doc, System.Drawing.Color color)
        {
            Category linecat = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines);

            CategoryNameMap subcats = linecat.SubCategories;

            Category linetype = null;

            //Check if we already did this before
            foreach (Category line in subcats)
            {
                if (line.Name == NPLUtil.LineType)
                {
                    linetype = line;
                }
            }

            

            if (!(linetype == null))
            {
                Transaction trans = new Transaction(doc, "ChangeColorLine");
                trans.Start();
                linetype.LineColor = ColorUtil.GetRevitColor(color);
                trans.Commit();
            }
        }

 Here's a gif after the transaction is complete. 

strangelinecolor.gif

0 Likes
Accepted solutions (1)
392 Views
2 Replies
Replies (2)
Message 2 of 3

jeremy_tammik
Alumni
Alumni

I cannot tell you why and I very much doubt it would help if I could.

 

However, this discussion might really help:

  

https://thebuildingcoder.typepad.com/blog/2014/06/refresh-element-graphics-display.html

  

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

normnoe
Participant
Participant
Accepted solution

Ah I see. It's a hackier solution. I believe hiding and unhiding is more efficient than moving by minute values, due to the possibility of an element being linked or locked in the model.

 

if (!(linetype == null))
            {
                Transaction trans = new Transaction(doc, "ChangeColorLine");
                trans.Start();

                List<Element> detaillines = CollectDetailLines(doc, linetype);

                foreach (Element e in detaillines)
                {
                    View ownedview = doc.GetElement(e.OwnerViewId) as View;

                    if (!e.IsHidden(ownedview))
                    {
                        ownedview.HideElements(new List<ElementId>() { e.Id });
                        ownedview.UnhideElements(new List<ElementId>() { e.Id });
                    }

                }
                linetype.LineColor = ColorUtil.GetRevitColor(color);
                trans.Commit();
            }

 

workingupdates.gif

 

Thank you for the direction @jeremy_tammik.  We are up and running now!

0 Likes