Results 1 to 8 of 8

Thread: Programmatically remove embedded VBA

  1. #1
    Member
    Join Date
    2009-06
    Posts
    2
    Login to Give a bone
    0

    Default Programmatically remove embedded VBA

    Is there a way using VBA or LISP to programmatically remove an embedded VBA project from a drawing? I found the code below. From my admittedly limited knowledge of LISP, it seems like it should do it. If I embed a projected and run it, it will detect it and ask if I want to remove it, but if I go to Tools->Macro->VBA Manager, it's still embedded. If I run it again, it won't detect it anymore. I'm using Autocad 2008.


    Code:
    (defun c:rem_vba_proj (/ mac-attach )
    (setq mac-attach (dictsearch (namedobjdict) "ACAD_VBA"))
    (if mac-attach
    (progn
    (getstring "\nFound embedded macro. Enter to delete, ESC to cancel...")
    (foreach name (massoc 350 mac-attach)
    (entdel name)
    )
    (dictremove (namedobjdict) "ACAD_VBA")
    (command "qsave")
    )
    )
    )
    
    (defun massoc (key alist / x nlist)
    (foreach x alist
    (if
    (eq key (car x))
    (setq nlist (cons (cdr x) nlist))
    ) ;end if
    ) ;end foreach
    (reverse nlist)
    ) ;end defun
    Last edited by RobertB; 2009-06-11 at 06:15 PM. Reason: Added [code] tags

  2. #2
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default Re: Programmatically remove embedded VBA

    Did you try closing and reopening the drawing?
    R. Robert Bell
    Design Technology Manager
    Stantec
    Opinions expressed are mine alone and do not reflect the views of Stantec.

  3. #3
    Member
    Join Date
    2009-06
    Posts
    2
    Login to Give a bone
    0

    Default Re: Programmatically remove embedded VBA

    No, I hadn't. That does it, but is there a way to do it without having to close the drawing?

  4. #4
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default Re: Programmatically remove embedded VBA

    I don't think so, since the embedded code has already been loaded when the drawing is opened.
    R. Robert Bell
    Design Technology Manager
    Stantec
    Opinions expressed are mine alone and do not reflect the views of Stantec.

  5. #5
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Programmatically remove embedded VBA

    Robert,

    Do you think it could be done on the ' beginDwgOpen ' event? Or would it be too late to try and open the drawing with ObjectDBX, and perform the request?

  6. #6
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default Re: Programmatically remove embedded VBA

    Quote Originally Posted by T.Willey View Post
    Do you think it could be done on the ' beginDwgOpen ' event? Or would it be too late to try and open the drawing with ObjectDBX, and perform the request?
    My gut instinct is that it would be too late, but testing would confirm.
    R. Robert Bell
    Design Technology Manager
    Stantec
    Opinions expressed are mine alone and do not reflect the views of Stantec.

  7. #7
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Programmatically remove embedded VBA

    Quote Originally Posted by RobertB View Post
    My gut instinct is that it would be too late, but testing would confirm.
    That is what I was thinking also. Maybe if I have some time today I will test and post back a confirmation either way. Thanks.

  8. #8
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Programmatically remove embedded VBA

    I couldn't even get the reactor to fire. It looks right to me.

    Code:
    (or
        GlbReactorBeginOpen
        (setq GlbReactorBeginOpen (vlr-editor-reactor nil '((:vlr-beginDwgOpen . TestOpening))))
    )
    (defun TestOpening ( react strList )
        
        (print strList)
        (setq GlbVarDwgOpening (car strList))
        (vl-propagate GlbVarDwgOpening)
        (princ)
    )
    Command: _open
    Command: !glbvardwgopening
    nil

Similar Threads

  1. Change Cut Plane Programmatically?
    By treaves04413213 in forum AutoLISP
    Replies: 0
    Last Post: 2013-08-29, 05:58 PM
  2. How to Delete Surface Points Programmatically?
    By a.hajihasani865722 in forum Dot Net API
    Replies: 0
    Last Post: 2012-08-22, 10:09 AM
  3. How to programmatically call refedit.
    By Paul Bryan Porter in forum ARX
    Replies: 4
    Last Post: 2012-01-17, 04:10 PM
  4. 2011: Export to ODBC database programmatically
    By morten.gorm.madsen663302 in forum Revit - API
    Replies: 0
    Last Post: 2011-08-19, 01:03 PM
  5. Setting Parameters Programmatically
    By awhite343 in forum Revit - API
    Replies: 5
    Last Post: 2006-07-18, 12:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •