Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to programmatically enter "Select" rebar presentation mode and click on "Select None" button?

4 REPLIES 4
Reply
Message 1 of 5
ghensi
467 Views, 4 Replies

How to programmatically enter "Select" rebar presentation mode and click on "Select None" button?

A colleague asked me if I can create a button that enters the presentation mode "Select" for a rebar set and automatically deselects all the rebars while staying in the presentation mode (just like the "Select None" button does, so that he can select the needed rebars and save a few clicks).
 
 With the API I can

 

Rebar.SetPresentationMode(currentView, RebarPresentationMode.Select);

 

but it doesn't enter the presentation mode, so the user can't select the rebars to show/hide.
 
In the journal I can see that the buttons have the following ids:

 

ID_REBAR_PRESENTATION_SELECT 
Dialog_Rebar_EditRebarSelectionDialogBar:Control_Rebar_EditRebarSelectHideAll

 

but if I try to use them in my code

 

var cmdId = RevitCommandId.LookupCommandId(name);
uiapp.PostCommand(cmdId);

 

I get the exception

 

The commandId must be in Autodesk.Revit.UI.PostableCommand or an external command

 

Indeed, I can't find similar items in the PostableCommand enumeration.

 

Is there a way to get the correct command IDs for these buttons?

 

4 REPLIES 4
Message 2 of 5
jeremy_tammik
in reply to: ghensi

You may be able to achieve what you wish by using a combination of PostCommand the the native Windows API or the .NET UI Automation library to simulate some very well-defined and minimal user input, such as clicking a specific button or so. You can take a look at some examples of surprising things that people have achieved in the past in The Building Code Automation category:

 

https://thebuildingcoder.typepad.com/blog/automation

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 5
ghensi
in reply to: jeremy_tammik

Hi @jeremy_tammik , thanks as always for your response!

 

I took a look at the articles of the link you posted, they have been somewhat useful, however:

 

  • The button that I need to click (Presentation mode "Select") is a ToggleButton;
  • Using FlaUInspect I can see that only the TogglePattern is supported
  • when I use TogglePattern.Toggle() the button get selected, but then it returns to "Select all" (or whatever option was selected before) and doesn't enter the selection mode.

I found this stackoverflow question with the same problem on a different togglebutton, but unfortunately nobody got an answer for it.

 

I tried to use Power Automate Desktop and record the clicks on the buttons;

It records the same IDs that I found, except it seems to cast the ToggleButton as a Button;

r_dV7EDK_0-1655300738859.png

when I try to playback the flow however, nothing happens: it waits forever at the "Press button in window" step

r_dV7EDK_1-1655300982839.png

 

I'm only left with the suspicion that there's some Revit UI sourcery involved here!

 

 

Message 4 of 5
jeremy_tammik
in reply to: ghensi

Well, if you want to go deeper still down the rabbit hole of Windows hacking, you may possibly be able to use the native Windows API to determine the native Windows button underlying all the .NET wrapper stuff and simulate a click on that. Have you looked at JtClicker yet? I am sure you can go deeper still...

  

     

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 5 of 5
ghensi
in reply to: jeremy_tammik

Thanks @jeremy_tammik!
I don't think it's worth spending any more time on this just to save a few clicks...
Sure, from a learning perspective it would be very interesting, but many other, more important things are awaiting me 😉

Thanks again, have a wonderful day!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community