malasky 发表于 2010-7-27 18:35:00

[求助]如何“拆离”光栅图像参照???

2007 + Visua C# 2005
插入光栅图像参照(菜单:“插入”->“光栅图像参照”)的效果:(Azul是图像名)
注意右键菜单的拆离



         
右键拆离的效果:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
下面是通过代码删除实体后的效果:


图像已经不显示了,但图像状态显示为“未参照”。
附删除实体的代码:(写得比较简单)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, 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#实现如上所示的右键拆离图像参照的效果...

christinary 发表于 2021-3-16 19:47:00

试试看,看界面有没有及时更新

malasky 发表于 2010-7-27 20:55:00

没人在看吗?我觉得是不是在Dictionary里面也要删除图像才行?
自己去研究研究了,也等待高手解答和讨论。

雪山飞狐_lzh 发表于 2010-7-27 22:21:00

图直接上传吧,看不见

malasky 发表于 2010-7-28 08:45:00

图像已经上传。。。

在firefox上看明明可以看到图的,怎么用ie看就是baidu了。

malasky 发表于 2010-7-28 19:40:00

还是没人看吗???
~~~~~~~~~~~
自己已解决!
附代码      
      public void SeeDict()
      {
            Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
            using (Transaction t = tm.StartTransaction())
            {
                // open the dictionary
                Autodesk.AutoCAD.DatabaseServices.ObjectId imgDictID = RasterImageDef.GetImageDictionary(db);
                DBDictionary imgDict;
                if (imgDictID.OldId != 0)
                {
                  imgDict = (DBDictionary)t.GetObject(imgDictID, OpenMode.ForWrite);
                  imgDict.Erase();
                  imgDict.Dispose();
                }                t.Commit();
            }
         }
首先要插入光栅图像参照(可以插入多个,会全部拆离),才可以看到效果。
删除实体(一楼的代码)相当于选中图像然后按Delete键,在外部参照中的状态显示的是“未参照”,因为在Dictionary中没有Erase掉。

雪山飞狐_lzh 发表于 2010-7-28 19:47:00

if (imgDictID != ObjectId.Null)
这样好些?

malasky 发表于 2010-7-28 20:06:00


好像好些...
不知道这个OldId到底是什么意思

雪山飞狐_lzh 发表于 2010-9-17 13:08:00

试下,删除名为Azui的参照
                  imgDict = (DBDictionary)t.GetObject(imgDictID, OpenMode.ForRead);
                  DBObject obj = t.GetObject(imgDict.GetAt(“Azul"), OpenMode.ForWrite);
                  obj.Erase();

malasky 发表于 2010-9-17 13:51:00

好的,解决了!多谢了!
页: [1] 2
查看完整版本: [求助]如何“拆离”光栅图像参照???