using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Windows;
using ACSMCOMPONENTS20Lib;
[assembly: CommandClass(typeof(Rivilis.SheetUtils))]
namespace Rivilis
{
public class SheetUtils
{
[CommandMethod("ImportSheet")]
public void MyCommand()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
if (doc == null) return;
Editor ed = doc.Editor;
AcSmSheetSetMgr mgr = new AcSmSheetSetMgr();
OpenFileDialog dlgDst = new OpenFileDialog (
"Файл подшивки", "SheetSetFile", "dst", "Выберите файл подшивки", 0);
System.Windows.Forms.DialogResult res = dlgDst.ShowDialog();
if (res != System.Windows.Forms.DialogResult.OK) return;
OpenFileDialog dlgDwg = new OpenFileDialog(
"Файл чертежа", "Drawing", "dwg", "Выберите файл чертежа", 0);
res = dlgDwg.ShowDialog();
if (res != System.Windows.Forms.DialogResult.OK) return;
PromptStringOptions prStr =
new PromptStringOptions("\nУкажите имя Layout: ");
prStr.AllowSpaces = true;
PromptResult rs = ed.GetString(prStr);
if (rs.Status != PromptStatus.OK) return;
ImportSheet(dlgDst.Filename, dlgDwg.Filename, rs.StringResult);
}
void ImportSheet(string dstFile, string dwgFile, string layoutName)
{
AcSmSheetSetMgr mgr = new AcSmSheetSetMgr();
AcSmDatabase db = mgr.OpenDatabase(dstFile, false);
db.LockDb(db);
try
{
AcSmSheetSet sheetSet = db.GetSheetSet();
AcSmAcDbLayoutReference lRef = new AcSmAcDbLayoutReference();
lRef.InitNew(sheetSet);
lRef.SetFileName(dwgFile);
lRef.SetName(layoutName);
AcSmSheet sheet = sheetSet.ImportSheet(lRef);
sheetSet.InsertComponent(sheet, null);
}
finally
{
db.UnlockDb(db, true);
mgr.Close(db);
}
}
}
}