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

Is it possible to remove Embedded VBA Projects?

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
fieldguy
1397 Views, 4 Replies

Is it possible to remove Embedded VBA Projects?

I am working on batch processes and have some files with Embedded VBA Projects. This has spread to several files now because of our work flow - open an old file, save with a new name.  Attached is the dialog that is displayed when the files are opened in the editor.  I would like to "extract" the embedded macros in .NET.  They do not need to be there and they interupt the batch processes.  I know I could un-check the "Always ask before opening projects with macros" but I would rather extract / remove them.

 

 

 

 

4 REPLIES 4
Message 2 of 5
Jeff_M
in reply to: fieldguy

The embedded macros are held in the Drawing Dictionary "ACAD_VBA". Deleting this dictionary should solve the problem.

Jeff_M, also a frequent Swamper
EESignature
Message 3 of 5
Hallex
in reply to: fieldguy

Here is Lisp written by Jeff Mishler

See if that helps to see algorithms

(defun c:rvba (/ adoc cnt dicts)
  (vl-load-com)
  (setq adoc  (vla-get-activedocument
  (vlax-get-acad-object)
       )
 dicts (vla-get-dictionaries adoc)
  )
  (if (not (vl-catch-all-error-p
      (setq vba_dict (vl-catch-all-apply
         (function (lambda ()
       (vla-item dicts "ACAD_VBA")
     )
         )
       )
      )
    )
      )
    (progn
    (setq cnt 0)
    (vlax-for a vba_dict
      (vla-delete a)
      (setq cnt (1+ cnt))
    )
  )
  (alert (strcat "Unloaded " (itoa cnt) " VBA project(s)")))
  (gc)
  (princ)
)

(c:rvba)
(princ)

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 4 of 5
Jeff_M
in reply to: Jeff_M

This seems to work in the limited testing I've done:

    public class testing: IExtensionApplication
    {
        #region IExtensionApplication Members

        public void Initialize()
        {
            Application.DocumentManager.DocumentCreated += new DocumentCollectionEventHandler(DocumentManager_DocumentCreated);
        }

        void DocumentManager_DocumentCreated(object sender, DocumentCollectionEventArgs e)
        {
            using (Transaction tr = e.Document.Database.TransactionManager.StartTransaction())
            {
                DBDictionary nod = (DBDictionary)e.Document.Database.NamedObjectsDictionaryId.GetObject(OpenMode.ForRead);
                try
                {
                    DBDictionary dict = (DBDictionary)tr.GetObject(nod.GetAt("ACAD_VBA"), OpenMode.ForWrite);
                    dict.Erase();
                }
                catch { }
                tr.Commit();
            }
        }

        public void Terminate()
        {
            
        }

        #endregion
    }

 

Jeff_M, also a frequent Swamper
EESignature
Message 5 of 5
fieldguy
in reply to: Jeff_M

Thank you very much!  Attached is what I am using.

 

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