public void MyTxtExp()
{
AcadDocument acadDocument = doc.GetAcadDocument() as AcadDocument;
AcadApplication acadApplication = Application.AcadApplication as AcadApplication;
PromptPointResult ppr1 = ed.GetPoint("请选择第一个点");
if (ppr1.Status != PromptStatus.OK)
{
return;
}
Point3d p1 = ppr1.Value;
PromptPointResult ppr2 = ed.GetCorner("请选择第二个点", p1);
if (ppr2.Status != PromptStatus.OK)
{
return;
}
Point3d p2 = ppr2.Value;
PromptSelectionResult psr = ed.SelectWindow(p1, p2);
if (psr.Status != PromptStatus.OK)
{
return;
}
List<AcadEntity> objs = new List<AcadEntity>();
List<Entity> entities = new List<Entity>();
using (Transaction trans = db.TransactionManager.StartTransaction())
{
foreach (ObjectId id in psr.Value.GetObjectIds())
{
Entity obj = id.GetObject(OpenMode.ForRead) as Entity;
entities.Add(obj);
objs.Add(obj.AcadObject as AcadEntity);
}
trans.Commit();
}
Extents3d extents = Extents3dEx.Ex_GetEntsExtents3d(entities);
AcadSelectionSet acadSelectionSet = null;
acadSelectionSet = acadDocument.SelectionSets.Add("SS01");
string fullFileName = acadDocument.FullName;
string direc = Path.GetDirectoryName(fullFileName);
string fileName = Path.GetFileNameWithoutExtension(fullFileName);
if (acadSelectionSet != null)
{
acadSelectionSet.AddItems(objs.ToArray());
acadDocument.Export(direc + "\\" + fileName, "wmf", acadSelectionSet);
}
string importFileName = direc + "\\" + fileName + ".wmf";
double[] point = new double[] { 0, 0, 0 };
acadDocument.Import(importFileName, point, 1);
acadSelectionSet.Delete();
using (Transaction trans = db.TransactionManager.StartTransaction())
{
Entity ent = Utils.EntLast().GetObject(OpenMode.ForWrite) as Entity;
Point3d basePoint = ent.GeometricExtents.MaxPoint;
Point3d targetPoint = extents.MaxPoint;
double baseDis = ent.GeometricExtents.MinPoint.DistanceTo(basePoint);
double targetDis = extents.MinPoint.DistanceTo(targetPoint);
double scale = targetDis / baseDis;
ent.Ex_Move(basePoint, targetPoint);
ent.Ex_Scale(targetPoint, scale);
DBObjectCollection dbObjs = new DBObjectCollection();
ent.Explode(dbObjs);
foreach (var obj in dbObjs)
{
db.Ex_AddToModelSpace(obj as Entity);
}
ent.Erase(true);
for (int i = 0; i < entities.Count; i++)
{
ent = entities[i].ObjectId.GetObject(OpenMode.ForWrite) as Entity;
ent.Erase(true);
}
trans.Commit();
}
}
分类:
CAD二次开发
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义