.NET

Reply
Valued Mentor
fieldguy
Posts: 367
Registered: ‎03-31-2005
Message 1 of 5 (457 Views)
Accepted Solution

Is it possible to remove Embedded VBA Projects?

457 Views, 4 Replies
06-29-2011 12:19 PM

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.

 

 

 

 

*Expert Elite*
Jeff_M
Posts: 4,202
Registered: ‎07-22-2003
Message 2 of 5 (450 Views)

Re: Is it possible to remove Embedded VBA Projects?

06-29-2011 12:32 PM 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
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 3 of 5 (445 Views)

Re: Is it possible to remove Embedded VBA Projects?

06-29-2011 12:45 PM 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
*Expert Elite*
Jeff_M
Posts: 4,202
Registered: ‎07-22-2003
Message 4 of 5 (434 Views)

Re: Is it possible to remove Embedded VBA Projects?

06-29-2011 01:59 PM 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
Valued Mentor
fieldguy
Posts: 367
Registered: ‎03-31-2005
Message 5 of 5 (429 Views)

Re: Is it possible to remove Embedded VBA Projects?

06-29-2011 02:16 PM in reply to: Jeff_M

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

 

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