+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14
  1. #1
    Forum Newbie
    Discipline
    HVAC
    Using
    Revit 2018
    Join Date
    Jan 2018
    Posts
    5

    Default List routine that replaces named block with other named block in drawing

    Registered forum members do not see this ad.

    Hi,

    wondering if any one can help me with this one. ive had a look throuhg similar threads but cant seem to find what im after.

    I need a lisp that essentially does what block replace does but without the required user input of selecting blocks.

    Say i have a block called "Circle 102" and i always want to replace this circle 102 block with one of another name. e.g "block 1"
    Then be able to do it to "Circle 103" with another "block 2"

    and so on and so on.

    If anyone can help me out as its doing my head in trying to think this one out.

    Cheers

  2. #2
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2016
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    667

    Default

    Hi Mattdalgety, welcome on CadTutor


    I have one of my own (but its a kind of a dragon) : http://www.cadtutor.net/forum/showth...ghlight=rlxblk


    I believe Tharwat has one that is a bit more friendly to use but can't find it so quickly so hope he reads this post and replies too.
    only found this site : https://autolispprograms.wordpress.c...c-application/


    ah , found it : https://apps.autodesk.com/ACD/en/Det...en&os=Win32_64


    And last but not least , I have no doubt master Lee has something on his brilliant site : http://www.lee-mac.com/index.html


    gr. Rlx
    Last edited by rlx; 12th Jan 2018 at 07:30 am.

  3. #3
    Forum Newbie
    Discipline
    HVAC
    Using
    Revit 2018
    Join Date
    Jan 2018
    Posts
    5

    Default

    Thanks mate, had a look at your routine and it looks a little bit more complicated than what im after.

    Essentially i just need a "dumb" lisp routine that i can set once and leave it.

    ie run command and it replaces all the nominated blocks with the other nominated blocks.

    eg block 1 replaces block a
    block 2 replaces block b
    block 3 replaces block c etc.

    What im using this for is to convert exported sprinkler symbols (or should i say lines and circles.) from revit to my own blocks.

    as revit to cad exports these as arcs and circles, im using a command to convert these to blocks based on radius, then i use block-replace to replace say blockname: radius200 with blockname :sprinklerupright.

    right now its a manual process for me to select each block.

    Im looking to streamline this so it clicks once and replaces all predefined block names.


    Quote Originally Posted by rlx View Post
    Hi Mattdalgety, welcome on CadTutor


    I have one of my own (but its a kind of a dragon) : http://www.cadtutor.net/forum/showth...ghlight=rlxblk


    I believe Tharwat has one that is a bit more friendly to use but can't find it so quickly so hope he reads this post and replies too.


    And last but not least , I have no doubt master Lee has something on his brilliant site : http://www.lee-mac.com/index.html


    gr. Rlx

  4. #4
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,109

    Default

    Thank you Rlx for your recommendations.

    I guess this link is what the OP wants. Replace Blocks with Another

  5. #5
    Forum Newbie
    Discipline
    HVAC
    Using
    Revit 2018
    Join Date
    Jan 2018
    Posts
    5

    Default

    Thanks guys,

    still doesn't look quite what im after.

    These routines are a little too complex with the user inputs

    what im really after is a dumbed down version of blockreplace, where instead of the user selecting the block to be replaced and then replace it, rather me being able to type out the blockname and save it into the routine so the command doesnt have to pause for the user input each time.

    eg. run routine

    lisp finds all blocks titles "blocka.dwg"

    replace all blocka.dwg with block b.dwg.

    Then search for the next one.

    find all blocks titles "blockc.dwg"

    replace all blockc.dwg with block d.dwg.

    and so on.


    Quote Originally Posted by Tharwat View Post
    Thank you Rlx for your recommendations.

    I guess this link is what the OP wants. Replace Blocks with Another

  6. #6
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2016
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    667

    Default

    Quote Originally Posted by mattdalgety View Post
    Thanks guys,

    still doesn't look quite what im after.

    These routines are a little too complex with the user inputs

    what im really after is a dumbed down version of blockreplace, where instead of the user selecting the block to be replaced and then replace it, rather me being able to type out the blockname and save it into the routine so the command doesnt have to pause for the user input each time.

    eg. run routine

    lisp finds all blocks titles "blocka.dwg"

    replace all blocka.dwg with block b.dwg.

    Then search for the next one.

    find all blocks titles "blockc.dwg"

    replace all blockc.dwg with block d.dwg.

    and so on.

    Unfortunately haven't come around implementing multiple blocks & script mode for my appie and somebody just gave me a load of work although if blocks are not dynamic and have no attributes that need to be migrated this would probably be relatively simpel.


    But just to give a hint , you can use the = option from the insert comand : -insert "BlockA=c:/temp/BlockB" would redefine all blocks with name "BlockA" with definition of "BlockB" (but name would still be BlockA) , or , just name blockB on file also BlockA. Just mind the setting of expert variable. Insert it once on 0,0 for example , entdel entlast , et voila...


    gr. Rlx
    Last edited by rlx; 12th Jan 2018 at 11:55 am.

  7. #7
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,109

    Default

    Hi,
    A quickie code that should work with regular blocks only (not Dynamic nor Attributed blocks).
    Code:
    (defun c:repblocks (/ blk1 blk2 msg1 msg2 doc)
      ;; Tharwat - Date: 12.Jan.2018	;;
      (setq blk1 "BlockA"
            blk2 "BlockB"
            msg1 "Block name <"
            msg2 "> could not be found in this drawing <!>"
            doc  (vla-get-activedocument (vlax-get-acad-object))
      )
      (if
        (and (or (setq sel (ssget "_X" (list '(0 . "INSERT") (cons 2 blk1))))
                 (alert (strcat msg1 blk1 msg2))
             )
             (or (tblsearch "BLOCK" blk2)
                 (alert (strcat msg1 blk2 msg2))
             )
        )
         (vlax-for spc (vla-get-blocks doc)
           (if (= (vla-get-islayout spc) :vlax-true)
             (vlax-for blk spc
               (and (= "AcDbBlockReference" (vla-get-objectname blk))
                    (= (vla-get-name blk) blk1)
                    (vla-insertblock
                      spc
                      (vla-get-insertionpoint blk)
                      blk2
                      (vla-get-xscalefactor blk)
                      (vla-get-yscalefactor blk)
                      (vla-get-zscalefactor blk)
                      (vla-get-rotation blk)
                    )
                    (vla-delete blk)
               )
             )
           )
         )
      )
      (princ)
    ) (vl-load-com)

  8. #8
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2016
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    667

    Default

    beautiful in its simplicity Tharwat

  9. #9
    Luminous Being Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draughtsman
    Discipline
    Mechanical
    Details
    HVAC, Drainage, Water Supply, Fire Fighting and a little about Electricity.
    Using
    AutoCAD 2015
    Join Date
    Oct 2009
    Location
    Great Syria , Living in Abu Dhabi
    Posts
    6,109

    Default

    Quote Originally Posted by rlx View Post
    beautiful in its simplicity Tharwat
    Thank you.

  10. #10
    Forum Newbie
    Discipline
    HVAC
    Using
    Revit 2018
    Join Date
    Jan 2018
    Posts
    5

    Default

    Registered forum members do not see this ad.

    Works like a charm.

    Cheers guys, absolute legends.


    Quote Originally Posted by Tharwat View Post
    Hi,
    A quickie code that should work with regular blocks only (not Dynamic nor Attributed blocks).
    Code:
    (defun c:repblocks (/ blk1 blk2 msg1 msg2 doc)
      ;; Tharwat - Date: 12.Jan.2018	;;
      (setq blk1 "BlockA"
            blk2 "BlockB"
            msg1 "Block name <"
            msg2 "> could not be found in this drawing <!>"
            doc  (vla-get-activedocument (vlax-get-acad-object))
      )
      (if
        (and (or (setq sel (ssget "_X" (list '(0 . "INSERT") (cons 2 blk1))))
                 (alert (strcat msg1 blk1 msg2))
             )
             (or (tblsearch "BLOCK" blk2)
                 (alert (strcat msg1 blk2 msg2))
             )
        )
         (vlax-for spc (vla-get-blocks doc)
           (if (= (vla-get-islayout spc) :vlax-true)
             (vlax-for blk spc
               (and (= "AcDbBlockReference" (vla-get-objectname blk))
                    (= (vla-get-name blk) blk1)
                    (vla-insertblock
                      spc
                      (vla-get-insertionpoint blk)
                      blk2
                      (vla-get-xscalefactor blk)
                      (vla-get-yscalefactor blk)
                      (vla-get-zscalefactor blk)
                      (vla-get-rotation blk)
                    )
                    (vla-delete blk)
               )
             )
           )
         )
      )
      (princ)
    ) (vl-load-com)

Similar Threads

  1. replace an object (rectangle) with a named block and keep the hyperlink
    By Jaap Marchal in forum AutoLISP, Visual LISP & DCL
    Replies: 18
    Last Post: 15th Mar 2017, 05:17 pm
  2. Inserting a block in named UCS then moving it in WCS
    By Dorian Gray in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 2nd Mar 2016, 02:49 am
  3. dynamic block + named view + model space = broken link...
    By baker in forum AutoCAD Drawing Management & Output
    Replies: 1
    Last Post: 2nd Apr 2013, 06:23 pm
  4. Explode block except named
    By LISP2LEARN in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 8th Jun 2011, 02:31 am
  5. Open a drawing to a named view
    By AutoCAD Tips Blog in forum AutoCAD RSS Feeds
    Replies: 0
    Last Post: 28th Sep 2006, 03:50 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