Results 1 to 4 of 4

Thread: Change all similar blocks to same

  1. #1
    Wish List Administration
    Join Date
    2011-08
    Posts
    4,581

    Default Re: Change all similar blocks to same

    Summary: Change all blocks that are similar/identical but have different block definitions to the same block

    Description: If there are multiple identical blocks in an AutoCAD file that have different block definitions/block names, the command should be able to change them all to have the same block definition/block name. That way if you use the SELECTSIMILAR command, all of these re-grouped blocks can be selected at the same time.

    Product and Feature: AutoCAD - Blocks

    Submitted By: aleung on 11/27/2023


  2. #2
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,371

    Default Re: Change all similar blocks to same

    The problem with that is how would a program define "similar". Only you you know what you want to be similar. You would have to redefine a block. I've attached a lisp with several commands for replacing block insertions. SSNREPLACE will allow you to select multiple insertions and replace them with another block name.
    Attached Files Attached Files
    C:> ED WORKING....

  3. #3
    Certified AUGI Addict cadtag's Avatar
    Join Date
    2000-12
    Location
    Cairo - no, not Illinois
    Posts
    5,068

    Default Re: Change all similar blocks to same

    Use the Block replace tool from Express, and get it done in seconds

  4. #4
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,713

    Default Re: Change all similar blocks to same

    The only issue I have with the BLOCKREPLACE Express Tool is that it does all Blocks, where I more often need to do this on a selection:

    Quote Originally Posted by BlackBox View Post
    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

Posting Permissions

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