Jump to content

Blocks Replace


PeterPan9720

Recommended Posts

Hi to everybody,

Is there a way to modify the tools blocks replace available in Autocad Express Tools ?.

 

I try to explain better :

- The express tools blocks replaces "all" blocks inside the dwg comparing the name.

- I would like to change only selected ones ? Is there a way to have access to express tools blocks replace "macro" and starting from that create another only for replace the selected one ?.

 

Somebody think that could be easier create complete new tools for my issue ?

 

Many thanks for all your support

Link to comment
Share on other sites

Like match properties but matching blocks?

 

I did not understood well your answer, but the original function matches the old blocks attributes with the new also.

My mod would be works in the same way.

 

Thanks

Link to comment
Share on other sites

If I understand you correctly you have, for example, 12 instance of block "ABC" in your drawing. Of these 12 you may only want to change 6 of them not all of them. Is that right?

Link to comment
Share on other sites

????

 

 
(defun c:mb (/ *error* ent ss ssent id)
 (defun *error* (msg)
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
        (princ (strcat "\n** Error: " msg " **"))
   )
   (setvar 'nomutt 0)
   (princ)
 )
 (while
   (not
     (and
(setq ent (car (entsel "\nSelect source block: ")))
(eq "INSERT" (cdr (assoc 0 (setq ent (entget ent)))))
     )
   )
   (prompt "\nPlease select a block!!")
 )
 (redraw (cdr (car ent)) 3)
 (prompt "\nSelect blocks to replace: ")
 (setvar 'nomutt 1)
 (repeat (setq id (sslength (setq ss (ssget '((0 . "insert"))))))
   (setq ssent (entget (ssname ss (setq id (1- id)))))
   (entmod (subst (assoc 2 ent)(assoc 2 ssent) ssent))
 )
 (setvar 'nomutt 0)
 (redraw (cdr (car ent)) 4)
 (princ)
)

Link to comment
Share on other sites

If I understand you correctly you have, for example, 12 instance of block "ABC" in your drawing. Of these 12 you may only want to change 6 of them not all of them. Is that right?

 

Yes, correct.

Selecting that on screen, even if are in different layers.

 

Thanks

Link to comment
Share on other sites

????

 

 
(defun c:mb (/ *error* ent ss ssent id)
 (defun *error* (msg)
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
        (princ (strcat "\n** Error: " msg " **"))
   )
   (setvar 'nomutt 0)
   (princ)
 )
 (while
   (not
     (and
(setq ent (car (entsel "\nSelect source block: ")))
(eq "INSERT" (cdr (assoc 0 (setq ent (entget ent)))))
     )
   )
   (prompt "\nPlease select a block!!")
 )
 (redraw (cdr (car ent)) 3)
 (prompt "\nSelect blocks to replace: ")
 (setvar 'nomutt 1)
 (repeat (setq id (sslength (setq ss (ssget '((0 . "insert"))))))
   (setq ssent (entget (ssname ss (setq id (1- id)))))
   (entmod (subst (assoc 2 ent)(assoc 2 ssent) ssent))
 )
 (setvar 'nomutt 0)
 (redraw (cdr (car ent)) 4)
 (princ)
)

 

Seems to work fine, I'll try to select more than one

 

Many thanks

Link to comment
Share on other sites

????

 

 
(defun c:mb (/ *error* ent ss ssent id)

   (entmod (subst (assoc 2 ([b][color="red"]entget[/color][/b] ent))(assoc 2 ssent) ssent))
 

 

You have forgotten to add entget function dear dan

 

Best regards

Link to comment
Share on other sites

WooHoo! I had logged in to ask about the very same issue. Lt. Dan's legs, you sir are awesome! With a couple of small tweaks this will do exactly what I need and save me several hours of fumbling around working out the code. Thank you for helping me to end my very bad week on a high note!

Mike

Link to comment
Share on other sites

Watch out when replacing attributed blocks.

 

this correct Alan?

(defun c:mb (/ *error* ent ss ssent id)
 (defun *error* (msg)
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
        (princ (strcat "\n** Error: " msg " **"))
   )
   (setvar 'nomutt 0)
   (princ)
 )
 (while
   (not
     (and
(setq ent (car (entsel "\nSelect source block: ")))
(eq "INSERT" (cdr (assoc 0 (setq ent (entget ent)))))
     )
   )
   (prompt "\nPlease select a block!!")
 )
 (redraw (cdr (car ent)) 3)
 (prompt "\nSelect blocks to replace: ")
 (setvar 'nomutt 1)
 (repeat (setq id (sslength (setq ss (ssget '((0 . "insert"))))))
   (setq ssent (entget (ssname ss (setq id (1- id)))))
   (entmod (subst (assoc 2 ent)(assoc 2 ssent) ssent))
   [b][color=red](entupd ssent)
[/color][/b]  )
 (setvar 'nomutt 0)
 (redraw (cdr (car ent)) 4)
 (princ)
)

Link to comment
Share on other sites

Entupd works on the entity, not it's data. Try entupd (cdr (assoc -1 ssent.

 

However, I'm talking about what will happen if you replace an attributed block. Try it, you will notice the attributes of the former block are still there. You will have to step through it (using entnext) and entdel each attribute.

 

I use the following; the replacement will only take on the rotation and size of the selected block and the original is just deleted.

http://www.cadtutor.net/forum/showthread.php?48458-Replace-Selected-Block-Or-Blocks-With-Another-Block&p=359585&viewfull=1#post359585

 

BTW, nice work. You are really coming along with your coding.

Link to comment
Share on other sites

Thank you to everybody for the support,

The last code seems to work fine only if the "destination" object to replace is a single object.

If I select more than one object just the last selected object will be replaced.

 

Pls Help Me.

Link to comment
Share on other sites

Entupd works on the entity, not it's data. Try entupd (cdr (assoc -1 ssent.

 

However, I'm talking about what will happen if you replace an attributed block. Try it, you will notice the attributes of the former block are still there. You will have to step through it (using entnext) and entdel each attribute.

 

I use the following; the replacement will only take on the rotation and size of the selected block and the original is just deleted.

http://www.cadtutor.net/forum/showthread.php?48458-Replace-Selected-Block-Or-Blocks-With-Another-Block&p=359585&viewfull=1#post359585

 

BTW, nice work. You are really coming along with your coding.

 

Thank you for your support but seems that your code do not transfer the attributes during the replacement, I need also to do this.

The best would be a mix between the two lsp, yours for multiple selection and the last from Lt Dan for the attributes.

 

Thank you !

Link to comment
Share on other sites

  • 2 weeks later...
this correct Alan?

(defun c:mb (/ *error* ent ss ssent id)
 (defun *error* (msg)
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
        (princ (strcat "\n** Error: " msg " **"))
   )
   (setvar 'nomutt 0)
   (princ)
 )
 (while
   (not
     (and
(setq ent (car (entsel "\nSelect source block: ")))
(eq "INSERT" (cdr (assoc 0 (setq ent (entget ent)))))
     )
   )
   (prompt "\nPlease select a block!!")
 )
 (redraw (cdr (car ent)) 3)
 (prompt "\nSelect blocks to replace: ")
 (setvar 'nomutt 1)
 (repeat (setq id (sslength (setq ss (ssget '((0 . "insert"))))))
   (setq ssent (entget (ssname ss (setq id (1- id)))))
   (entmod (subst (assoc 2 ent)(assoc 2 ssent) ssent))
   [b][color=red](entupd ssent)
[/color][/b]  )
 (setvar 'nomutt 0)
 (redraw (cdr (car ent)) 4)
 (princ)
)

 

Thank you for your support, but seems that the above code substitutes only the block attribute and not the complete block with the source blocks attributes.

Thank You

Link to comment
Share on other sites

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...