2007 + Visua C# 2005
插入光栅图像参照(菜单:“插入”->“光栅图像参照”)的效果:(Azul是图像名)
注意右键菜单的拆离
s20hmmakhrg.jpg
右键拆离的效果:
ahqiyahphv5.jpg
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
下面是通过代码删除实体后的效果:
n3dk2kny5ed.jpg
图像已经不显示了,但图像状态显示为“未参照”。
附删除实体的代码:(写得比较简单)
- static public void DelImage()
- {
- Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
- Transaction t = tm.StartTransaction();
- using (DocumentLock docLock = doc.LockDocument())
- {
- BlockTable bt = (BlockTable)t.GetObject(db.BlockTableId, OpenMode.ForRead);
- BlockTableRecord btr = (BlockTableRecord)t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead);
- foreach (ObjectId id in btr)
- {
- Entity ent = t.GetObject(id, OpenMode.ForWrite) as Entity; if (ent != null)
- {
- ent.Erase();
- ent.Dispose();
-
- }
-
- }
- t.Commit();
- t.Dispose();
- } }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
问题是如何用C#实现如上所示的右键拆离图像参照的效果...
|