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

Cannot remove events in AutoCAD 2008?

11 REPLIES 11
Reply
Message 1 of 12
Anonymous
704 Views, 11 Replies

Cannot remove events in AutoCAD 2008?

Is this a bug in AutoCAD 2008? After I execute the "StopCapturecircles" command in the following codes,the "ObjectAppended" event handler is still be executed?
using AAAS = Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Internal;
namespace eventbug
{
public class ggClass
{
private const string New_bolthole_layer = "BoltHoleLayer";
[CommandMethod("capturelines")]
static public void Capturecircles()
{
Database db = AAAS.Application.DocumentManager.MdiActiveDocument.Database;
ggClass.gg_Creatlayer(New_bolthole_layer, db);
db.ObjectAppended += new ObjectEventHandler(ObjectAppended);
}
[CommandMethod("StopCapturecircles")]
static public void stopCapturecircles()
{
Database db = AAAS.Application.DocumentManager.MdiActiveDocument.Database;
db.ObjectAppended -= new ObjectEventHandler(ObjectAppended);
}
static private void gg_Creatlayer(string layername, Database db)
{
using (Transaction trans = db.TransactionManager.StartTransaction())
{
ObjectId layertableid = db.LayerTableId;
LayerTable layers = (LayerTable)trans.GetObject(layertableid, OpenMode.ForRead);
if (layers.Has(layername))
{
return;
}
else
{
LayerTableRecord newlayer = new LayerTableRecord();
newlayer.Name = layername;
layers.UpgradeOpen();
layers.Add(newlayer);
trans.AddNewlyCreatedDBObject(newlayer, true);
trans.Commit(); trans.Dispose();
}
}
}
static void ObjectAppended(object sender, ObjectEventArgs e)
{
//throw new System.Exception("The method or operation is not implemented.");
if (e.DBObject is Line)
{
Line newLine = e.DBObject as Line;
newLine.UpgradeOpen();
if (newLine.IsWriteEnabled)
{
newLine.Layer = New_bolthole_layer;
}
}
}
}
}
11 REPLIES 11
Message 2 of 12
Anonymous
in reply to: Anonymous

Congradulations.

Defect confirmed.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5584661@discussion.autodesk.com...
Is this a bug in AutoCAD 2008? After I execute the "StopCapturecircles" command in the following codes,the "ObjectAppended" event handler is still be executed?
using AAAS = Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Internal;
namespace eventbug
{
public class ggClass
{
private const string New_bolthole_layer = "BoltHoleLayer";
[CommandMethod("capturelines")]
static public void Capturecircles()
{
Database db = AAAS.Application.DocumentManager.MdiActiveDocument.Database;
ggClass.gg_Creatlayer(New_bolthole_layer, db);
db.ObjectAppended += new ObjectEventHandler(ObjectAppended);
}
[CommandMethod("StopCapturecircles")]
static public void stopCapturecircles()
{
Database db = AAAS.Application.DocumentManager.MdiActiveDocument.Database;
db.ObjectAppended -= new ObjectEventHandler(ObjectAppended);
}
static private void gg_Creatlayer(string layername, Database db)
{
using (Transaction trans = db.TransactionManager.StartTransaction())
{
ObjectId layertableid = db.LayerTableId;
LayerTable layers = (LayerTable)trans.GetObject(layertableid, OpenMode.ForRead);
if (layers.Has(layername))
{
return;
}
else
{
LayerTableRecord newlayer = new LayerTableRecord();
newlayer.Name = layername;
layers.UpgradeOpen();
layers.Add(newlayer);
trans.AddNewlyCreatedDBObject(newlayer, true);
trans.Commit(); trans.Dispose();
}
}
}
static void ObjectAppended(object sender, ObjectEventArgs e)
{
//throw new System.Exception("The method or operation is not implemented.");
if (e.DBObject is Line)
{
Line newLine = e.DBObject as Line;
newLine.UpgradeOpen();
if (newLine.IsWriteEnabled)
{
newLine.Layer = New_bolthole_layer;
}
}
}
}
}
Message 3 of 12
Anonymous
in reply to: Anonymous

Shouldn't you be removing the handler you added in Capturecircles?
--
Owen Wengerd
President, ManuSoft ==> http://www.manusoft.com
VP Americas, CADLock, Inc. ==> http://www.cadlock.com
Message 4 of 12
Anonymous
in reply to: Anonymous

Hi Owen.

He does remove it (in stopCapturecircles())
but the event continues to fire.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

"Owen Wengerd" wrote in message news:5585957@discussion.autodesk.com...
Shouldn't you be removing the handler you added in Capturecircles?
--
Owen Wengerd
President, ManuSoft ==> http://www.manusoft.com
VP Americas, CADLock, Inc. ==> http://www.cadlock.com
Message 5 of 12
Anonymous
in reply to: Anonymous

Tony:

> He does remove it (in stopCapturecircles())
> but the event continues to fire.

Excuse my .NET ignorance, but to me it looks like he is creating a new
handler, then trying to remove the new one while leaving the old one in
place. No?
--
Owen Wengerd
President, ManuSoft ==> http://www.manusoft.com
VP Americas, CADLock, Inc. ==> http://www.cadlock.com
Message 6 of 12
Anonymous
in reply to: Anonymous

"Owen Wengerd" wrote:

>> it looks like he is creating a new handler, then
>> trying to remove the new one while leaving the
>> old one in place. No?

Yes it appears that way because the names of the
types are confusing. The 'handler' is the method of
the class that is called to handle the event. The
object he creates via 'new ObjectEventHandler()', is
actually a reference to the handler (which is passed
as the parameter).


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com
Message 7 of 12
Anonymous
in reply to: Anonymous

Tony:

Ok, I see what you're saying. I wonder though if the "reference to the
handler" isn't really a thunk which simply passes control to the actual
handler. If this were the case, the 'handler' from AutoCAD's perspective
would be the instance of the thunk. That is, different instances of the
thunk would appear to AutoCAD as different event handlers, and would
presumably result in the behavior that the OP is observing.

For the record, I'm pretty much clueless when it comes to .NET, so this is
all wild speculation on my part. 🙂
--
Owen Wengerd
President, ManuSoft ==> http://www.manusoft.com
VP Americas, CADLock, Inc. ==> http://www.cadlock.com


"Tony Tanzillo" wrote in message
news:5587182@discussion.autodesk.com...
"Owen Wengerd" wrote:

>> it looks like he is creating a new handler, then
>> trying to remove the new one while leaving the
>> old one in place. No?

Yes it appears that way because the names of the
types are confusing. The 'handler' is the method of
the class that is called to handle the event. The
object he creates via 'new ObjectEventHandler()', is
actually a reference to the handler (which is passed
as the parameter).


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com
Message 8 of 12
Anonymous
in reply to: Anonymous

The codes run well in AutoCAD07.. Message was edited by: csharpbird
Message 9 of 12
Anonymous
in reply to: Anonymous

Confirmed

~'J'~
Message 10 of 12
Anonymous
in reply to: Anonymous

I wouldn't call it a thunk, just a class that contains
the info needed to invoke the handler.

The main thing is that I also have code that was
affected by this and worked just fine in '07, but in
'08 with the exact same code, the event continues
to fire even after its removed.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

"Owen Wengerd" wrote in message news:5587382@discussion.autodesk.com...
Tony:

Ok, I see what you're saying. I wonder though if the "reference to the
handler" isn't really a thunk which simply passes control to the actual
handler. If this were the case, the 'handler' from AutoCAD's perspective
would be the instance of the thunk. That is, different instances of the
thunk would appear to AutoCAD as different event handlers, and would
presumably result in the behavior that the OP is observing.

For the record, I'm pretty much clueless when it comes to .NET, so this is
all wild speculation on my part. 🙂
--
Owen Wengerd
President, ManuSoft ==> http://www.manusoft.com
VP Americas, CADLock, Inc. ==> http://www.cadlock.com


"Tony Tanzillo" wrote in message
news:5587182@discussion.autodesk.com...
"Owen Wengerd" wrote:

>> it looks like he is creating a new handler, then
>> trying to remove the new one while leaving the
>> old one in place. No?

Yes it appears that way because the names of the
types are confusing. The 'handler' is the method of
the class that is called to handle the event. The
object he creates via 'new ObjectEventHandler()', is
actually a reference to the handler (which is passed
as the parameter).


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com
Message 11 of 12
Ed.Jobe
in reply to: Anonymous

Is this typical of all events or just this one?

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 12 of 12
Anonymous
in reply to: Anonymous

Don't know, haven't checked yet.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5589306@discussion.autodesk.com...
Is this typical of all events or just this one?

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