2
我需要批量導入dgns。我可以用用在API的最新命令選項做到這一點:在會話上下文中運行AutoCAD命令
Application.DocumentManager.MdiActiveDocument.Editor.Command("-dgnimport", currentdgnname, "", "Master", "Standard");
然而,問題是,我還需要控制保存繪圖(和保存的文件名)。我不明白的方式來做到這一點沒有在會議環境中使用我的命令是這樣的:
const string DGNIMPORTBATCHname = "DGNIMPORTBATCH";
[CommandMethod(DGNIMPORTBATCHname, CommandFlags.Session)]
的Editor.Command方法雖然只有文檔上下文。
添加文檔鎖不起作用。有沒有辦法在會話命令中切換到在文檔上下文中運行代碼?
**編輯:示例代碼與Activationcontext:
const string DGNIMPORTBATCHname = "DGNIMPORTBATCH";
[CommandMethod(DGNIMPORTBATCHname)]
public static void RunDGNIMPORTBATCH()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
OpenFileDialog ofd = new OpenFileDialog("Convert DGNs", "", "dgn", "", OpenFileDialog.OpenFileDialogFlags.AllowMultiple);
System.Windows.Forms.DialogResult dr = ofd.ShowDialog();
if (dr != System.Windows.Forms.DialogResult.OK)
return;
foreach (string f in ofd.GetFilenames())
{
string dwgfilename = Path.Combine(Path.GetDirectoryName(f), Path.GetFileNameWithoutExtension(f) + ".dwg");
if (File.Exists(dwgfilename))
File.Delete(dwgfilename);
currentdgnname = f;
currentdwgname = dwgfilename;
List<string> names = new List<string>() { currentdgnname, currentdwgname };
//creates our document and sets it current Application.DocumentManager.ExecuteInApplicationContext(CreateDGNDocHelper, names);
currentdoc.Editor.Command("-dgnimport", currentdgnname, "", "Master", "Standard");
currentdoc.Editor.Command("._ZOOM", "Extents");
}
}
static Document currentdoc;
static void CreateDGNDocHelper(object data)
{
currentdoc = Application.DocumentManager.Add("acad.dwt");
Application.DocumentManager.MdiActiveDocument = currentdoc;
}
static string currentdgnname;
static string currentdwgname;
我正試圖按照這個。但唯一的初始文件得到的命令。 –
@DavidWolfe,你能詳細說明一下嗎? –
剛剛添加的示例代碼 –