Post command doesn't execute command after panel was hidden

Post command doesn't execute command after panel was hidden

Anonymous
Not applicable
2,777 Views
22 Replies
Message 1 of 23

Post command doesn't execute command after panel was hidden

Anonymous
Not applicable

Hi,

 

I'm having trouble with getting a command to execute using an external event. I'll explain.

 

I have an app that creates a ribbon tab, a panel and a button which executes a command. Now I also have a button that I add to an existing tab. That button should execute the same command as the button in my own panel, so I use UIApplication.PostCommand.

 

This seems to work well, except when my own ribbon panel was hidden. I want to hide that panel when there is no active project, and show it when there is. For some reason, the command just doesn't get executed in this case. When I lookup the command using RevitCommandId.LookupCommandId, I do get a valid RevitCommandId.

 

I've attached a sample (VS2015) project demonstrating the issue. If you run it, everything works. If you uncomment line 32 in TestCommandRibbon.cs, the command won't get executed anymore.

 

Can someone explain me what's going on, and possible help me with a solution? Thanks in advance.

0 Likes
2,778 Views
22 Replies
Replies (22)
Message 2 of 23

Anonymous
Not applicable

I just noticed I forgot to save a file, the line that was to be uncommented is already uncommented. So when you run it, the command won't get executed. If you comment line 32, then you'll notice everything works as expected.

0 Likes
Message 3 of 23

Revitalizer
Advisor
Advisor

Hi TorX85,

 

I didn't read your attached project files, but what is the problem ?

 

If your panel (the one added the default, advised way) is hidden or disabled because no document is opened, your function does not work.

If a button is not enabled, the function behind it cannot be performed.

Your other button or panel (the one added the inofficial, unsupported way) just reflects the command availability / command binding of the first one.

 

 

Revitalizer

 




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 4 of 23

Anonymous
Not applicable

Hi Revitalizer,

 

Thanks for your reply. The attached project would demonstrate the problem, but I'll try to explain better.

 

Obviously functions do not work for hidden or disabled GUI elements. But when a document is opened, I make my panel visible again. In that case, the button on that panel works, but the button on the modify panel does not work anymore. Now, if I never make my panel invisible, then the button on the modify panel does work.

 

And just as a reminder, in the code behind the button on the modify tab, I still get a valid RevitCommandId from RevitCommandId.LookupCommandId. So it can find the command, but PostCommand does not work anymore.

0 Likes
Message 5 of 23

Revitalizer
Advisor
Advisor

Hi,

 

what about not making it invisible but adding or removing it each time ?

 

Autodesk.Windows.RibbonPanel.Source.Items seems to be editable, meaning you can add but also remove an item.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 6 of 23

Anonymous
Not applicable

I'm afraid that won't help me.

 

First of all, I don't get an Autodesk.Windows.RibbonPanel but an Autodesk.Revit.UI.RibbonPanel, which doesn't expose a Source property.

Second, I don't want to hide (remove) the items on the panels, but the panels themselves.

Last but not least, I really would like to just hide and show the panels, because the code is more complex in my production code and it feels like hiding / showing is much more resource friendly than removing / adding.

 

I do appreciate your help very much. I just hope someone from the Revit team can look into this issue. This might be a problem with potentially more consequences. The project attached in my opening post should make it easy to find the problem.

0 Likes
Message 7 of 23

jeremytammik
Autodesk
Autodesk

Dear TorX85,

 

I will take a look.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 8 of 23

jeremytammik
Autodesk
Autodesk

Dear TorX85,

 

Thank you again for your query, sample code and patience.

 

I compiled it and ran into several issues:

 

  • It was set up to use the .NET framework 4.5.2, whih I do not have installed. I reset it to use 4.5 instead.
  • It used several variables with a trailing question mark, i.e., using a null-conditional operator, cf. https://msdn.microsoft.com/en-us/magazine/dn802602.aspx. I removed the question marks, since they caused compilation errors.
  • The debugging application was set to Revit MEP 2015. This does not really match the .NET frtamework setting.
  • The Regeneration attribute is superfluous, since RegenerationOption.Manual is the only available option anyway.
  • You sample command can be read-only, anyway; no need for manual transaction mode.

 

I was unable to load your add-in after these changes, so I created a new one based on your code instead.

 

My new add-in is attached to this message in PostCommandFromHiddenPanel.zip.

 

Please resync your code with this to ensure we are talking about the same thing.

 

However, there is something seriously wrong with it, so I cannot reproduce the issue you describe.

 

It loads all right, and I can debug through the statements defined in the OnStartup method.

 

Afer loading has completed, if I click in the Revit Add-Ins tab, Revit disappears with no message, a so-called silent exit.

 

The last two lines in the Visual Studio debug output console window say:

 

A first chance exception of type 'System.NullReferenceException' occurred in PostCommandFromHiddenPanel.dll
The program '[4544] Revit.exe: Managed (v4.0.30319)' has exited with code -1073741819 (0xc0000005) 'Access violation'.

 

No idea what this is due to.

 

Can you see what went wrong in my reuse of your code?

 

Maybe you also might want to explain what you are trying to achieve, and above all why.

 

So far, all this makes little sense to my poor little simple brain.

 

I hope this helps.

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 9 of 23

Anonymous
Not applicable

Hi Jeremy,

Thank you for looking into this and apologies for having to change the project. I've managed to get your version working by changing two things:
- In ComponentManager_UIElementActivated, first check if the e.Item is not null before comparing the id (this is what caused the silent exit).
- When creating the normal button, change the className to PostCommandFromHiddenPanel.MyCommand.

If you run the code (and having a document opened), the button "Open command alternative" seems to do nothing. If you comment out the UpdatePanels(false) in the startup method, that button works as expected.

Now about what I want to achieve. In my actual project, I also have a ribbon tab with a panel with buttons that start commands. My product owner would also like to have a button on the modify tab, which should do the same thing as one of the buttons on my own panel. I've managed to get that working. Another thing my product owner wants, is that my own panel is hidden when there is no document active. But when I hide the panel (and show it again), the button on the modify tab doesn't work anymore. That is strange in my opinion.

Thanks again for your help.

0 Likes
Message 10 of 23

jeremytammik
Autodesk
Autodesk

Dear Torx85,

 

Thank you for taking a look, finding the problems (my fault! - I see the coolness of the null-operator) and explanation.

 

I can now load the add-in and see the Test tab with the Open command button. When I click it, the command is executed and the message appears.

 

How do you hide your panel?

 

I can imagine that this behaviour is as designed, though.

 

If the Revit add-in framework expects your command to be shown in a specific location in the ribbon, turning iff your panel may somehow toggle the command state... 

 

Tell me how to hide and unhide the panel, and I'll taker one last look, but that will probably be it.

 

I cannot spend much time exploring, nor do I think that the development team would give this a high priority, even if it was recognised as a problem.

 

I hope some of yoour peers take an interst in the issue and chip in as well  🙂

 

Later: Where is the 'Open command alternative' button that you mention?

 

I only see 'Open command' in the Test panel in the Test command tab, and that works fine.

 

I'm attaching my updated add-in solution PostCommandFromHiddenPanel.zip.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 11 of 23

Anonymous
Not applicable

Hi Jeremy,

 

Yes, C# 6 has some very neat features 🙂

 

What do you mean with how I hide / show my panel? The UpdatePanels method in the project is made for that purpose. Or do you mean something else? Thanks again!

0 Likes
Message 12 of 23

jeremytammik
Autodesk
Autodesk

On my system, I stepped through the AddButton and UpdatePanels methods, all statements executed, yet no button was added to the Modify tab, and the Test command panel remained visible.



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 13 of 23

Anonymous
Not applicable

The panel might be visible because UpdatePanels(true) is called when a document is opened, which makes the panel visible. Not that the tab is always visible, but the panel inside the tab should toggle between hidden and visible.

 

Why the button doesn't show up in the modify tab is a mystery. Are you looking in the correct place? I've attached a screenshot with the correct tab and the location of the button.

0 Likes
Message 14 of 23

jeremytammik
Autodesk
Autodesk

Nothing there in the Modify tab.

 

Test command tab and Test panel still appear.

 

Both UpdatePanels and AddButton are each called exactly once, during startup.

 

Did you check with my updated solution?

 

What build of Revit are you using?



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 15 of 23

Anonymous
Not applicable

Sorry, I didn't notice you attached the updated project. I've tried it, and I get the same results as before. UpdatePanels is called twice (once during startup, second time when the document is opened). AddButton is indeed called once. But I do see the button in the modify tab, just as in my screenshot.

 

I had to change two things in your project to get it working on my system, but it should not affect the result:

- Change the references to the Revit MEP 2015/ instead of Revit 2015/

- Change the command line argument to a project that exists on my computer.

0 Likes
Message 16 of 23

jeremytammik
Autodesk
Autodesk

Dear TorX85,

 

Are you running on the most up-to-date service pack?

 

I have heard of various fixes beiing applied to PostCommand and the modeless panels.

 

I have not raised an issue for you yet with the development team.

 

I am leaving on vacation for the next two weeks.

 

Therfore, please get back to me after I return if the problem persists, or if you have any other new information on it.

 

Thank you!

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 17 of 23

Anonymous
Not applicable

I had not updated to the last service pack. But after updating to "20150702_1515(x64) Update Release 9", the problem still exists unfortunately.

0 Likes
Message 18 of 23

jeremytammik
Autodesk
Autodesk

Sorry to hear that!

 

Have you tried it in Revit 2016?



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 19 of 23

Anonymous
Not applicable

I hadn't, but I've just tried it in version "16.0.428.0  20150220_1215(x64)". It doesn't work there as well.

0 Likes
Message 20 of 23

ModPlus
Enthusiast
Enthusiast

The year is 2024 - this problem is still relevant!

Has anyone come up with any solution?

0 Likes