.NET

Reply
Active Contributor
calvindale
Posts: 33
Registered: ‎03-11-2010
Message 1 of 2 (289 Views)

Null Reference Thrown at Autodesk.AutoCAD.EditorInput.Editor.get_IsQuiescent()

289 Views, 1 Replies
11-04-2011 04:59 PM

I have a simple method which checks and records the existence of table entities.

 

When the method exits (in a VS debug session and control returns to AutoCAD), AutoCAD throws this exception.

 

System.NullReferenceException: Object reference not set to an instance of an object.
   at Autodesk.AutoCAD.EditorInput.Editor.get_IsQuiescent()
   at Autodesk.AutoCAD.Ribbon.RibbonPaletteSet.AcadApplication_Idle(Object sender, EventArgs e)
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at Autodesk.AutoCAD.ApplicationServices.Application.raise_Idle(Object value0, EventArgs value1)
   at Autodesk.AutoCAD.ApplicationServices.Application.OnIdle()

 

And it seems to endlessly throw it in an infinite loop.

 

Here's the method:

 

 

 

        [CommandMethod("HasTables")]
        public static void Update__Utility_AcadFixTablesLog_HasTables() {
            const string connectionString = @"......";
            using (var db = new ProductCatalogEntities(connectionString)) {
                using (var document = Application.DocumentManager.MdiActiveDocument) {
                    TypedValue[] typedValues = { new TypedValue((int)DxfCode.Start, "ACAD_TABLE") };
                    SelectionFilter selectionFilter = new SelectionFilter(typedValues);
                    var rec = db.AcadFixTablesLogs.FirstOrDefault(_ => String.Compare(_.FileName, document.Name, false) == 0);
                    var promptSelectionResult = document.Editor.SelectAll(selectionFilter);
                    var hasTablesResult = promptSelectionResult.Status == PromptStatus.None;
                    if (rec != null) {
                        rec.HasTables = hasTablesResult;
                        db.SaveChanges();
                    }
                }
            }
        }

 

 

 

 

Any ideas?  Thanks!

Active Contributor
HomeBoyLV
Posts: 47
Registered: ‎06-04-2004
Message 2 of 2 (242 Views)

Re: Null Reference Thrown at Autodesk.AutoCAD.EditorInput.Editor.get_IsQuiescent

11-07-2011 04:08 PM in reply to: calvindale

Are you calling this routine directly from your pallett? Sounds like you are call this from the "ApplicationContext". Try using SendStringToExec to force it into "DocumentContext" and see if that fixes it.

 

HomeBoy Out

 

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!