See the top rated post in this thread. Click here

Results 1 to 8 of 8

Thread: Export list of Blocks to individual drawing files

  1. #1
    I could stop if I wanted to
    Join Date
    2001-01
    Posts
    244
    Login to Give a bone
    0

    Default Export list of Blocks to individual drawing files

    Hi All
    I have created a list of known blocks that I want to wblock into individual drawings. I wrote the following routine but it is not working. I am not sure why it is not. Any help is greatly appreciated. Thank you.
    Manuel A. Ayala

    Code:
    (defun c:blk2dwg (/ tcblklst bdval bdsel)
      (setq tcblklst '("COAX" "COAX2" "DATA1" "DATA2" "DATA3" "DATA5" "DATA6" "DATA2COAX1"))
      (setq bdval 0)
      (foreach item 'tcblklst
        (if (tblsearch "BLOCK" item)
          (progn
            (setq bdsel (ssget "X" '((0. "INSERT")(2 . item))) bdval (+ 1 bdval))
            (if bdsel
              (command "_.wblock" (strcat (gevar "dwgprefix") "tc-blocks-" (itoa bdval)) "" "0,0" bdsel)
            )
          )
        )
      )
    (prompt "\nAll done")
    (princ)
    )

  2. #2
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    8,780
    Login to Give a bone
    0

    Default Re: Export list of Blocks to individual drawing files

    You are wanting to WBLOCK out the insertions of those block names to the current drawing's folder. Is that correct? On your command line element, did you finish the necessary responses to your command? You may be missing a set of double quotes at the end.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  3. #3
    I could stop if I wanted to
    Join Date
    2002-08
    Posts
    212
    Login to Give a bone
    0

    Default Re: Export list of Blocks to individual drawing files

    I have the impression that bdval is incremented only once, so the next time 'wblock' will ask for confirmation for a file that already exists.
    (setq bdsel (ssget "X" '((0. "INSERT")(2 . item))) bdval (+ 1 bdval))
    ->
    (setq bdsel (ssget "X" '((0. "INSERT")(2 . item))) (setq bdval (+ 1 bdval))) ??? not tested!

  4. #4
    Login to Give a bone
    0

    Default Re: Export list of Blocks to individual drawing files

    If you would like a ready to use (and free) tool, take a look at AutoWblock from the Autodesk App Store.

    https://apps.autodesk.com/ACD/en/Det...en&os=Win32_64

  5. #5
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    561
    Login to Give a bone
    1

    Default Re: Export list of Blocks to individual drawing files

    Corrections to the code that was posted :

    Code:
    (defun c:blk2dwg ( / tcblklst bdval bdsel )
      (setq tcblklst '("COAX" "COAX2" "DATA1" "DATA2" "DATA3" "DATA5" "DATA6" "DATA2COAX1"))
      (setq bdval 0)
      (foreach item tcblklst ;;; 'tcblklst  should be just tcblklst - lisp evaluates variable just by suppliying its declaration (without any additions like quotes-double quotes-back quotes, slashes-back slashes, tildes, or apostophes (which are used for specifying literal specifications - no evaluation processing))
        (if (tblsearch "BLOCK" item)
          (progn
            (setq bdsel (ssget "X" (list '(0 . "INSERT") (cons 2 item))) bdval (+ 1 bdval)) ;;; when composing list with values contained in some variable/symbol - here "item", be sure you pass it to (ssget) function correctly - literal expressions won't work : this is wrong - '((0. "INSERT")(2 . item)), should be either - 1. (list '(0 . "INSERT") (cons 2 item)) or 2. (list (cons 0 "INSERT") (cons 2 item)) 
            (if bdsel
              (command "_.wblock" (strcat (gevar "dwgprefix") "tc-blocks-" (itoa bdval)) "" "0,0" bdsel "") ;;; Opie's suggestion - you probably missed "" at the end of (command) statement - it mimic pressing ENTER when bdsel selection was called through (command) function
            )
          )
        )
      )
      (prompt "\nAll done")
      (princ)
    )

  6. #6
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    503
    Login to Give a bone
    0

    Default Re: Export list of Blocks to individual drawing files

    Pretty sure came across this and a problem. If the wblock exists then the command asks for a extra "Y" so I checked does wblock exist if so in a "IF" 2 options second has the "Y" just use (findfile wblockname) must include path will return NIL if does not exist.
    Last edited by BIG-AL; 2022-02-20 at 11:38 PM.

  7. #7
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,560
    Login to Give a bone
    1

    Default Re: Export list of Blocks to individual drawing files

    Many ways to import blocks from a drawing with a list of known blocks so I'll offer two more.

    Open Design Center with MUTCD.dwg with macro:
    Code:
    ^C^C^P(command "adcnavigate" "G:/ENGDESGN/BeaufordT/Blocks/MUTCD.dwg")
    Open Blockspalette to Typicals.dwg:
    Code:
    ^C^C-blocknavigate;"G:/ENGDESGN/BeaufordT/Blocks/Typicals/Typicals.dwg";_blockspalette
    With either of these you can pick the block you want from those displayed in a window.

    To insert a ScaleBar matching current Annotation scale:
    Code:
    ^C^C^P(or C:ScaleBarIns (load "ScaleBarIns.lsp"));ScaleBarIns
    Code:
    (defun c:ScaleBarIns (/ Trim0s bNameLoc InsScl InsPt Rot bName Clayer )
    
     (defun Trim0s (xb) ; Thank ronjonp
      (if (= (type xb) 'real); Trim 0's from end of string conversion, then trim . if it's at the end afterwards.
       (vl-string-right-trim "." (vl-string-right-trim "0" (vl-princ-to-string xb)))
       (itoa xb); if integer convert to string without trimming 0's from end.
      )
     )
    
     (if (= 1 (getvar 'cvport))(command-s "MSPACE"))
     (load "GetBlock.lsp")
     (setq bNameLoc (strcat (vl-filename-directory (findfile "VDOT.LSP")) (chr 92) "Scales2.dwg")
         InsScl (Trim0s(/ 1(vla-get-CustomScale (vla-get-ActivePViewport (vla-get-activedocument (vlax-get-acad-object))))))
         InsPt (getvar "viewctr")
         Rot (if(zerop (getvar 'worlducs))0(/ (* 180 (- (getvar "viewtwist"))) pi))
         bName (strcat "Scale" InsScl "-2")
         Clayer (getvar 'clayer)
     )
     (princ "\nRot = ")(princ Rot)
    ; -INSERTCONTENT 
    ; https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2021/ENU/AutoCAD-Core/files/GUID-B5D64510-561E-4FA9-8AD6-625445CCD81F-htm.html
     (or (tblsearch "BLOCK" bName)(GetBlock bNameLoc bName))
     (if (tblsearch "BLOCK" bName)
      (progn
       (setvar 'clayer (strcat "Scale" InsScl))
       (command-s "-INSERT" bName "R" Rot "S" 1 (getpoint "ScaleBar insertion point: "))
      ); progn
      (princ (strcat "\nSorry no ScaleBar for viewport scale of " InsScl "."))
     ); if (tblsearch "BLOCK" bName)
     (setvar 'clayer Clayer)
     (princ)
    )
    Other than that I usually use Lee Mac's Steal From Drawing which allows you to import groups almost anything from other drawings.
    The user may choose multiple items from a list of:

    - Blocks
    - Layers
    - Linetypes
    - Dimension Styles
    - Text Styles
    - Table Styles
    - MLeader Styles
    - MLine Styles
    - Layouts
    - Page Setups
    - User Coordinate Systems
    - Groups
    - Views
    - Layer States
    - Scales
    - Materials
    - Viewports
    - Drawing Properties
    - Custom Properties

    I use it everyday, thanks Lee!
    Attached Files Attached Files
    Last edited by Tom Beauford; 2022-02-21 at 03:08 PM. Reason: added more options

  8. #8
    I could stop if I wanted to
    Join Date
    2001-01
    Posts
    244
    Login to Give a bone
    0

    Default Re: Export list of Blocks to individual drawing files

    Thank you very much. I'll give this a try.
    Manuel

Similar Threads

  1. Convert multiple layouts to individual drawing files
    By ase in forum AutoCAD Customization
    Replies: 3
    Last Post: 2012-12-27, 04:14 PM
  2. Exdclude individual elements from IFC Export?
    By janne in forum Revit Architecture - General
    Replies: 4
    Last Post: 2012-08-07, 08:42 AM
  3. export individual sheets from '08 to '09?
    By chris.spenski in forum Revit Structure - General
    Replies: 3
    Last Post: 2009-04-14, 07:18 PM
  4. Exporting Layouts to individual drawing files
    By andrewd in forum AutoCAD Customization
    Replies: 7
    Last Post: 2006-08-13, 11:39 AM
  5. Export Layouts as individual drawing files
    By patricks in forum AutoCAD General
    Replies: 3
    Last Post: 2006-08-11, 12:31 PM

Posting Permissions

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