Author Topic: Multiple Block Redefinitions  (Read 2173 times)

0 Members and 1 Guest are viewing this topic.

M-dub

  • Guest
Multiple Block Redefinitions
« on: January 23, 2013, 11:09:23 AM »
I swear I had something from years ago that did this for me.

We have umpteen different drawing borders that use umpteen different title blocks and we now have to update a portion of each of the title blocks.
What I want to end up with is a routine that will redefine the one that exists in that particular drawing.

For example, it should look for each of the following and redefine only the one that is used in the current drawing
A-Imp-TitleBlock=O:\Blocks\A-Imp-TitleBlock.dwg
B-Imp-TitleBlock=O:\Blocks\B-Imp-TitleBlock.dwg
C-Imp-TitleBlock=O:\Blocks\C-Imp-TitleBlock.dwg
D-Imp-TitleBlock=O:\Blocks\D-Imp-TitleBlock.dwg
A-Met-TitleBlock=O:\Blocks\A-Met-TitleBlock.dwg
B-Met-TitleBlock=O:\Blocks\B-Met-TitleBlock.dwg
C-Met-TitleBlock=O:\Blocks\C-Met-TitleBlock.dwg
D-Met-TitleBlock=O:\Blocks\D-Met-TitleBlock.dwg

Could someone help me with this, please?
Many thanks!

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Multiple Block Redefinitions
« Reply #1 on: January 23, 2013, 11:14:08 AM »
I would think something like this would work for you:

Code: [Select]
(foreach x '("a-imp-titleblock=o:\\blocks\\a-imp-titleblock.dwg"
     "b-imp-titleblock=o:\\blocks\\b-imp-titleblock.dwg"
     "c-imp-titleblock=o:\\blocks\\c-imp-titleblock.dwg"
     "d-imp-titleblock=o:\\blocks\\d-imp-titleblock.dwg"
     "a-met-titleblock=o:\\blocks\\a-met-titleblock.dwg"
     "b-met-titleblock=o:\\blocks\\b-met-titleblock.dwg"
     "c-met-titleblock=o:\\blocks\\c-met-titleblock.dwg"
     "d-met-titleblock=o:\\blocks\\d-met-titleblock.dwg"
    )
  (if (and (vl-string-position (ascii "=") x)
   (tblobjname "block" (substr x 1 (vl-string-position (ascii "=") x)))
      )
    (command ".-INSERT" x '(0 0 0) (command))
  )
)
*modified to check for existence of block in drawing
*corrected paths per Lee's ninja eyes
« Last Edit: January 23, 2013, 12:39:46 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Multiple Block Redefinitions
« Reply #2 on: January 23, 2013, 11:49:33 AM »
Minor tweaks to Ron's code  :-)

Code: [Select]
(foreach x
   '(
        "a-imp-titleblock=o:\\blocks\\a-imp-titleblock.dwg"
        "b-imp-titleblock=o:\\blocks\\b-imp-titleblock.dwg"
        "c-imp-titleblock=o:\\blocks\\c-imp-titleblock.dwg"
        "d-imp-titleblock=o:\\blocks\\d-imp-titleblock.dwg"
        "a-met-titleblock=o:\\blocks\\a-met-titleblock.dwg"
        "b-met-titleblock=o:\\blocks\\b-met-titleblock.dwg"
        "c-met-titleblock=o:\\blocks\\c-met-titleblock.dwg"
        "d-met-titleblock=o:\\blocks\\d-met-titleblock.dwg"
    )
    (if (and (wcmatch x "*=*") (tblsearch "block" (substr x 1 (vl-string-position 61 x))))
        (command "_.-insert" x nil)
    )
)

(Sorry Ron)

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Multiple Block Redefinitions
« Reply #3 on: January 23, 2013, 12:13:12 PM »
Potayto potawto  :-P  :lmao:

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Multiple Block Redefinitions
« Reply #4 on: January 23, 2013, 12:25:55 PM »
Potayto potawto  :-P  :lmao:
A bit of that, and a few double-backslashes  :wink:

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Multiple Block Redefinitions
« Reply #5 on: January 23, 2013, 12:29:49 PM »
Potayto potawto  :-P  :lmao:
A bit of that, and a few double-backslashes  :wink:

Yeah ... I saw that after I posted.  :oops:

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Multiple Block Redefinitions
« Reply #6 on: January 23, 2013, 12:37:07 PM »
After more thought about this I'd probably approach it like so:
 :-)
Code: [Select]
(defun blockupdater (path filter)
  (foreach x (vl-directory-files path filter 1)
    (if (tblobjname "block" (vl-filename-base x))
      (command "._-insert" (strcat (vl-filename-base x) "=" path x) nil)
    )
  )
)
(blockupdater "o:\\blocks\\" "*titleblock*")

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Multiple Block Redefinitions
« Reply #7 on: January 23, 2013, 12:44:31 PM »
Nice one Ron  :-)

To offer an alternative method:

Code: [Select]
(defun bdef ( dir ftr / msp org )
    (setq dir (vl-string-right-trim "\\" (vl-string-translate "/" "\\" dir))
          msp (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
          org (vlax-3D-point 0 0)
    )
    (foreach dwg (vl-directory-files dir ftr 1)
        (if (tblsearch "BLOCK" (vl-filename-base dwg))
            (vla-delete (vla-insertblock msp org (strcat dir "\\" dwg) 1.0 1.0 1.0 0.0))
        )
    )
    (princ)
)
(vl-load-com) (princ)
Code: [Select]
(bdef "o:\\blocks" "*titleblock*")

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Multiple Block Redefinitions
« Reply #8 on: January 23, 2013, 12:49:54 PM »
I think Mike has some options now.  :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

M-dub

  • Guest
Re: Multiple Block Redefinitions
« Reply #9 on: January 23, 2013, 04:10:24 PM »
Thanks a lot, guys.  I've been away from my desk most of the day.  I'll give this a shot tomorrow.  :)

M-dub

  • Guest
Re: Multiple Block Redefinitions
« Reply #10 on: January 24, 2013, 10:58:53 AM »
Thanks again, you two.  I think this is going to take a lot of the pain out of this exercise.  It's not possible to remove all of the pain, but this will help out on many of our drawings.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Multiple Block Redefinitions
« Reply #11 on: January 24, 2013, 11:00:54 AM »
 8-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Multiple Block Redefinitions
« Reply #12 on: January 24, 2013, 11:12:44 AM »
 8-)