script for binding xrefs and purging?

Discussion in 'AutoCAD' started by thomasjfletcher, Nov 3, 2004.

  1. Hi! I have a huge bunch of dwg. sheet files that I need to bind the xrefs in and purge. I'm using Desktop 3.3. Could somebody please tell me how to do this using a script??
    thanks
    Tom NYC
     
    thomasjfletcher, Nov 3, 2004
    #1
  2. Just step through the commands as you would at the command prompt. Write it
    in a text file and save it with a .scr extension. Use script pro or some
    other program to run it on multiple drawings. Saving the file at the end of
    the script is also necessary. There are probably better ways to accomplish
    this than with a qsave command so others may have additional input.

    Your script should/could contain the following: (binds xrefs and purges 3
    times.) - you may also want to add an audit at the end as sometimes purging
    causes errors (at least that was my experience in R2000).


    -xref
    bind
    *
    -purge
    all
    *
    n
    -purge
    all
    *
    n
    -purge
    all
    *
    n
    qsave


    in and purge. I'm using Desktop 3.3. Could somebody please tell me how to do
    this using a script??
     
    Casey Roberts, Nov 3, 2004
    #2
  3. thanks very much-----
     
    thomasjfletcher, Nov 4, 2004
    #3
  4. If you like, I've amalgamated a lisp that binds all xrefs and adds the date
    to the filename, and saves as a new file in the original drawing directory.

    If you want it, let me know and I'll email it.
     
    Casey Roberts, Nov 5, 2004
    #4
  5. I'd love to try it-

    thanks
    Tom
     
    thomasjfletcher, Nov 8, 2004
    #5
  6. thomasjfletcher

    spencer1971 Guest

    Try this,
    It will save as "filename-bound" , delete unloaded xrefs and bind loaded ones.

    (defun saveasm ()
    (setq dpref (GETVAR "dwgprefix"))
    (setq dname (getvar "dwgname"))
    (setq dname1 (substr dname 1 (- (strlen dname) 4)))
    (setq dnamefin (strcat dpref dname1 "-bound"))
    (command "saveas" "" dnamefin)
    )

    (defun bindall ()
    (command "xref" "b" "*")
    (command "purge" "a" "*" "n")
    )


    (defun remove-unloaded-xrefs ()
    (vlax-for block (vla-get-blocks
    (vla-get-activedocument
    (vlax-get-acad-object)))
    (if (and (= :vlax-true (vla-get-isxref block))
    (= 0 (vla-get-count block))
    )
    (vla-detach block)
    )
    )
    )


    (defun c:SAVEBIND ()
    (princ "\nContinue? Yes / [No]")
    (setq yn "Yes")
    (initget "Yes No" )
    (setq yn (getpoint "\nThis will saveas and bind all Xrefs *REMEMBER TO SAVE FIRST*"))
    (if (= yn "Yes")
    (PROGN
    (saveasm)
    (remove-unloaded-xrefs)
    (bindall)
    )
    (princ)
    )
    (PRINC)
    )


    Spencer
     
    spencer1971, Nov 8, 2004
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.