获取栅格图形名称
请问我从图面上选择了一个 Autodesk.AutoCAD.DatabaseServices.Image 类型的实体,请问用程序如何获取该image图形的名称和位置点? 你选择的应该是 Autodesk.AutoCAD.DatabaseServices.RasterImage 而不是 Autodesk.AutoCAD.DatabaseServices.Image 吧? 我选择的栅格图形就是 Autodesk.AutoCAD.DatabaseServices.Image类型呢 名称是Name属性可以读取,Path可以读取路径,里面也包含了名称位置点应该是Position属性,是一个Point3d类型 要先转换成rasterimage对象 本帖最后由 sailorcwx 于 2011-11-10 13:02 编辑
public void Test5()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptEntityOptions selectOptions = new PromptEntityOptions("\n选择光栅图像");
selectOptions.SetRejectMessage("\n只能选择光栅图像");
selectOptions.AddAllowedClass(typeof(Image),false);
PromptEntityResult selectResult = ed.GetEntity(selectOptions);
if (selectResult.Status != PromptStatus.OK) return;
Transaction tr = doc.TransactionManager.StartTransaction();
using (tr)
{
RasterImage imageSelected = tr.GetObject(selectResult.ObjectId, OpenMode.ForRead) as RasterImage;
ed.WriteMessage("\n图像名称:{0}\n图像路径:{1}\n图像位置:{2},{3},{4}", imageSelected.Name, imageSelected.Path, imageSelected.Position.X.ToString(), imageSelected.Position.Y.ToString(), imageSelected.Position.Z.ToString());
}
}
楼上的请问你是用的cad什么版本? 我用的07版本,把image转换成RasterImage后,RasterImage 是空值啊
附代码如下:
/// <summary>删除选择的块和图片
/// </summary>
/// <returns></returns>
public static int ClearBlockAndImage()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
int count = 0;
ObjectIdCollection colInputEntIds;
PromptSelectionOptions promptSelRess = new PromptSelectionOptions();
promptSelRess.MessageForAdding = "请选择对象";
PromptSelectionResult promptSelRes;
promptSelRes = Editor.GetSelection(promptSelRess);
if (promptSelRes.Status != PromptStatus.OK)
{
return 0;
}
colInputEntIds = new ObjectIdCollection(promptSelRes.Value.GetObjectIds());
using (doc.LockDocument())
{
using (Transaction tran = db.TransactionManager.StartTransaction())
{
try
{
foreach (ObjectId id in colInputEntIds)
{
//实体类型判断
Entity ent = tran.GetObject(id, OpenMode.ForRead) as Entity;
if (ent is BlockReference)// || ent is Autodesk.AutoCAD.DatabaseServices.Image)
{
ent.UpgradeOpen();
ent.Erase();
count++;
}
if (ent is Autodesk.AutoCAD.DatabaseServices.Image)
{
RasterImage imageSelected = tran.GetObject(id, OpenMode.ForRead) as RasterImage;
count++;
}
}
tran.Commit();
}
catch (System.Exception se)
{
ed.WriteMessage("\n" + se.Message + "\n");
}
}
return count;
}
} 并不是转换后是空值,而是你的判断ent is Autodesk.AutoCAD.DatabaseServices.Image有误,你试试我下面这段代码就知道,其实你选择的光栅图像对应的类型应该是rasterimage
public void Test6()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptEntityOptions selectOptions = new PromptEntityOptions("\n选择对象");
PromptEntityResult selectResult = ed.GetEntity(selectOptions);
if (selectResult.Status != PromptStatus.OK) return;
Transaction tr = doc.TransactionManager.StartTransaction();
using (tr)
{
Entity ent = tr.GetObject(selectResult.ObjectId, OpenMode.ForRead) as Entity;
ed.WriteMessage("\n你选择的对象为{0}", ent.GetType().ToString());
}
} 刚用你的代码试了,我选择的对象就是Autodesk.AutoCAD.DatabaseServices.Image类型,我要获取的就是这个image类型的名称,最后再进行删除,如直接根据image的objectid去erase的话只是把image卸载掉,并没有从图面上拆除
页:
[1]
2