How to redefine a block by AutoLISP?

Discussion in 'AutoCAD' started by antonioy, Dec 15, 2004.

  1. antonioy

    antonioy Guest

    Does anybody know how to redefine a block by AutoLISP? So that I do not need to redefine them one by one by the insert command.
    Thanks
     
    antonioy, Dec 15, 2004
    #1
  2. Hi,

    Yes. Naturally - anybody who has read the help files.

    But, to get one of them to give you some useful guidelines you will have to
    ask a much more specific question and clarify exactly what it is you are
    currently doing manually and how you want to automate it.


    --

    Regards,


    Laurie Comerford
    www.cadapps.com.au
     
    Laurie Comerford, Dec 15, 2004
    #2
  3. antonioy

    OLD-CADaver Guest

    If you have several to do, it may be easier to start a new drawing from scratch, insert the new blocks using design center (or Explorer), then insert the drawing in which you wish the blocks redefined. The blocks in that dwg will assume the new definitions.

    After that, you can saveas, or you may wish to return to the old drawing delete and purge everything, then insert the new "scratch" drawing.
     
    OLD-CADaver, Dec 15, 2004
    #3
  4. antonioy

    Rick Keller Guest

    Autolisp.... Block name is scut90 in example being replaced with block
    scut90.
    (command "-insert" "SCUT90=//G12/Support/blocks/PLAN/SCUT90" pause pause
    pause "")

    Rick
     
    Rick Keller, Dec 15, 2004
    #4
  5. antonioy

    Tom Smith Guest

    (command "-insert" "SCUT90=//G12/Support/blocks/PLAN/SCUT90" pause pause
    pause "")

    If the block being replaced has the same name as the external file, and if
    that file is on the search path (so that a full path isn't needed to find
    it) the shorthand is simply (command "-insert" "SCUT90=" etc.).
     
    Tom Smith, Dec 15, 2004
    #5
  6. antonioy

    OLD-CADaver Guest

    Found this old one, it might be a place to start.

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;; Block redefiner assumes replacement block
    ;; is in path and is the same name as the block
    ;; Falcon Design Services - 29-Apr-1993
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (defun c:blkrein ()
    (setvar "cmdecho" 0)
    (command "undo" "begin")
    (setq blkname (getstring "\nEnter Block Name: ")) ;;; Get Block Name
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (if
    (/= (tblsearch "block" blkname) nil) ;;; Check If Block exists
    (progn ;;; start Progn 1
    (command ".-insert" (strcat blkname "=") "y" (command)
    "regen"
    )
    ) ;;; end Progn 1
    ) ;;;end if
    (princ (strcat "\n " (strcase blkname) " Redefined"))
    (command "undo" "end")
    (command)
    (princ)
    )
     
    OLD-CADaver, Dec 15, 2004
    #6
  7. Sorry people,

    I got an error message that it could not be posted, thought it was because
    it was a zip file or something so I sent it again as a lsp. And here they
    both are... Weird, sorry again.

    Must be some Microsoft thing or a blocker thing. Third Monday in a row...

    Arnold
     
    Arnold Williams, Dec 15, 2004
    #7
  8. antonioy

    Joshua Tapp Guest

    Good to see you posting your code, Arnold!

    I wish I could look at it for right now, but alas, the office I work in
    doesn't use AutoCAD, so I can't open it up in the Vlisp editor, or run it,
    so it'll have to wait till I get home.

    Hope everything's great for you.
     
    Joshua Tapp, Dec 16, 2004
    #8
  9. Josh,

    Yeah, I post very little actually. Don't have too much time here but when I
    think something will work I try. Then something weird like this happens, I
    show my ignorance or at least my lack of experience in posting here.

    Anyway, email me directly and let me know what is happening with you now.
    For me it is same business as usual. Learning the ins and outs of ADT 2005.

    Ok, back to business. I do hope there is some use for this, hope you find
    it useful too Joshua, I use it quite a bit, draw it once... change it once.
    Which means we have a large and varied block library.

    Still interested in knowing how to select or exit cleanly out of this a
    little bit more elegantly. Or is it OK as it is?

    Arnold Williams
     
    Arnold Williams, Dec 16, 2004
    #9
  10. Yes Robert,

    Thanks. What you are saying about a separate function is the way I been
    trying to develop a bunch of the things I have, and there are several. Then
    you can use it or a variant of it in other programs. I usually only have
    time to skim these NGs and miss too much good stuff or save it for later. I
    will search and get more into these ssget + L and S and others and try to
    incorporate them into what I have. Your approach is what I want. And I
    also usually have my programs just close out if there are no blocks in the
    file and a message saying so, no point going any farther. This one does not
    have that yet.

    I thought maybe antonioy could possibly use this, hopefully he or others
    can.

    Thanks again Robert,

    Arnold Williams
     
    Arnold Williams, Dec 16, 2004
    #10
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.