本文介绍了如何使用C#在acad.exe中关闭文件以保持acad.exe运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2010,并且有一个要在AutoCAD中打开的.DWG文件.直到现在我都用过.

I am using visual studio 2010 and I am having a .DWG file which I want to open in autocad. Till now I have used this.

Process p = new Process();
ProcessStartInfo s = new ProcessStartInfo("D:/Test File/" + fileName);
p.StartInfo = s;
p.Start();

但是我要关闭的是Autocad内的文件,而不是autocad本身. (意味着atocad.exe应该保持运行).

But what I want is to close the file inside the Autocad but not the autocad itself. (Means atocad.exe should be kept running).

到目前为止,我已经使用了它,但是它关闭了acad.exe而不是文件.

Till now I hve used this but its closing the acad.exe not the file.

foreach (Process Proc in Process.GetProcesses())
{
    if (Proc.ProcessName.Equals("acad"))
    {
        Proc.CloseMainWindow();
        Proc.Kill();
    }
}

推荐答案

要执行文件关闭,最好的解决方法是按照此,并使用以下代码更改以下代码.

To perform the closing of file, best way out is to follow the steps at this ObjectARX SDK for c# and change the following code with the below code.

            [CommandMethod("CD", CommandFlags.Session)]
            static public void CloseDocuments()
            {
                DocumentCollection docs = Application.DocumentManager;
                foreach (Document doc in docs)
                {
                    // First cancel any running command
                    if (doc.CommandInProgress != "" &&
                        doc.CommandInProgress != "CD")
                    {
                        AcadDocument oDoc =
                          (AcadDocument)doc.AcadDocument;
                        oDoc.SendCommand("\x03\x03");
                    }

                    if (doc.IsReadOnly)
                    {
                        doc.CloseAndDiscard();
                    }
                    else
                    {
                        // Activate the document, so we can check DBMOD
                        if (docs.MdiActiveDocument != doc)
                        {
                            docs.MdiActiveDocument = doc;
                        }
                        int isModified =
                          System.Convert.ToInt32(
                            Application.GetSystemVariable("DBMOD")
                          );

                        // No need to save if not modified
                        if (isModified == 0)
                        {
                            doc.CloseAndDiscard();
                        }
                        else
                        {
                            // This may create documents in strange places
                            doc.CloseAndSave(doc.Name);
                        }
                    }
                }

这篇关于如何使用C#在acad.exe中关闭文件以保持acad.exe运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 15:40