How Perform click (simulate) on ribbon button?

How Perform click (simulate) on ribbon button?

AndrewButenko
Advocate Advocate
1,992 Views
5 Replies
Message 1 of 6

How Perform click (simulate) on ribbon button?

AndrewButenko
Advocate
Advocate

Hello !

 

 How add "Detail Line" button from tab "Annotation" to  "Modify" ribbon tab  or simulate click on "Detail Line" button (if i add my button to "Modify" tab) programmaticaly? 

0 Likes
1,993 Views
5 Replies
Replies (5)
Message 2 of 6

Revitalizer
Advisor
Advisor

Hi,

 

you could invoke the original command this way:

 

RevitCommandId commandId = RevitCommandId.LookupPostableCommandId(PostableCommand.DetailLine);

if (uiApp.CanPostCommand(commandId))
{
    uiApp.PostCommand(commandId);
}

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 3 of 6

AndrewButenko
Advocate
Advocate

Dear Revitalizer!

 

After first call your code nothing happened. After second calling i got error: 

 

Autodesk.Revit.Exceptions.InvalidOperationException: "Revit does not support more than one command are posted."

0 Likes
Message 4 of 6

Revitalizer
Advisor
Advisor

Hi,

 

I must admit that I used this PostCommand method just with PostableCommands that relate to the window arrangement.

These are TileWindows, CascadeWindows, ReplicateWindow.

Obviously, they do not interact with the current Document since they may invoke just Windows API methods.

(Respectively, ReplicateWindow generates a new View Element.)

 

For the PostableCommand.DetailLine, I haven't tried this on myself.

I would suppose it needs a valid 2D view to be executed (which could be done by assigning a proper AvailabilityClassName to your button).

 

So perhaps in the first run, it is invoked, but waiting for execution.

If you execute the original command manually, you see a cursor waiting for input; you then either draw lines by picking points etc. or you leave the command by pressing the ESC key.

After (and only after) that you can invoke another command, in the GUI.

This may be the cause of the error message for the second run.

 

What also comes in mind:

You only can invoke those PostableCommands on the very end of your command.

Nothing can be done in the Document after that, in your command.

 

If uiApp.CanPostCommand is true but Revit throws an Exception if you uiApp.PostCommand,

then I think there is a bug in the API.

 

No more ideas, sorry.

 

 

Revitalizer

 

 

 

 

 




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 5 of 6

AndrewButenko
Advocate
Advocate

Dear Revitalizer!

 

Thank you for your advice. I solved a problem another method. I got button Detail Line:

 

 

  If (ribbonTab.Id = "Annotate") Then
                    'перебираем панели в закладке Annotate
                    For Each ribbonPanel1 As AdWin.RibbonPanel In ribbonTab.Panels

                        'ищем панель detail_shr
                        If ribbonPanel1.Source.Id = "detail_shr" Then
                            'присваиваем панель переменной adWinSysPanelDetail
                            adWinSysPanelDetail = ribbonPanel1
                            'перебираем панель для поиска RibbonFoldPanel
                            For i = 0 To adWinSysPanelDetail.Source.Items.Count - 1
                                If adWinSysPanelDetail.Source.Items(i).GetType Is GetType(AdWin.RibbonFoldPanel) Then
                                    Dim rfp As AdWin.RibbonFoldPanel = adWinSysPanelDetail.Source.Items(i)
                                    'перебираем элементы RibbonFoldPanel  для поиска кнопки DetailLine 
                                    For j = 0 To rfp.Items.Count - 1
                                        If rfp.Items(j).Id = "ID_OBJECTS_DETAIL_CURVES" Then
                                            'присваиваем кнопку переменной btnDetailLine 
                                            btnDetailLine = rfp.Items(j)

                                        End If

                                    Next
                                End If
                            Next

                        End If
                    Next
                End If

After, I added it to tab Modify

 

Message 6 of 6

Revitalizer
Advisor
Advisor

Hi,

 

yes, using the AdWindows.dll can be useful in many cases.

I consider it being a workaround since it is not officially supported, but hey, I does the job.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes