.NET

Reply
Valued Contributor
dynamicscope
Posts: 95
Registered: ‎04-04-2012
Message 1 of 3 (164 Views)
Accepted Solution

eNoDocument Exception when auto-loading CustomCUIX

164 Views, 2 Replies
08-06-2012 04:47 AM

Hi, I have the following block of code in myPlugin.cs in IExtensionApplication.Initialize() method...

 

 

            object oldCmdEcho = Application.GetSystemVariable("CMDECHO");

            object oldFileDia = Application.GetSystemVariable("FILEDIA");

 

            Application.SetSystemVariable("CMDECHO", 0);

            Application.SetSystemVariable("FILEDIA", 0);

 

            Document doc = Application.DocumentManager.MdiActiveDocument;             

            doc.SendStringToExecute(

              "_.cuiload "

              + "MyCui.cuix"

              + " ",

              false, false, false

            );

           

            Application.SetSystemVariable("FILEDIA", oldFileDia);

            Application.SetSystemVariable("CMDECHO", oldCmdEcho);

 

 

(Assuming MyCui.cuix already exists)

 

It's fine if I load this managed dll via "netload" command (after the document is loaded)

 

But it seems there is a problem if I try to load this using demand load (auto-load at AutoCad startup)

It seems like DocumentManager.MdiActiveDocument gets called before the document is fully loaded.

This code gives me eNoDocument exception.

 

Anybody else have had the same issue?

Is there other approaches to auto-load the custom cuix?

 

Thank you for your help always.

 

 

Hi,

 

>> Is there other approaches to auto-load the custom cuix?

don't use SendCommand, at least not when you start it during the initialization-process.

You have either the chance to use an eventhandler watching AutoCAD to get quiescent (and then do your SendCommand) or load the menues with the menu-collection-functions.

Make sure that when you already have loaded the menu (AutoCAD normally starts with the menues that where loaded previously), so an additional load would result in an error.

 

>> using demand load (auto-load at AutoCad startup)

Be careful! "demand-load" loads a command (and it's modules) at the time a command is started by the user, not when AutoCAD starts! "demand-load" and "load during AutoCAD-start" are two different things!

 

- alfred -

*Expert Elite*
Alfred.NESWADBA
Posts: 9,371
Registered: ‎06-29-2007
Message 2 of 3 (162 Views)

Re: eNoDocument Exception when auto-loading CustomCUIX

08-06-2012 05:06 AM in reply to: dynamicscope

Hi,

 

>> Is there other approaches to auto-load the custom cuix?

don't use SendCommand, at least not when you start it during the initialization-process.

You have either the chance to use an eventhandler watching AutoCAD to get quiescent (and then do your SendCommand) or load the menues with the menu-collection-functions.

Make sure that when you already have loaded the menu (AutoCAD normally starts with the menues that where loaded previously), so an additional load would result in an error.

 

>> using demand load (auto-load at AutoCad startup)

Be careful! "demand-load" loads a command (and it's modules) at the time a command is started by the user, not when AutoCAD starts! "demand-load" and "load during AutoCAD-start" are two different things!

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 3 of 3 (157 Views)

Re: eNoDocument Exception when auto-loading CustomCUIX

08-06-2012 07:29 AM in reply to: dynamicscope

Better use instead:

 

   AcadDocument acdoc = doc.AcadDocument as AcadDocument;
                    acdoc.SendCommand("_CUILOAD+  "MyCui.cuix"

              + " ",

"\n");

 

and also use:

using Autodesk.AutoCAD.Interop.Common;

using Autodesk.AutoCAD.Interop;

 

in References

Just on the quick glance, sorry

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!