- using System;
- using System.Collections.Generic;
- using System.Text;
- using Autodesk..Runtime;
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.EditorInput;
- namespace TestClassLib
- {
- public class Class1 : IExtensionApplication
- {
- #region IExtensionApplication 成员 public void Initialize()
- {
- AddDatabaseEvent();
-
- } public void Terminate()
- {
-
-
- } #endregion public static bool b_DbEvent;
- public void AddDatabaseEvent()
- {
- // Get the current document
- Document acDoc = Application.DocumentManager.MdiActiveDocument;
- Database db = acDoc.Database;
-
- db.ObjectAppended +=
- new ObjectEventHandler(DatabaseAppended);
- acDoc.Editor.WriteMessage("\nEvent added!\n");
- b_DbEvent = true; } [CommandMethod("RemovevDatabaseEvent")]
- public void RemoveDatabaseEvent()
- {
- // Get the current document
- Document acDoc = Application.DocumentManager.MdiActiveDocument;
- Database db = acDoc.Database;
-
- db.ObjectAppended -=
- new ObjectEventHandler(DatabaseAppended);
- acDoc.Editor.WriteMessage("\nEvent removed!\n");
- b_DbEvent = false;
- }
- public void DatabaseAppended(object senderObj,
- ObjectEventArgs dbAdded)
- {
- //App.ShowAlertDialog("Database added!");
- RemoveDatabaseEvent();
- InterZ();
- AddDatabaseEvent(); }
- public void InterZ()
- {
-
- Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
- Editor ed = doc.Editor;
- Database db = doc.Database; using(DocumentLock docLock = doc.LockDocument())
- {
- PromptSelectionResult curSR;
- curSR = ed.SelectLast();
- if (curSR.Status != PromptStatus.OK || curSR.Value.Count == 0)
- return;
-
- ObjectId[] ids = curSR.Value.GetObjectIds();
- DBPoint dbpt = null;
- Polyline pln = null; foreach (ObjectId id0 in ids)
- {
- #region foreach
- Transaction tr = db.TransactionManager.StartTransaction();
- Entity ent = tr.GetObject(id0, OpenMode.ForRead) as Entity; dbpt = ent as DBPoint;
- pln = ent as Polyline; tr.Dispose(); #endregion } }
-
- } }
- }
画直线、点的时候,都没有问题,画多义线(Polyline、Polyline3d)的时候,就会有致命错误另外,选中一个点,复制,粘贴,也会报错,但不知道错在哪里!?
V C# 2005 + AutoCAD2007,附件要改成.cs文件
请各位指教
|