How to close a file in Autocad using C# keeping acad.exe running?

后端 未结 6 1605
执念已碎
执念已碎 2020-12-19 19:32

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();
ProcessStart         


        
6条回答
  •  轮回少年
    2020-12-19 20:33

    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);
                            }
                        }
                    }
    

提交回复
热议问题