.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to disable the macro dialogbox by program?

4 REPLIES 4
Reply
Message 1 of 5
pro_sun
560 Views, 4 Replies

How to disable the macro dialogbox by program?

Hi, I have a program (C#.NET) that opens files in a batch by using the DocumentManager.Open() method.

The first problem is , if one of the files has a macro, the vba dialogbox appears which interrupts the progress. How can I disable the macro and block the dialogbox?

 

Another problem is, it will take a very long time to open a file by the CAD application after processing 10 or 20 files later. I have closed the file and disposed the document object by using the Dispose() method after opening. The application looks like crashing and the memory used by CAD is up to 200~300M which is only 50~80M when the first sevral files was processed.  

 

Anyone can help?

Thanks.

4 REPLIES 4
Message 2 of 5
Hallex
in reply to: pro_sun

I didn't see this problem on my end

Try for  comparing:

        #region "Batch example"
        [CommandMethod("ProcFiles", CommandFlags.Session)]
        public void Yeah()
        {
            Document doc = acadApp.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            FileInfo[] myFiles = GetAllFiles(@"C:\Test\BATM\BatchRemFields", true);
            BatchFolderFiles(myFiles);
        }
        public FileInfo[] GetAllFiles(string dirName, bool include)
        {

            DirectoryInfo dir = new DirectoryInfo(dirName);
            if (!dir.Exists)
            {
                return null;
            }
            else
            {
                FileInfo[] myFiles = dir.GetFiles("*.dwg", include ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
                return myFiles;
            }

        }

        public void BatchFolderFiles(FileInfo[] Files)
        {
            acadApp.MainWindow.Visible = true;

            //get current document
            Document cdoc = acadApp.DocumentManager.MdiActiveDocument;
            Document dwg = null;
                try
                {
                    // iterate through files
                    foreach (FileInfo file in Files)
                    {
                        
                        // Open file
                        dwg = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(file.FullName, false);

                        //Activate file to be proceed. It is very important
                        if (Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument != dwg)
                        {
                            Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument = dwg;
                        }
                        //-------------------------------------------------//
                        //        your code goes here
                        //e.g.:
           
                        using (DocumentLock dwglock = dwg.LockDocument())
                        {
                            using (Database db = dwg.Database)
                            {

                                using (Transaction tr = db.TransactionManager.StartTransaction())
                                {
                                    using (BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord)
                                    {
                                        using (Line ln = new Line(new Point3d(0, 0, 0), new Point3d(100, 100, 0)))
                                        {
                                            ln.ColorIndex = 1;
                                            btr.AppendEntity(ln);
                                            tr.AddNewlyCreatedDBObject(ln, true);
                                        }
                                        using (DBText txt = new DBText())
                                        {
                                            txt.SetDatabaseDefaults();
                                            txt.Position = new Point3d(100, 100, 0);
                                            txt.TextString = "Batch example";
                                            txt.Height = 12.5;
                                            txt.Rotation = Math.PI / 4;
                                            btr.AppendEntity(txt);
                                            tr.AddNewlyCreatedDBObject(txt, true);
                                        }

                                    }

                                    tr.Commit();
                                }

                            }

                        }
                        Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument = cdoc;

                        dwg.CloseAndSave(file.FullName);
                    }
                    
                }

                catch (System.Exception ex)
                {
                    acadApp.ShowAlertDialog(ex.Message + "\n" + ex.StackTrace);
                    //If eroror then close without saving changes
                    dwg.CloseAndDiscard();
                }
                finally
                {
                    Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Check result");
                }

        }

 

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 5
pro_sun
in reply to: Hallex

Thank you, Hallex. I will take a look

Message 4 of 5
fieldguy
in reply to: pro_sun
Message 5 of 5
pro_sun
in reply to: fieldguy

The first problem has been resolved. It is another function of my program that leads the issue, and I have disabled the module. The program works fine now.

 

Deleting the embedded VBA is just the method which I am using by. Before openning dwg-files, you have to read them to the database first, delete the embedded vba, then save them. Is there another method better to disable the dialogbox directly?

 

Please forgive my poor english. Thank you all.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost