Jump to content

Recommended Posts

Posted

DOES ANYONE HAVE A QUICK AND EASY WAY TO REPLACE A SELECTED BLOCK. ALSO IS THERE A WAY TO REPLACE MULTIPLE SLECTED BLOCKS AND REPLACE WITH A DIFFERENT BLOCK TYPICAL FOR ALL THE BLOCKS THAT ARE SELECTED? I HAVE A BIG A$$ PROJECT DUE FRIDAY AND NEED TO SWAP OUT ALOT OF BLOCKS NOW...:cry:

  • Replies 38
  • Created
  • Last Reply

Top Posters In This Topic

  • alanjt

    9

  • Efeezy

    3

  • lpseifert

    2

  • justindm

    2

Posted

Ouch... not so loud

Have you tried the Express Tools' Blockreplace?

Posted

LOL sorry about that. Yes, I have express tools. The Blockreplace command replaces all the blocks i just want to replace the block that I have manually selected. I pulled an old stript and trying to alter it but not sure if I can pull it off though.

Posted (edited)

nope couldn't get the script to work I am a not good at writing or modifying lisp my bock i need to replace is smoke 1 with smoke rb

 

------------------------------------------

 

[b]([/b]defun c:rblk [b][color=fuchsia]([/color][/b]/ pre nb ss i en ed[b][color=fuchsia])[/color][/b][b][color=fuchsia]([/color][/b]while [b][color=navy]([/color][/b]or [b][color=maroon]([/color][/b]not pre[b][color=maroon])[/color][/b][b][color=maroon]([/color][/b]not [b][color=green]([/color][/b]snvalid pre[b][color=green])[/color][color=maroon])[/color][color=navy])[/color][/b][b][color=navy]([/color][/b]setq pre [b][color=maroon]([/color][/b]getstring [color=darkslategray]"\nExisting BLOCKs Name Prefix:   "[/color][b][color=maroon])[/color][color=navy])[/color][color=fuchsia])[/color][/b][b][color=fuchsia]([/color][/b]while [b][color=navy]([/color][/b]not nb[b][color=navy])[/color][/b][b][color=navy]([/color][/b]setq nb [b][color=maroon]([/color][/b]getstring [color=darkslategray]"\nNew BLOCK Name:   "[/color][b][color=maroon])[/color][color=navy])[/color][/b][b][color=navy]([/color][/b]cond [b][color=maroon]([/color][color=green]([/color][/b]not [b][color=blue]([/color][/b]snvalid nb[b][color=blue])[/color][color=green])[/color][/b][b][color=green]([/color][/b]setq nb nil[b][color=green])[/color][color=maroon])[/color][/b][b][color=maroon]([/color][color=green]([/color][/b]tblsearch [color=darkslategray]"BLOCK"[/color] nb[b][color=green])[/color][color=maroon])[/color][/b][b][color=maroon]([/color][color=green]([/color][/b]findfile [b][color=blue]([/color][/b]strcat nb [color=darkslategray]".DWG"[/color][b][color=blue])[/color][color=green])[/color][/b][b][color=green]([/color][/b]command [color=darkslategray]"_.INSERT"[/color] nb[b][color=green])[/color][/b][b][color=green]([/color][/b]command[b][color=green])[/color][color=maroon])[/color][/b][b][color=maroon]([/color][/b]T [b][color=green]([/color][/b]setq nb nil[b][color=green])[/color][color=maroon])[/color][color=navy])[/color][color=fuchsia])[/color][/b][b][color=fuchsia]([/color][/b]and [b][color=navy]([/color][/b]setq ss [b][color=maroon]([/color][/b]ssget [color=darkslategray]"X"[/color] [b][color=green]([/color][/b]list [b][color=blue]([/color][/b]cons 0 [color=darkslategray]"INSERT"[/color][b][color=blue])[/color][/b][b][color=blue]([/color][/b]cons 2 [b][color=red]([/color][/b]strcat pre [color=darkslategray]"*"[/color][b][color=red])[/color][color=blue])[/color][color=green])[/color][color=maroon])[/color][color=navy])[/color][/b][b][color=navy]([/color][/b]setq i [b][color=maroon]([/color][/b]sslength ss[b][color=maroon])[/color][color=navy])[/color][/b][b][color=navy]([/color][/b]while [b][color=maroon]([/color][/b]not [b][color=green]([/color][/b]minusp [b][color=blue]([/color][/b]setq i [b][color=red]([/color][/b]1- i[b][color=red])[/color][color=blue])[/color][color=green])[/color][color=maroon])[/color][/b][b][color=maroon]([/color][/b]setq en [b][color=green]([/color][/b]ssname ss i[b][color=green])[/color][/b]                    ed [b][color=green]([/color][/b]entget en[b][color=green])[/color][color=maroon])[/color][/b][b][color=maroon]([/color][/b]entmod [b][color=green]([/color][/b]subst [b][color=blue]([/color][/b]cons 2 nb[b][color=blue])[/color][/b] [b][color=blue]([/color][/b]assoc 2 ed[b][color=blue])[/color][/b] ed[b][color=green])[/color][color=maroon])[/color][/b][b][color=maroon]([/color][/b]entupd en[b][color=maroon])[/color][color=navy])[/color][color=fuchsia])[/color][/b][b][color=fuchsia]([/color][/b]prin1[b][color=fuchsia])[/color][color=black])[/color][/b]

Edited by SLW210
Posted

I've had this in my archives for a long time, hope it works for you

rblock.zip

Posted
:D:DGood one.........its working fine...Mr.Efeezy, Are u got solution? if yes complete the target before due..................Congrats...:D:D
Posted (edited)
DOES ANYONE HAVE A QUICK AND EASY WAY TO REPLACE A SELECTED BLOCK. ALSO IS THERE A WAY TO REPLACE MULTIPLE SLECTED BLOCKS AND REPLACE WITH A DIFFERENT BLOCK TYPICAL FOR ALL THE BLOCKS THAT ARE SELECTED? I HAVE A BIG A$$ PROJECT DUE FRIDAY AND NEED TO SWAP OUT ALOT OF BLOCKS NOW...:cry:

 

try Bre.lsp from Alan Thompson... It's works quite well..

 

See updated CODE

Edited by SLW210
Removed Lisp File
Posted
try Bre.lsp from Alan Thompson... It's works quite well..

I forgot all about that one. Haven't used it since the project I wrote it for.

 

Original link

  • 4 months later...
Posted (edited)
bre is good! :D

 

Glad you like it. I wish I could remove that old version gilsoto posted, but here's an updated version:

 

(defun c:BRE (/ *error* blk f ss temp)
 ;; Replace multiple instances of selected blocks (can be different) with selected block
 ;; Size and Rotation will be taken from original block and original will be deleted
 ;; Required subroutines: AT:GetSel
 ;; Alan J. Thompson, 02.09.10

 (vl-load-com)

 (defun *error* (msg)
   (and f *AcadDoc* (vla-endundomark *AcadDoc*))
   (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))
     (princ (strcat "\nError: " msg))
   )
 )

 (if
   (and
     (AT:GetSel
       entsel
       "\nSelect replacement block: "
       (lambda (x / e)
         (if
           (and
             (eq "INSERT" (cdr (assoc 0 (setq e (entget (car x))))))
             (/= 4 (logand (cdr (assoc 70 (tblsearch "BLOCK" (cdr (assoc 2 e))))) 4))
             (/= 4 (logand (cdr (assoc 70 (entget (tblobjname "LAYER" (cdr (assoc 8 e)))))) 4))
           )
            (setq blk (vlax-ename->vla-object (car x)))
         )
       )
     )
     (princ "\nSelect blocks to be repalced: ")
     (setq ss (ssget "_:L" '((0 . "INSERT"))))
   )
    (progn
      (setq f (not (vla-startundomark
                     (cond (*AcadDoc*)
                           ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
                     )
                   )
              )
      )
      (vlax-for x (setq ss (vla-get-activeselectionset *AcadDoc*))
        (setq temp (vla-copy blk))
        (mapcar (function (lambda (p)
                            (vl-catch-all-apply
                              (function vlax-put-property)
                              (list temp p (vlax-get-property x p))
                            )
                          )
                )
                '(Insertionpoint Rotation XEffectiveScaleFactor YEffectiveScaleFactor
                  ZEffectiveScaleFactor
                 )
        )
        (vla-delete x)
      )
      (vla-delete ss)
      (*error* nil)
    )
 )
 (princ)
)

(defun AT:GetSel (meth msg fnc / ent good)
 ;; meth - selection method (entsel, nentsel, nentselp)
 ;; msg - message to display (nil for default)
 ;; fnc - optional function to apply to selected object
 ;; Ex: (AT:GetSel entsel "\nSelect arc: " (lambda (x) (eq (cdr (assoc 0 (entget (car x)))) "ARC")))
 ;; Alan J. Thompson, 05.25.10
 (setvar 'errno 0)
 (while (not good)
   (setq ent (meth (cond (msg)
                         ("\nSelect object: ")
                   )
             )
   )
   (cond
     ((vl-consp ent)
      (setq good (cond ((or (not fnc) (fnc ent)) ent)
                       ((prompt "\nInvalid object!"))
                 )
      )
     )
     ((eq (type ent) 'STR) (setq good ent))
     ((setq good (eq 52 (getvar 'errno))) nil)
     ((eq 7 (getvar 'errno)) (setq good (prompt "\nMissed, try again.")))
   )
 )
)

Edited by alanjt
  • 1 month later...
Posted

I'm trying to run the above but get an error: "Error: no function definition: VLAX-ENAME->VLA-OBJECT"

 

Some of the blocks I'm selecting have spaces, dashes and underscores...could that be a problem?

Posted

Perfecto!!!!!!!! :shock:

 

You're so awesome. This is awesome. You're a life saver.

Can't thank you enough. :D

Posted
Perfecto!!!!!!!! :shock:

 

You're so awesome. This is awesome. You're a life saver.

Can't thank you enough. :D

Enjoy.

 

 

 

..............

  • 1 year later...
Posted
Thanks! Bre worked great

You're welcome. Be sure to use the one I posted, not the very old version gilsoto posted.

  • 7 months later...
Posted
Glad you like it. I wish I could remove that old version gilsoto posted, but here's an updated version:

 

(defun c:BRE (/ *error* blk f ss temp)
 ;; Replace multiple instances of selected blocks (can be different) with selected block
 ;; Size and Rotation will be taken from original block and original will be deleted
 ;; Required subroutines: AT:GetSel
 ;; Alan J. Thompson, 02.09.10

 (vl-load-com)

 (defun *error* (msg)
   (and f *AcadDoc* (vla-endundomark *AcadDoc*))
   (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))
     (princ (strcat "\nError: " msg))
   )
 )

 (if
   (and
     (AT:GetSel
       entsel
       "\nSelect replacement block: "
       (lambda (x / e)
         (if
           (and
             (eq "INSERT" (cdr (assoc 0 (setq e (entget (car x))))))
             (/= 4 (logand (cdr (assoc 70 (tblsearch "BLOCK" (cdr (assoc 2 e))))) 4))
             (/= 4 (logand (cdr (assoc 70 (entget (tblobjname "LAYER" (cdr (assoc 8 e)))))) 4))
           )
            (setq blk (vlax-ename->vla-object (car x)))
         )
       )
     )
     (princ "\nSelect blocks to be repalced: ")
     (setq ss (ssget "_:L" '((0 . "INSERT"))))
   )
    (progn
      (setq f (not (vla-startundomark
                     (cond (*AcadDoc*)
                           ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
                     )
                   )
              )
      )
      (vlax-for x (setq ss (vla-get-activeselectionset *AcadDoc*))
        (setq temp (vla-copy blk))
        (mapcar (function (lambda (p)
                            (vl-catch-all-apply
                              (function vlax-put-property)
                              (list temp p (vlax-get-property x p))
                            )
                          )
                )
                '(Insertionpoint Rotation XEffectiveScaleFactor YEffectiveScaleFactor
                  ZEffectiveScaleFactor
                 )
        )
        (vla-delete x)
      )
      (vla-delete ss)
      (*error* nil)
    )
 )
 (princ)
)

(defun AT:GetSel (meth msg fnc / ent good)
 ;; meth - selection method (entsel, nentsel, nentselp)
 ;; msg - message to display (nil for default)
 ;; fnc - optional function to apply to selected object
 ;; Ex: (AT:GetSel entsel "\nSelect arc: " (lambda (x) (eq (cdr (assoc 0 (entget (car x)))) "ARC")))
 ;; Alan J. Thompson, 05.25.10
 (setvar 'errno 0)
 (while (not good)
   (setq ent (meth (cond (msg)
                         ("\nSelect object: ")
                   )
             )
   )
   (cond
     ((vl-consp ent)
      (setq good (cond ((or (not fnc) (fnc ent)) ent)
                       ((prompt "\nInvalid object!"))
                 )
      )
     )
     ((eq (type ent) 'STR) (setq good ent))
     ((setq good (eq 52 (getvar 'errno))) nil)
     ((eq 7 (getvar 'errno)) (setq good (prompt "\nMissed, try again.")))
   )
 )
)

Hi Alan J,

I've been searching for a block replace Lisp for three days but couldn't find any good one. I found this lisp it is working nice, I wanted to ask is it possible to make this lisp a batch block replacement so that you don't need to open every drawing to change blocks. I have to replace old blocks from new blocks in more than 300 drawings.

If it is possible plz tell.

Thanks for your previous (BRE) Lisp too.

  • 10 months later...
Posted

Do you have a similar routine that wors with attributes? I often have to change (blocks with attributes) parts of my drawing from proposed to existing. The blocks are the same except for color and font style. Thanks

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...