.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Commands not registering

3 REPLIES 3
Reply
Message 1 of 4
rollinson44
554 Views, 3 Replies

Commands not registering

I have been using my applicaiton as I develop it and have had no problem until today. Suddenly my commands are no longer registered in Autocad and no matter what I try I can't get them registered again. The problem began when I added a commandmethod in another class in the project and inlucded the assembly reference to that class. I have since removed that method to the main class and removed the assembly reference; however, I can't get it to work now. I am including the entry class code, if someone might have some insight into this that would be great. This is driving me crazy. I am running Autocad 2008. The debug info under project properties is set to the correct .exe and path. I have the correct references and have tried to remove and reload them with no luck.

using System;

using System.Collections.Generic;

using System.Text;

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.DatabaseServices;

using Autodesk.AutoCAD.Geometry;

using Autodesk.AutoCAD.EditorInput;

using Autodesk.AutoCAD.Runtime;

using Iesi.Collections.Generic;

using System.Threading;


//[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.xml", Watch = true)]

[assembly: ExtensionApplication(typeof(GateConnectionAnalyzer.MainEntry))]

[assembly: CommandClass(typeof(GateConnectionAnalyzer.MainEntry))]


namespace GateConnectionAnalyzer

{

public class MainEntry

: Autodesk.AutoCAD.Runtime.IExtensionApplication

{


private bool initialized = false;

public void Initialize()

{

//setup event handlers for application


AppSessionData.readConfigSettings();

NHibernateUtil.buildSessionFactory(true);

Application.DocumentManager.DocumentToBeDestroyed += new DocumentCollectionEventHandler
(DocumentManager_DocumentToBeDestroyed);

Application.DocumentManager.DocumentCreated += new DocumentCollectionEventHandler(DocumentManager_DocumentCreated);

}


[CommandMethod("drtest", CommandFlags.Session)]

public void begin()

{

FileSelectorForm fsf = new FileSelectorForm();

fsf.Show();

}


[CommandMethod("iembed")]

public void insertField()

{

BlockForm bf = new BlockForm();

bf.Show();

}


[CommandMethod("drupdb", CommandFlags.Session)]

public void runUpdateMethod()

{

BlockEvents.updateDb2();

}


internal void DocumentManager_DocumentToBeDestroyed(object sender, DocumentCollectionEventArgs e)

{

if (initialized)

{

Document doc = e.Document;

doc.Database.ObjectErased -= new ObjectErasedEventHandler(BlockEvents.Database_ObjectErased);

doc.CommandWillStart -= new CommandEventHandler(BlockEvents.doc_CommandBegin);

doc.CommandCancelled -= new CommandEventHandler(BlockEvents.doc_CommandEnded);

doc.CommandEnded -= new CommandEventHandler(BlockEvents.doc_CommandEnded);

}

}


internal void DocumentManager_DocumentCreated(object sender, DocumentCollectionEventArgs e)

{

e.Document.CommandWillStart +=new CommandEventHandler(BlockEvents.doc_CommandBegin);

e.Document.CommandCancelled +=new CommandEventHandler(BlockEvents.doc_CommandEnded);

e.Document.CommandEnded += new CommandEventHandler(BlockEvents.doc_CommandEnded);

initialized = true;

}


public void Terminate()

{

}


}

}

3 REPLIES 3
Message 2 of 4
norman.yuan
in reply to: rollinson44

That fact that your command was working and you have code in the interface-implemeting method Initialize() prompts me that the most possible reason is your code runs into exception in the Initialize() method.

In most case exception that occurs in Initialize() would not kill AutoCAD, it "kills" the loading DLL that causes the Initialize() without saying anything.

I always place try...catch to box all code I have to write in Initialize(), even I do nothig in the catch... part:

public void Initialize()
{
try
{
//your code here
}
catch{}
}


By the way, I saw your commands below which show forms in Acad. According to Acad doucment, you do not use System.Windows.Forms.Form.Show()/ShowDialog() to show win form in Acad, use Autodesk.AutoCAD.ApplicatioonServices.Application.ShowModelessDialog()/ShowModalDialog() instead.

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 4
Anonymous
in reply to: rollinson44

If you use the CommandClass attribute on a class that has command methods,
you must use it on every class that has command methods.

From your description of when the problem started, that seems to be the
problem.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6275687@discussion.autodesk.com...
I have been using my applicaiton as I develop it and have had no problem
until today. Suddenly my commands are no longer registered in Autocad and no
matter what I try I can't get them registered again. The problem began when
I added a commandmethod in another class in the project and inlucded the
assembly reference to that class. I have since removed that method to the
main class and removed the assembly reference; however, I can't get it to
work now. I am including the entry class code, if someone might have some
insight into this that would be great. This is driving me crazy. I am
running Autocad 2008. The debug info under project properties is set to the
correct .exe and path. I have the correct references and have tried to
remove and reload them with no luck.


using System;

using System.Collections.Generic;

using System.Text;

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.DatabaseServices;

using Autodesk.AutoCAD.Geometry;

using Autodesk.AutoCAD.EditorInput;

using Autodesk.AutoCAD.Runtime;

using Iesi.Collections.Generic;

using System.Threading;


//[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.xml",
Watch = true)]

[assembly: ExtensionApplication(typeof(GateConnectionAnalyzer.MainEntry))]

[assembly: CommandClass(typeof(GateConnectionAnalyzer.MainEntry))]


namespace GateConnectionAnalyzer

{

public class MainEntry

: Autodesk.AutoCAD.Runtime.IExtensionApplication

{


private bool initialized = false;

public void Initialize()

{

//setup event handlers for application



AppSessionData.readConfigSettings();

NHibernateUtil.buildSessionFactory(true);

Application.DocumentManager.DocumentToBeDestroyed += new
DocumentCollectionEventHandler
(DocumentManager_DocumentToBeDestroyed);

Application.DocumentManager.DocumentCreated += new
DocumentCollectionEventHandler(DocumentManager_DocumentCreated);

}


[CommandMethod("drtest", CommandFlags.Session)]

public void begin()

{

FileSelectorForm fsf = new FileSelectorForm();

fsf.Show();

}


[CommandMethod("iembed")]

public void insertField()

{

BlockForm bf = new BlockForm();

bf.Show();

}


[CommandMethod("drupdb", CommandFlags.Session)]

public void runUpdateMethod()

{

BlockEvents.updateDb2();

}



internal void DocumentManager_DocumentToBeDestroyed(object sender,
DocumentCollectionEventArgs e)

{

if (initialized)

{

Document doc = e.Document;

doc.Database.ObjectErased -= new
ObjectErasedEventHandler(BlockEvents.Database_ObjectErased);

doc.CommandWillStart -= new
CommandEventHandler(BlockEvents.doc_CommandBegin);

doc.CommandCancelled -= new
CommandEventHandler(BlockEvents.doc_CommandEnded);

doc.CommandEnded -= new CommandEventHandler(BlockEvents.doc_CommandEnded);

}

}



internal void DocumentManager_DocumentCreated(object sender,
DocumentCollectionEventArgs e)

{

e.Document.CommandWillStart +=new
CommandEventHandler(BlockEvents.doc_CommandBegin);

e.Document.CommandCancelled +=new
CommandEventHandler(BlockEvents.doc_CommandEnded);

e.Document.CommandEnded += new
CommandEventHandler(BlockEvents.doc_CommandEnded);

initialized = true;

}


public void Terminate()

{

}


}

}
Message 4 of 4
riley-ge
in reply to: norman.yuan

This is very useful for me, also an artical on http://tson.com/net-autocad-commands-regist/

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost