using System;
using System.Windows.Forms;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using AcAp = Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Windows;
[assembly: CommandClass(typeof(DXFOUT.Utils))]
namespace DXFOUT
{
public class Utils
{
[CommandMethod("MYDXFOUT")]
public void MyDxfOut()
{
Document doc = AcAp.Application.DocumentManager.MdiActiveDocument;
if (doc == null) return;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptSelectionOptions prOpts = new PromptSelectionOptions();
prOpts.MessageForAdding = "Выберите примитивы для экспорта в DXF: ";
PromptSelectionResult res = ed.GetSelection(prOpts);
if (res.Status != PromptStatus.OK || res.Value.Count == 0) return;
Autodesk.AutoCAD.Windows.SaveFileDialog dlg =
new Autodesk.AutoCAD.Windows.SaveFileDialog("Укажите имя dxf-файла", "", "dxf", "MyDxfOut",
Autodesk.AutoCAD.Windows.SaveFileDialog.SaveFileDialogFlags.NoUrls);
DialogResult ds = dlg.ShowDialog();
if (ds != DialogResult.OK) return;
// Создаём новую базу и копируем туда выбранные примитивы
using (ObjectIdCollection objs = new ObjectIdCollection(res.Value.GetObjectIds())) {
using (Database tempDb = db.Wblock(objs, Point3d.Origin)) {
// Выполняем DXFOUT
// Тут можно играться параметрами: http://adn-cis.org/soxranenie-chertezha-v-dxf-formate.html
tempDb.DxfOut(dlg.Filename, 16, false);
}
}
}
}
}