Results 1 to 6 of 6

Thread: Block replacement lisp needed

  1. #1
    I could stop if I wanted to cadd4la's Avatar
    Join Date
    2001-12
    Location
    Newport Beach, CA
    Posts
    399
    Login to Give a bone
    0

    Question Block replacement lisp needed

    Hi everyone,

    Looking to see if someone has or can write a lisp for me that will replace existing blocks in a drawing with another one. I'm not looking for it to do it globally (like the one in the express tools) or individual, I need to select the new block, then select the old one, and then do a window around the area and only the selected existing block updates.

    Thanks,

    Cadd4la

  2. #2
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Block replacement lisp needed

    Hi,

    You can try my program from THIS LINK

  3. #3
    I could stop if I wanted to cadd4la's Avatar
    Join Date
    2001-12
    Location
    Newport Beach, CA
    Posts
    399
    Login to Give a bone
    0

    Default Re: Block replacement lisp needed

    Tharwat,

    Thanks, for the program. However, I do need it to handle blocks that are dynamic and have attributes.

    Regards,

    Cadd4la

  4. #4
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Block replacement lisp needed

    Quote Originally Posted by cadd4la View Post
    Tharwat,

    Thanks, for the program. However, I do need it to handle blocks that are dynamic and have attributes.

    Regards,

    Cadd4la
    You are welcome.

    Unfortunately, my program is for regular blocks only and what you are asking for is really in need of a custom program.

  5. #5
    Woo! Hoo! my 1st post
    Join Date
    2017-06
    Posts
    1
    Login to Give a bone
    0

    Default Re: Block replacement lisp needed


  6. #6
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Block replacement lisp needed

    This has always served me well:

    Code:
    (vl-load-com)
    
    (defun c:RB () (c:ReplaceBlock))
    (defun c:ReplaceBlock (/ *error* blockName ok acDoc space ss oBlock)
    
      (defun *error* (msg)
        (if ss (vla-delete ss))
        (if acDoc
          (vla-endundomark acDoc)
        )
        (cond ((not msg))                                                   ; Normal exit
              ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
              ((princ (strcat "\n** Error: " msg " ** ")))                  ; Fatal error, display it
        )
        (princ)
      )
    
      (if
        (and
          (ssget "_:L" '((0 . "INSERT")))
          (or (/= ""
                  (setq blockName
                         (strcase
                           (getstring
                             T
                             (strcat "\nEnter replacement block name"
                                     (if *ReplaceBlockName*
                                       (strcat " <" *ReplaceBlockName* ">: ")
                                       ": "
                                     )
                             )
                           )
                         )
                  )
              )
              (setq blockName *ReplaceBlockName*)
          )
          (setq *ReplaceBlockName* blockName)
          (or (and (tblsearch "block" blockName) (setq ok T))
              (setq blockName (findfile (strcat blockName ".dwg")))
          )
        )
         (progn
           (vla-startundomark
             (setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
           )
           (setq space (vlax-get acDoc
                                 (if (= 1 (getvar 'cvport))
                                   'paperspace
                                   'modelspace
                                 )
                       )
           )
           (vlax-for x (setq ss (vla-get-activeselectionset acDoc))
             (vla-put-layer
               (setq oBlock (vla-insertblock
                              space
                              (vla-get-insertionpoint x)
                              blockName
                              (vla-get-xscalefactor x)
                              (vla-get-yscalefactor x)
                              (vla-get-zscalefactor x)
                              (vla-get-rotation x)
                            )
               )
               (vla-get-layer x)
             )
             (vla-put-color oBlock (vla-get-color x))
             (vla-delete x)
             (if (not ok)
               (progn
                 (setq blockName (vl-filename-base blockName))
                 (setq ok T)
               )
             )
           )
         )
      )
      (*error* nil)
    )

    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

Similar Threads

  1. Block replacement
    By .chad in forum ACA General
    Replies: 3
    Last Post: 2008-12-02, 08:29 PM
  2. Lisp needed to change block units.
    By cadd4la in forum AutoLISP
    Replies: 5
    Last Post: 2006-04-13, 12:58 AM
  3. Block Replacement
    By jmctamney in forum AutoLISP
    Replies: 7
    Last Post: 2005-10-25, 02:01 PM
  4. Block replacement
    By csiress in forum AutoLISP
    Replies: 3
    Last Post: 2005-07-07, 04:55 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
  •