Elements "remembers" SelectionColor after changing it

Elements "remembers" SelectionColor after changing it

vhh7Z3D2
Contributor Contributor
1,096 Views
11 Replies
Message 1 of 12

Elements "remembers" SelectionColor after changing it

vhh7Z3D2
Contributor
Contributor

I am working on a tool that changes the SelectionColor introduced in the Revit 2020.1 API temporarily while doing a selection.pickObjects command using Revit 2022.1.4.

Our custom families seems to "remember" the color used for selection after the color is changed back. I am wondering exactly what could cause this behavior.

 

Code:

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //Save original color
            var currentColor = ColorOptions.GetColorOptions().SelectionColor;

            //Set temporary selection color
            ColorOptions.GetColorOptions().SelectionColor = new Color(0, 255, 0);

            List<Reference> references = new List<Reference>();

            try
            {
                references.AddRange(commandData.Application.ActiveUIDocument.Selection
                                   .PickObjects(
                                       ObjectType.Element,
                                       new AllSelectionFilter(),
                                       "Choose geometry")
                                   .ToList());
            }
            catch { }

            //Set color back
            ColorOptions.GetColorOptions().SelectionColor = currentColor;

            return Result.Succeeded;
        }

 

Color has been changed to green. Pickobjects in progress. Looks ok.Color has been changed to green. Pickobjects in progress. Looks ok.

Color changed in the beginning to green before running pick objects. Looks ok.

 

Selecting all elements AFTER code has been run. Custom elements at bottom maintains the green colorSelecting all elements AFTER code has been run. Custom elements at bottom maintains the green color

Multiselection on custom elements at the bottom after running the command displays these in green even though the color was set back to blue.

 

Single selection looks ok.Single selection looks ok.

Looks ok for single selection.

 

Selecting all elements and changing to a different view seems to change the color back.Selecting all elements and changing to a different view seems to change the color back.

Changing to a different view seems to also change the color of the custom elements to the color set after the command.

 

During a second pick objects session, the custom objects now remembers the color reset in the previous step and ignores the green temporary color.During a second pick objects session, the custom objects now remembers the color reset in the previous step and ignores the green temporary color.

However when switching back to the original view and running the command for a second time, the custom objects now ignores the color change and remembers the color shift from when I changed to the 3D view.

 

What could be the issue here?

0 Likes
Accepted solutions (4)
1,097 Views
11 Replies
Replies (11)
Message 2 of 12

RPTHOMAS108
Mentor
Mentor

Have you tried the effects of using UIDocument.RefreshActiveView & UIDocument.UpdateAllOpenViews.

 

Perhaps you are changing global application options to force a temporary change where Revit is deciding instead it doesn't need to update those items in view since they have not physically changed.

0 Likes
Message 3 of 12

vhh7Z3D2
Contributor
Contributor

Yes. No effect unfortunately. I suspect its something to do with the custom families but I am unsure in what way.

0 Likes
Message 4 of 12

vhh7Z3D2
Contributor
Contributor

I have attached the file in question. I'd like if someone could try and test to check if the behavior is the same and confirm back.

 

To replicate: 

 

Run the following C# code as an IExternal command:

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //Save original color
            var currentColor = ColorOptions.GetColorOptions().SelectionColor;

            //Set temporary selection color (Green)
            ColorOptions.GetColorOptions().SelectionColor = new Color(0, 255, 0);
            
            List<Reference> references = new List<Reference>();

            try
            {
                references.AddRange(commandData.Application.ActiveUIDocument.Selection
                                   .PickObjects(
                                       ObjectType.Element,
                                       new AllSelectionFilter(),
                                       "Choose geometry")
                                   .ToList());
            }
            catch { }

            //Set color back
            ColorOptions.GetColorOptions().SelectionColor = currentColor;

            //Select with old color
            commandData.Application.ActiveUIDocument.Selection.SetElementIds(references.Select(s => s.ElementId).ToList());

            //Deselect
            commandData.Application.ActiveUIDocument.Selection.SetElementIds(new List<ElementId>());

            //Refresh views
            commandData.Application.ActiveUIDocument.RefreshActiveView();
            commandData.Application.ActiveUIDocument.UpdateAllOpenViews();

            return Result.Succeeded;
        }

 

Check that the selection color is set to blue via File>Option>

06.png

Run the command and select the 4 walls as well as the the 8 walls (based on beam family) at the bottom:

07.png08.png

Click on finish:

09.png

Reselect the walls/elements using multiselect:

10.png

Recheck that the selection color has been set back.

0 Likes
Message 5 of 12

vhh7Z3D2
Contributor
Contributor

Are you able to replicate the issue? I have attached the file in a previous reply.

0 Likes
Message 6 of 12

jeremy_tammik
Alumni
Alumni
Accepted solution

Dear Verner,

 

Thank you for your report, clear description and sample material. Sorry to hear about this.

 

I logged the issue REVIT-212103 [SelectionColor is remembered and cannot be changed] 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 7 of 12

vhh7Z3D2
Contributor
Contributor

Hello Jeremy

 

My answers in green:

 

  • Impact on your application and/or your development. The color change was an idea suggested by the team lead to make it easier to distinguish between individual elements in a usercontrol currently beeing developed. It works without it, but it can be difficult too see the difference between an unselected gridline (black) and a selected one (blue).
  • The number of users affected. Around 40.
  • The potential revenue impact to you. Our tools help to automate designprocesses. At present the usercontrol can be used as is, but will probably require greater attention from the user. I dont have an estimate.
  • The potential revenue impact to Autodesk. None at present.
  • Realistic timescale over which a fix would help you. I estimate it will be 2 months before this tool is ready for production.
  • 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. Not relevant in our case.
0 Likes
Message 8 of 12

jeremy_tammik
Alumni
Alumni
Accepted solution

Dear Verner,

 

Thank you for your business case!

 

Best regards,

 

Jeremy

 

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

jeremy_tammik
Alumni
Alumni
Accepted solution

Dear Verner,

 

Thank you for reporting this issue and your patience while we took a closer look at it. The development team analysed the issue REVIT-212103 [SelectionColor is remembered and cannot be changed] and determined a need for a code fix. That case has now been closed, and a new ticket REVIT-212965 [SelectionColor is remembered and cannot be changed] opened to perform the actual work. 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.

 

Best regards,

 

Jeremy

 

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

jeremy_tammik
Alumni
Alumni

Dear Verner,

  

Thank you for your patience while the development took a closer look at your issue REVIT-212965 [SelectionColor is remembered and cannot be changed]. Unfortunately, the requested enhancement is trickier than expected, and they say:

  

We are going to close this as 'will not fix'. The fix is a bit more involved than we currently have time for. I have been looking for a work-around that is accessible through the API. Unfortunately all I have at them moment is UpdateAllOpenViews. But looking at the code, that does not clear the caches that need clearing. Internally, we call it with a 'full_redraw' hint, and I believe we need something like 'clear_graphic_cache_and_full_redraw' instead. We are still searching for other ideas on how to trigger a DBView cache clear from the API.

  

Best regards,

  

Jeremy

  

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

jeremy_tammik
Alumni
Alumni
Accepted solution

Actually, the other thing that might work is if you can trigger a regeneration on the affected elements. But that assumes that you know the affected elements. The Building Coder mentioned some possible approaches, e.g.,

  

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 12 of 12

vhh7Z3D2
Contributor
Contributor
Thank you Jeremy. I'll note your suggestions on our internal workitem.
0 Likes