Is it possible to dynamically add commands after IExternalApplication.OnStartup has executed to Revit's Ribbon Panel?
I came across this post on TheBuildingCoder...
http://thebuildingcoder.typepad.com/blog/2010/03/adding-noncommands-to-the-revit-ribbon.html
.. and the first "P.S." on there seems to imply that it's not possible, but that was back in 2010. I'm wondering if anything has changed?
I haven't been able to figure it out myself. Trying to just execute the AddPushButton() code that I've written results in:
An unhandled exception of type System.Runtime.InteropServices.SEHException' occurred in RevitAPIUI.dll
It works fine when placed inside the IExternalApplication.OnStartup block, which seems to imply that I either need to execute the code to add to the Ribbon panel in some sort of Transaction pattern or similar... or, it's just not possible :(
Any help would be appreciated, thank you!
I've been able to do this in the past (at least with Pulldown buttons, adding more of them later on).
During the OnStartup, I stored a static reference to the main PulldownButton, and then later on, call PulldownButton.AddPushButton() to add the additional buttons.
(I know- short on details, but I hope it helps!).
Related
Basically, it has been 3 days since I'm trying to resolve this issue. I'm coding a sort of Mail Client in C# - everything was working pretty much good, while I started getting this unhandled exception... I would like to post a code section, but I do not know exactly what it causing this problem. A good fact is that the project is pushed over Github. Over internet it is said that maybe some variables used on some loops may cause the problem; I've already tried to edit some parts, but unluckily nothing worked...
Latest edit:
Added a Bunifu.Framework.UI.BunifuFlatButton over a UserControl. On click event, this happens:
MessageBox.Show(settingsControl.FLAG.ToString());
- I was testing if this would print me the int FLAG variable taken from another UserControl called settingsControl.
Every suggestion is appreciated. Thanks!
I was wondering if there is any way to return the path that Visual Studio takes when running through a program. For example, without setting breakpoints, is it possible to know exactly what happens when I click a button on a web app I created? Like if I clicked a button that had an action, is there some kind of info that Visual Studio can spit out that tells me what happened? (which functions in which files were used, etc. Essentially the "code path").
To add on to my question, I'd like to use something like this to help debug an issue. I want to know exactly what is happening when I perform some kind of action (button click in my example). If I know every "code path" I can better address the issue I'm having.
If I understand correctly your question, you're looking for Environment.StackTrace
The StackTrace property lists method calls in reverse chronological order, that is, the most recent method call is described first, and one line of stack trace information is listed for each method call on the stack. However, the StackTrace property might not report as many method calls as expected due to code transformations that occur during optimization.
Something else you can do is adding debug log entries to know what's is going on. It may be more useful since you could add extra custom data.
Not sure if you already have a log framework on your project. If you don't have any log4net could be a good option
Converting my comment to an answer so there is an answer that addresses the original question:
Use a performance profiler, which is designed to observe execution paths (typically to help you find bottlenecks, etc., but it will work fine for your purposes too). A good performance profiler will let you dig down and see, for any method, what methods it calls, how frequently, etc.
You can print out a call stack results to the output window in Visual Studio. You will still need to use breakpoints but the ones that doesn't stop the application. To do that:
Find the place in your code when you would like to get the stack printed out. For instance at the end of button clicked handler.
Place a break point there.
Right click the breakpoint. From the context menu select "When Hit..." option.
In the window that will show up select "Print a message:" checkbox. It will enable a textbox. In the textbox type in: $CALLSTACK.
Check the "Continue execution" checkbox if you don't want to stop the execution while printing the results.
I don't remember if the "When Hit..." option is available in the Express edition of Visual Studio.
There are also some other data you can print out without breaking execution, e.g.: previous function, process id, etc. The details are actually available in the "When Hit..." window.
I am having a small c# 4.0 project (VS2010) with workflows.
First I had one workflow only and that worked perfect.
Now I inserted a 2nd one (and later need more).
I now got Workflow_One with many activities, and Workflow_Two with other activities.
Workflow_Two is inserted into Workflow_One as an activity.
My problem is 'I don't know how to finish or end Workflow_Two which is a part or activity of Workflow_One.
I tried to insert W_One as an activity into W_Two itself, where W_Two should end, but then VS2010 crashed and I could not open the Flowchart editor anymore...
How do I end W_Two with the flowchart editor or in the code, to continue to the parent workflow W_One again?
By the way, in my opinion it is a bug when the VS is crashing and the flowchart editor cannot be opened anymore when you insert two workflows in one each other... :-)
Please give me a hint how to tell W_Two it is finished. Thanks a lot!
Firlefanz
Thanks, I found out when I get to an activity, which has no "follower", it changes automatically back to the parent workflow. I had some error which went from there back to the child workflow at once.
Best regards,
Firlefanz
So, I made a program in Visual C# 2010 Express. Finished enough to work, and pretty darned good for my first attempt at the language. But then I foolishly decided, "Hey, this program needs a close confirmation dialog before I send it out!" So I write the function, and then I go into the auto-generated code to bind said function appropriately.
KABOOM!
Now, the form designer shows a blank form, and all those shiny components have all been erased from both the designer and the auto-generated code. Which, in such a simple program, is about 80% of the work I put into it.
Now, in NetBeans, I would right-click the file's tab, and just go back to a previous version, maybe losing about 15 minutes of work. This is a pretty obvious concept, I'm just not sure where to find file history in Visual Studio. So, where is the equivalent so I can get my work back?
(I've also managed to get my code back by just undoing a whole bunch - but the designer doesn't see it, and neither does the compiler, so it still builds to a blank form.)
Sadly, you've just learned a couple of things.
One is to never, ever modify designer-generated code. In fact, C# has a concept called partial classes which allow you to modify a generated class without having to modify the generated file.
Second, that Visual Studio in and of itself has no built in source code control -- you need to choose the one you like and be diligent in using it. Some of the most popular are git, subversion, mercurial, and Team Foundation Server. I personally use svn, but the others are good too. Avoid something called Visual SourceSafe (VSS).
From the sound of it, I'd say you tried ctrl-z until some point in your code, but not in the designer?
Performing multiple "undo's" in the code-behind file where you put your code is one thing, performing "undo's" in the designer is another.
Hopefully, you have not closed visual studio yet, and viewing your now blank form in design view, and trying a bunch of ctrl-z presses there, might do the trick.
Actually the controls are not lost from Design code or Initialize
Component() ,make sure that whether check
Initialize Component() { this.controls.add("Where the control was ")
}
Example:
1-this.Controls.Add(this.panel1.label1); 2-this.Controls.Add(this.panel1.label2);
either in form you can write like below
should write in the Initialize Component()
this.Controls.Add(this.label1);
I had a similar effect: the code wasn't lost because the project compiled perfectly but I only got a blank form in designer.
This was because the form was inherited from another form, and I added in the Load event of the base form the line: this.MdiParent = Application.OpenForms("BaseForm");
After deleting this line (and recompiling) I could access the design of the descendig forms again.
One thing you could do, it won't help you this time, but may be a good idea for the future - if you copy your code alot (like I do), get one of those clipboard savers - like ClipTrap (which is lightweight, simple, and great).
Then, if you realize you can't undo what you did, then you get a second chance by running through the "trapped" text to see if what you want might just be there.
Another good option is to try something like AutoVer, which will save a copy of any changed file (or files in a folder) every so often as you like. This could provide you with a backup of your codefile, or even the entire project - every five minutes, or every minute as long as something has been changed. Awesome program. This is a certain fashion of source control, or at least source backup.
(And no I'm not the authour of either application)
However, for your particular problem, if the code is still there in your designer.cs page - maybe you just erased a reference or a namespace. Make sure the namespace matches, and make sure your in your form's code file, that the InitializeComponent(); function is being called (that's what places all the designer's controls onto the form, you know).
In the code behind file click 'undo', not in the designer window. Accept the warning, and when the code comes back, the form should be back to normal, Visual Studio 2015.
When developing AddIns for Visual Studio 2010 the following line fails:
CommandBarEvents handler = (EnvDTE.CommandBarEvents)m_VSStudio.DTE.Events.get_CommandBarEvents(popup);
Update: Forgot to tell that m_VSStudio is of the type DTE2
Where popup is of the type CommandBarPopup (for the type CommandBarControl it works though)
The line fails with this Exception:
System.Runtime.InteropServices.COMException (0x80020003): Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))
The exact same line worked in Visual Studio 2008.
The purpose of the line is to get a handler which handles clickevents, when one clicks the Popup.
After som searching I found this link: http://connect.microsoft.com/VisualStudio/feedback/details/524335/events-get-commandbarevents-exception-on-submenus-reproducible-bug-addin
Which basicly states that it is a known bug, which will not be fixed, because there is a workaround. But unfortunately it does not state the workaround :(
I would be extremely pleased if anybody has a great idea for a workaround ?
The reason why I want to listen to the click events is because I want to show or hide the submenuitems (CommandBarControl) given some condition, when one clicks a menu (CommandBarPopup).
So a workaround that uses something else than the click event would also be appreciated.
Jesper and I talked about this in e-mail. What he was trying to do was ensure that members of a popup menu that he created were in the proper state right before they were shown. He was using the Click even on CommandBarPopup (which was deprecated in 2010 in the move to WPF) to have a way of knowing when he needed to do the state updating. I mentioned the preferred method for doing this (even in 2008) would be to implement IDtCommandtarget on his AddIn class. The VS shell will call this method when it needs to find the status of commands. It will call this method at all the 'regular' times it updates command state (i.e. on idle if needed, right before showing a menu, etc..). Moving to this method works for his scenario and seems to solve his problem.
Ryan
It is unfortunate that the phrase 'our e-mail correspondance' and 'you found a workaround' was put in a public bug with no indication of what the work around was. I suspect the person was trying to do something quite different from you (even if he was using the same event mechanism to hook in), so perhaps we found a better way to do what he needed. I can't think of any easy way to do what you are doing, though if I understood why you were trying to do what you are doing (i.e. are you hiding your own commands? The commands of other people? To what end?) then perhaps we could think of something. Feel free to mail me directly, address is rmolden AT microsoft DOT com, sorry for the inconvienence. We can also follow up here with any work around we find so it will be captured by the internet rememberance machine for all time.