Jump to content

How to change a block with another block!?


Recommended Posts

Hi All


Im sitting with at little quistion, because I have alot of dwg's with different blocks in them. I now need to change one specific block with another block. Since I have around 100 drawings where I have to change the block then I was hoping that there would be an easy way so I don't have to go in manually in each dwg. Can you help me or give me some hints on how to do this? o:)



I can not change the old block in block editor because I still need it.

Link to comment
Share on other sites

Using VL lisp you can PUT a new block name against an existing block you would read stuff like scale rotation etc as well. Then you could script the 100 dwgs and just churn through very quickly.



open dwg1 (load "blkchange") close Y

open dwg2 etc


 ; this is just to show how it could be done
(setq blkobj (vlax-ename->vla-object(car (entsel "\nPick block"))))
; (setq blkoldname (vla-get-name blkobj)) ; just here to show GET method for block name for ssget
(setq newblk (getstring "\Enter name of new block")) ; note is case sensitive
; need ssget here all blocks
; need vlax-for here to go through all blocks
(vla-put-name blkobj newblk) ; updates block

Link to comment
Share on other sites

Version 2 like Dadgad just script it


open dwg1 -blockreplace oldblockname newblockname N close Y
open dwg2 -blockreplace oldblockname newblockname N close Y
open dwg3 -blockreplace oldblockname newblockname N close Y

Link to comment
Share on other sites

  • 3 years later...

Hi, could someone help me with that lisp or send to me something other, i use a changeblock.lisp, program works excellent, but i need to change block with their base point, that can be possible?


 (defun *ERROR*(msg)
   (if olaySt
     (vla-put-Lock objLay olaySt)
     ); end if
   (vla-EndUndoMark actDoc)
   ); end of *ERROR*
 (defun GetBoundingCenter(vlaObj / blPt trPt cnPt)
 (vla-GetBoundingBox vlaObj 'minPt 'maxPt)
     (setq blPt(vlax-safearray->list minPt)
      trPt(vlax-safearray->list maxPt)
            (+(car blPt)(/(-(car trPt)(car blPt))2))
            (+(cadr blPt)(/(-(cadr trPt)(cadr blPt))2))
           ); end list
     ); end vlax-3D-point
    ); end setq
 ); end of GetBoundingCenter
 (if(not(setq extSet(ssget "_I")))
     (princ "\nSelect objects, need to replace ")
     (setq extSet(ssget))
     ); end progn
   ); end if
 (if(not extSet)
   (princ "\nDistination objects isn't selected!")
   ); end if
   (setq toObj(entsel "\nSelect original object "))
   ); and and
     (setq actDoc
       (vla-get-Layers actDoc)
       (mapcar 'vlax-ename->vla-object
                   (vl-remove-if 'listp
                    (mapcar 'cadr(ssnamex extSet))))
      vlaObj(vlax-ename->vla-object(car toObj))
      objLay(vla-Item layCol
            (vla-get-Layer vlaObj))
      olaySt(vla-get-Lock objLay)
      fromCen(GetBoundingCenter vlaObj)
      errCount 0
      okCount 0
      ); end setq
     (vla-StartUndoMark actDoc)
     (foreach obj extLst
  (setq toCen(GetBoundingCenter obj)
        scLay(vla-Item layCol
             (vla-get-Layer obj))
             );end setq
  (if(/= :vlax-true(vla-get-Lock scLay))
    (setq curLay(vla-get-Layer obj))
    (vla-put-Lock objLay :vlax-false)
    (setq copObj(vla-copy vlaObj))
    (vla-Move copObj fromCen toCen)
    (vla-put-Layer copObj curLay)
    (vla-put-Lock objLay olaySt)
    (vla-Delete obj)
    (setq okCount(1+ okCount))
    ); end progn
    (setq errCount(1+ errCount))
    ); end if
  ); end foreach
  (strcat "\n" (itoa okCount) " were changed. "
     (if(/= 0 errCount)
       (strcat (itoa errCount) " were on locked layer! ")
       ); end if
     ); end strcat
  ); end princ
     (vla-EndUndoMark actDoc)
     ); end progn
   (princ "\nSource object isn't selected! ")
   ); end if
 ); end of c:CHANGEBLOCK

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.

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