Hi,
I have this Acad plugin (C#), where I simply create a Ribbon, Button on it that executes a Command.
Windows 7, AutoCAD 2013 all running x64.
Used the ObjectARX x64 Libraries for my references.
In my environment, everything works just fine, on my clients workstations... it shows 'Unhandled access violation reading 0x0000 exception'
Since client installed AutoCAD 2012 and then 2013, I tried a Repair, to no result.
Have verified all references, put all ObjectARX references, just to make sure, put debug lines in the code.
It crashes at first line:
Autodesk.Windows.RibbonControl ribbonControl = Autodesk.Windows.ComponentManager.Ribbon;
All other Commands seem to run just fine.
Any clue what could be the cause, what I could try more?
Maybe is just a matter of timing...when is this code called? During startup?
Please also try with
Autodesk.Windows.RibbonControl ribbonControl =
Autodesk.AutoCAD.Ribbon.RibbonServices.RibbonPaletteSet.RibbonControl;
And make sure all references are from ObjectARX folder with Copy Local equals FALSE.
All references are already set to CopyLocal = False
Code is called by command (so after loading of all AutoCAD stuff, no?)
As far as I understand, Autodesk.AutoCAD.Ribbon.RibbonServices.RibbonPaletteSet.RibbonControl is an internal API (AcRibbon.dll), which I cannot reference?
Visual Studio Compiler tells me a property is used as a type...
All of a sudden, I am losing it 🙂
Also, you mention possible timing issue?
Wonder how (my environment ok, clients not?)
However, I found code that puts this kind of thing in OnIdle... mmm
Don't loose it just yet 🙂
It should be under AcWindows.dll and AdWindows.dll references.
Are you using on the same version of AutoCAD?
About the timing, don't use OnIdle, but maybe something like
>>>
public class AdskApplication : IExtensionApplication
{
public void Initialize()
{
if (Autodesk.Windows.ComponentManager.Ribbon == null)
{
//load the custom Ribbon on startup, but at this point
//the Ribbon control is not available, so register for
//an event and wait
Autodesk.Windows.ComponentManager.ItemInitialized +=
new EventHandler<RibbonItemEventArgs>(ComponentManager_ItemInitialized);
}
else
{
//the assembly was loaded using NETLOAD, so the ribbon
//is available and we just create the ribbon
createRibbon();
}
}
public void Terminate()
{
}
void ComponentManager_ItemInitialized(object sender, RibbonItemEventArgs e)
{
//now one Ribbon item is initialized, but the Ribbon control
//may not be available yet, so check if before
if (Autodesk.Windows.ComponentManager.Ribbon != null)
{
//ok, create Ribbon
createRibbon();
//and remove the event handler
Autodesk.Windows.ComponentManager.ItemInitialized -=
new EventHandler<RibbonItemEventArgs>(ComponentManager_ItemInitialized);
}
}
}
<<<
Have tried the Autodesk.AutoCAD.Ribbon.RibbonServices.RibbonPaletteSet.RibbonControl... No Exception, but nothing else happens? So the custom Ribbon does not show at all.
I catched both System.Exception and Autodesk.AutoCAD.Runtime.Exception, but that does not reveal anything.
Since I explicitly do a NETLOAD and then type my command, I am pretty sure it is no timing issue.
Am I right? However, Autodesk.Windows.ComponentManager.Ribbon remains null???
Any other ideas?
I'd highly recommend that you instead hook the Application.Idle Event in Initialize(), and then in your Idle Event handler, unregister the Event handler first, and then add your component(s) to ComponentManager.
Cheers
"How we think determines what we do, and what we do determines what we get."
@BlackBox_ wrote:I'd highly recommend that you instead hook the Application.Idle Event in Initialize(), and then in your Idle Event handler, unregister the Event handler first, and then add your component(s) to ComponentManager.
Cheers
For reference:
Add Custom RibbonTab at Startup
"How we think determines what we do, and what we do determines what we get."
This is very useful information, I keep it for further reference.
Nevertheless, the client works in Classic View and needs more than just buttons, so a Tool Palette is more appropriate.
That works from the very first time!
Thanks for all the help.
@winnes wrote:This is very useful information, I keep it for further reference.
Nevertheless, the client works in Classic View and needs more than just buttons, so a Tool Palette is more appropriate.
That works from the very first time!
Thanks for all the help.
That is kind of you to say, winnes; I'm happy to help.
It sounds like you've got the Tool Palette under control, but if you've ever been interested in going a bit above and beyond, you might consider adding a Windows Presentation Foundation (WPF) UserControl, as Kean demonstrates here:
"How we think determines what we do, and what we do determines what we get."
Sometimes, one needs to go fast... like this time.
Therefore, further reference, like in a "next" project.
For Office automation tasks I am already a longtime believer of the Ribbon...
WPF on the other hand is fairly new to me...
But there again, Kean is one of THE references, and once again it will certainly serve in the next iteration of this, or another project.
I already have some ideas for future use.
Thanks for the link
You're welcome; I'm happy to help. :beer:
"How we think determines what we do, and what we do determines what we get."
Hi Augusto,
this code saved me. He really works great. Thank you very much.
Greetings from Germany. Wish you a merry Christmas and a really good next year.
Jürgen
Can't find what you're looking for? Ask the community or share your knowledge.