.NET

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

How to disable the macro dialogbox by program?

264 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 (249 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 (241 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: 367
Registered: ‎03-31-2005
Message 4 of 5 (216 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 (207 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.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community