Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help adapting a lisp? Multiple selection.

8 REPLIES 8
Reply
Message 1 of 9
Anonymous
600 Views, 8 Replies

Help adapting a lisp? Multiple selection.

Hi there,

 

I've found a .lsp that does nearly what I require. I don't suppose anyone could give me a hand adapting it?

The lisp that I've got allows you to identify a block, and have another block replace it.

Is it possible to adapt this lisp to allow you to select multiple target blocks to be overwritten?

 

(defun c:rblk (/ pre nb ss i en ed)

  (while (or (not pre)
             (not (snvalid pre)))
         (setq pre (getstring "\nExisting BLOCKs Name Prefix:   ")))

  (while (not nb)
         (setq nb (getstring "\nNew BLOCK Name:   "))
         (cond ((not (snvalid nb))
                (setq nb nil))
               ((tblsearch "BLOCK" nb))
               ((findfile (strcat nb ".DWG"))
                (command "_.INSERT" nb)
                (command))
               (T (setq nb nil))))

  (and (setq ss (ssget "X" (list (cons 0 "INSERT")
                                 (cons 2 (strcat pre "*")))))
       (setq i (sslength ss))
       (while (not (minusp (setq i (1- i))))
              (setq en (ssname ss i)
                    ed (entget en))
              (entmod (subst (cons 2 nb) (assoc 2 ed) ed))
              (entupd en)))
  (prin1))

 In this particular instance, I'm trying to have multiple different door symbols in a 2D plan overwritten with a uniform marker. If that helps at all.

 

Many thanks in advance! Smiley Very Happy

8 REPLIES 8
Message 2 of 9
maxim_k
in reply to: Anonymous

Hi,

This Lisp replaces all current insertions of block in drawing with new, specified by user. Do you want to be able to "restrict" it to replace only selected blocks?

Maxim

Do you find the posts helpful? "LIKE" these posts!
Have your question been answered successfully? Click 'ACCEPT SOLUTION' button.


Maxim Kanaev
Architect
MARSS

MacACAD | Linkedin

Etiquette and Ground Rules of Autodesk Community
Message 3 of 9
Anonymous
in reply to: maxim_k

Hi there, thanks for the reply.

 

What I'd ideally like to do, is replace many different blocks over numerous insertions.

 

For instance,

I'd like to replace all instances of block "Door1.dwg.", "Door2.dwg" and "Door3.dwg" with instances of "Door4.dwg"

 

Turning a variety of shapes into one shape. Does that make sense?

If you'll excuse this childlike example...

 

blocks.png

 

Assuming each different shape is a different block loaded into my current drawing.

Message 4 of 9
maxim_k
in reply to: Anonymous

If all block names that you want to replace in a drawing start with the same prefix, like "Door" in your example, it seems you can use Lisp file you have to accomplish the task. You just have to type "Door" (without quotes) at the command prompt, when routine asks which block to replace. Then type the name of new block.
Have you tried this?

Maxim

Do you find the posts helpful? "LIKE" these posts!
Have your question been answered successfully? Click 'ACCEPT SOLUTION' button.


Maxim Kanaev
Architect
MARSS

MacACAD | Linkedin

Etiquette and Ground Rules of Autodesk Community
Message 5 of 9
Anonymous
in reply to: maxim_k

unfortunately, owing to what I assume is purchased library blocks by the op that drew the file, all of these blocks have seemingly random strings for names.

But for future reference, could I type something like: *door*

to include all blocks that have door contained in the block name?

 

Finally, I can't seem to enter any block names that contain a space. Foolishly, perhaps, I've assigned one of my blocks a space in it's name...

 

Ideally what I'd like is something akin to REPLACEBLOCK, where I could select as many blocks to be replaced and give them all the same block to be inserted.

 

 

Message 6 of 9
3wood
in reply to: Anonymous

You can also try attached MBLOCKREPLACE.vlx.

Message 7 of 9
maxim_k
in reply to: Anonymous


@Anonymous wrote:

...
But for future reference, could I type something like: *door*

to include all blocks that have door contained in the block name?

...

 

 


Yes, you can but only as prefix - that means that block names could be "door123", but not "123door"

 


@Anonymous wrote:
...

 

Finally, I can't seem to enter any block names that contain a space. Foolishly, perhaps, I've assigned one of my blocks a space in it's name...

 

....

 

 


You need to add T to second GETSTRING, then you will be able to include spaces in new block name, you just have to end name input with Enter key (not Spacebar):

(defun c:rblk (/ pre nb ss i en ed)

  (while (or (not pre)
             (not (snvalid pre)))
         (setq pre (getstring "\nExisting BLOCKs Name Prefix:   ")))

  (while (not nb)
         (setq nb (getstring T "\nNew BLOCK Name:   "))
         (cond ((not (snvalid nb))
                (setq nb nil))
               ((tblsearch "BLOCK" nb))
               ((findfile (strcat nb ".DWG"))
                (command "_.INSERT" nb)
                (command))
               (T (setq nb nil))))

  (and (setq ss (ssget "X" (list (cons 0 "INSERT")
                                 (cons 2 (strcat pre "*")))))
       (setq i (sslength ss))
       (while (not (minusp (setq i (1- i))))
              (setq en (ssname ss i)
                    ed (entget en))
              (entmod (subst (cons 2 nb) (assoc 2 ed) ed))
              (entupd en)))
  (prin1))

 

 

And, of course it is possible to adopt existing Lisp to allow user to select which blocks to replace, but this is another, little bit more complex task.

 

 

Maxim


Do you find the posts helpful? "LIKE" these posts!
Have your question been answered successfully? Click 'ACCEPT SOLUTION' button.


Maxim Kanaev
Architect
MARSS

MacACAD | Linkedin

Etiquette and Ground Rules of Autodesk Community
Message 8 of 9
Anonymous
in reply to: 3wood

I was bombarded with all sorts of popup dialogues with this one.

Trial didn't seem to let me do anything.

Message 9 of 9
Anonymous
in reply to: 3wood

Also, upon reading around. My lisp performs this function already.

 

Ideally what I need is the ability to target multiple blocks, each with different names.

for example, I have a dwg with 4 door blocks in it. These are called:

  1. 030_026D
  2. Door Toilet
  3. 100x1800
  4. Door 2

The prefixing method here just won't work, because as you can see, they're all vastly different.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost