.NET

.NET

Reply
Member
pro_sun
Posts: 3
Registered: ‎08-21-2010
Message 1 of 5 (286 Views)

How to disable the macro dialogbox by program?

286 Views, 4 Replies
12-26-2011 07:35 AM

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.

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 5 (271 Views)

Re: How to disable the macro dialogbox by program?

12-26-2011 02:34 PM 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
Member
pro_sun
Posts: 3
Registered: ‎08-21-2010
Message 3 of 5 (263 Views)

Re: How to disable the macro dialogbox by program?

12-26-2011 05:41 PM in reply to: Hallex

Thank you, Hallex. I will take a look

Valued Mentor
fieldguy
Posts: 382
Registered: ‎03-31-2005
Message 4 of 5 (238 Views)

Re: How to disable the macro dialogbox by program?

12-28-2011 09:11 AM in reply to: pro_sun
Member
pro_sun
Posts: 3
Registered: ‎08-21-2010
Message 5 of 5 (229 Views)

Re: How to disable the macro dialogbox by program?

12-28-2011 05:28 PM 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.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.