Jump to content

Looking for a Lisp to replace a block with another version of the same block in several drawings (Batch)


Recommended Posts

Posted

Hi everyone, I have looked for something similar here but have not succeeded.

 

I have several drawings in a folder that I need to open one by one, delete a block, purge the block, and finally paste the new block version.

 

The new block version is in another dwg, which I copied with the base point 0,0. The pasting is in the same coordinate, 0,0. All the blocks (the new version) and the old to be replaced have the same name and are located in the layout at 0,0 (not in the model). I do need to run the purge command after deleting so the block is pated with the new changes.

 

I'm wondering if any of you have an LISP file that can help me automate this process.

 

The inputs could be the Block name, the route of the new block version, and the folder route with the other drawings where the block will be replaced. Another option could be that the lisp is executed over the drawings opened in the current session, and the new block is taken from the active drawing where the command is executed.

Posted

I wrote a post about auto executing a command in batch.

It should work on this problem as well

 

 

  • Like 1
Posted (edited)

Lee Mac has a blocks delete LISP which I think you can modify to remove user interaction

https://lee-mac.com/deleteblocks.html for Lee Macs code

 

Below to remove the block, note the c:blockdelbatch is as an example, removing the block revtriangle (as part of a list that you can add to). You need Lee Macs LISP above.

 

And then just insert the new block. Can use something like Lee Macs script writer to do the batch processing.

 

(defun c:blockdelbatch (/ deletelst)
  (setq deletelst (list "revtriangle"))
  (blksdelbatch deletelst)
)

(defun blksdelbatch ( lst / *error* del lst )

  (defun *error* ( msg )
    (LM:endundo (LM:acdoc))
    (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
      (princ (strcat "\nError: " msg))
    )
    (princ)
  )
  (cond
    (   t
      (LM:startundo (LM:acdoc))
      (setq del  (LM:DeleteBlocks (LM:acdoc) lst))
      (vla-regen (LM:acdoc) acallviewports)
      (foreach block lst
        (if (member (strcase block) del)
          (princ (strcat "\nDeleted block " block "."))
          (princ (strcat "\nUnable to delete block " block "."))
        )
      )
      (LM:endundo (LM:acdoc))
    )
  )    
  (princ)
)

 

 

Edit.

Nearly forgot to say, if this is a simple single block, copy the bock to the clipboard and use 

(command "pasteclip" "0,0")

Edited by Steven P
  • Like 1
Posted

I wrote this program like four years ago (just for fun / exercise) and maybe used it once or twice so as we say here on Mars : guaranteed to the doorstep 😁

If it works 🍻 , if it doesn't ... 🗑️

 

image.thumb.png.b3566b82aabfb22cb6d79df69753bea1.png

 

As usual never wrote a manual so have fun experimenting.

 

🐉

RlxBlockSync.lsp

  • Like 5
Posted (edited)

What about wblock out the new block to a separate dwg name it the current block name, then insert that block dwg into your current dwg, you should get a "do you want to redefine block", may also need attsync on the block. Did this where we changed company address and updated older projects.

Edited by BIGAL
Posted

Just wanted something more flexible , user friendly and sexier for me , myself and I

  • Like 2
Posted

😱 now you tell me 😁

 

I like this quote “Life is not obliged to give us what we expect.”

Sure , some users don't respond or don't give a like but unlike some users , I don't feel the need to respond to every thread or want to collect as many likes as I can for the sake of reputation points.

 

Most of us are here just to give a helping hand to those who ask for it and expecting eternal glory or whatever only leads to disappointment.

Having said this , I am gratefull for everybody who liked my post. It does give a feeling of appreciation. 🙏

Even when OP is a No Show , others may still find your response useful.

 

So when you do deal with a 'leacher' , just append his folder with "_No_Show" so next time you feel the urge to respond you can lower your expection for ever getting a response.

 

🐉

  • Like 2
  • Thanks 1

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