如何通过c#炸开代理对象ACAD_PROXY_ENTITY
网上下载的代码,可惜不能炸开ACAD_PROXY_ENTITY对象。using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.ApplicationServices;
namespace ExplodeProxyMgd
{
public class ExplodeProxy
{
/// <summary>
/// Explode proxy entity to blockreference
/// Return string name of blockreference in drawing database
/// </summary>
/// <param name="rbArgs">Lisp arguments: entity objectId, string BlockPrefix</param>
/// <returns>string BlockReference name</returns>
public static TypedValue ProxyExplodeToBlock(ResultBuffer rbArgs)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
TypedValue res = new TypedValue((int)LispDataType.Text,"");
if (rbArgs.AsArray().Length == 2)
{
TypedValue entity = rbArgs.AsArray();
TypedValue blkPrefix = rbArgs.AsArray();
if ((entity.TypeCode == (int)LispDataType.ObjectId) && (blkPrefix.TypeCode == (int)LispDataType.Text))
{
using (Transaction tr = doc.TransactionManager.StartTransaction())
{
try
{
ObjectId id = (ObjectId)entity.Value;
DBObjectCollection objs = new DBObjectCollection();
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
Entity entx = (Entity)tr.GetObject(id, OpenMode.ForWrite);
entx.Explode(objs);
string blkName = blkPrefix.Value.ToString() + entx.Handle.ToString();
if (bt.Has(blkName) == false)
{
BlockTableRecord btr = new BlockTableRecord();
btr.Name = blkName;
bt.UpgradeOpen();
ObjectId btrId = bt.Add(btr);
tr.AddNewlyCreatedDBObject(btr, true);
foreach (DBObject obj in objs)
{
Entity ent = (Entity)obj;
btr.AppendEntity(ent);
tr.AddNewlyCreatedDBObject(ent, true);
}
}
res = new TypedValue((int)LispDataType.Text, blkName);
tr.Commit();
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
tr.Abort();
ed.WriteMessage(ex.Message);
}
}
}
}
return res;
}
/// <summary>
/// Explode proxy entity in place
/// </summary>
/// <param name="rbArgs">entity name</param>
public static void ProxyExplodeInPlace(ResultBuffer rbArgs)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
if (rbArgs.AsArray().Length == 1)
{
TypedValue entity = rbArgs.AsArray().First();
if (entity.TypeCode == (int)LispDataType.ObjectId)
{
using (Transaction tr = doc.TransactionManager.StartTransaction())
{
try
{
ObjectId id = (ObjectId)entity.Value;
DBObjectCollection objs = new DBObjectCollection();
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
Entity entx = (Entity)tr.GetObject(id, OpenMode.ForWrite);
entx.Explode(objs);
entx.Erase();
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
foreach (DBObject obj in objs)
{
Entity ent = (Entity)obj;
btr.AppendEntity(ent);
tr.AddNewlyCreatedDBObject(ent, true);
}
tr.Commit();
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
tr.Abort();
ed.WriteMessage(ex.Message);
}
}
}
}
}
}
}
ExplodeProxy提供了供lisp调用的函数,只是只有arx文件,没有源码。
页:
[1]