+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Forum Newbie
    Using
    AutoCAD 2014
    Join Date
    Jul 2014
    Posts
    7

    Default How to change a block with another block!?

    Registered forum members do not see this ad.

    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?

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

  2. #2
    Luminous Being Dadgad's Avatar
    Using
    AutoCAD 2013
    Join Date
    Nov 2011
    Location
    At the confluence of worthlessness & invaluability
    Posts
    6,056

    Default

    Try using the BLOCKREPLACE command.
    Volume and repetition do not validate opinions forged in the absence of thought.

  3. #3
    Quantum Mechanic BIGAL's Avatar
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    10,794

    Default

    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.

    script
    open dwg1 (load "blkchange") close Y
    open dwg2 etc

    Code:
     ; 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
    A man who never made mistakes never made anything

  4. #4
    Quantum Mechanic BIGAL's Avatar
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    10,794

    Default

    Version 2 like Dadgad just script it

    Code:
    open dwg1 -blockreplace oldblockname newblockname N close Y
    open dwg2 -blockreplace oldblockname newblockname N close Y
    open dwg3 -blockreplace oldblockname newblockname N close Y
    A man who never made mistakes never made anything

  5. #5
    Forum Newbie
    Discipline
    Electrical
    Using
    AutoCAD 2018
    Join Date
    Oct 2017
    Posts
    2

    Default

    Registered forum members do not see this ad.

    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?

    Code:
    (defun c:CHANGEBLOCK(/ ACTDOC COPOBJ ERRCOUNT EXTLST
            EXTSET FROMCEN LAYCOL MAXPT CURLAY
            MINPT OBJLAY OKCOUNT OLAYST
            SCLAY TOCEN TOOBJ VLAOBJ *ERROR*)
      (vl-load-com)
      (defun *ERROR*(msg)
        (if olaySt
          (vla-put-Lock objLay olaySt)
          ); end if
        (vla-EndUndoMark actDoc)
        (princ)
        ); 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)
           cnPt(vlax-3D-point
            (list
                 (+(car blPt)(/(-(car trPt)(car blPt))2))
                 (+(cadr blPt)(/(-(cadr trPt)(cadr blPt))2))
              0.0
                ); end list
          ); end vlax-3D-point
         ); end setq
      ); end of GetBoundingCenter
      (if(not(setq extSet(ssget "_I")))
        (progn
          (princ "\nSelect objects, need to replace ")
          (setq extSet(ssget))
          ); end progn
        ); end if
      (if(not extSet)
        (princ "\nDistination objects isn't selected!")
        ); end if
      (if
        (and
        extSet
        (setq toObj(entsel "\nSelect original object "))
        ); and and
        (progn
          (setq actDoc
            (vla-get-ActiveDocument
              (vlax-get-Acad-object))
           layCol
            (vla-get-Layers actDoc)
           extLst
            (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))
         (progn
         (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
          (princ
       (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
      (princ)
      ); end of c:CHANGEBLOCK

Similar Threads

  1. Select dynamic block and change to a different block
    By johny4901 in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 7th Mar 2012, 09:52 pm
  2. Replies: 16
    Last Post: 25th May 2011, 06:56 pm
  3. Change the object layer of block to on which the block is inserted
    By symoin in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 4th Jan 2011, 09:52 pm
  4. change dynamic block into standard block
    By cadamrao in forum AutoLISP, Visual LISP & DCL
    Replies: 3
    Last Post: 11th May 2010, 10:06 am

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts