need a lisp code to extract all the blocks as .dwg files in selected folder

hello all,

1.i am badly in need of lisp code to extract all the blocks as .dwg files in selected folder. even batch mode is also acceptable.

2. i got a lisp code to insert blocks from the selected .dwg into working .dwg. right now, this code is able to list all the blocks in dropdown selection box. it is not showing the preview of the blocks. can any one add thumbnails of blocks along with the name please. i am attaching the list code.

can any one please help me in this regard.

Comments

  • Hi Kotesh,

    Change a patch to the folder you need.

    [code](while (setq b (tblnext "BLOCK"))
     (vl-cmdf "_wblock" (strcat "c:\\folder\\" (setq b (cdr (assoc 2 b))) ".dwg") b)
    )[/code]

    Regards, Vaidas
  • @ Vaidas:
    Nice and short. But how about anonymous blocks?
  • @ Roy

    Probably a code must be little bit longer:
    [code](while (setq b (tblnext "BLOCK"))
     (setq b (cdr (assoc 2 b)))
     (if (= "*" (substr b 1 1)) (setq b (strcat "anonymous-" (substr b 2))))
     (vl-cmdf "_wblock" (strcat "c:\\folder\\" b ".dwg") b)
    )[/code]

    regards, Vaidas
  • hi Vaidas Guogis,

    can you guide me how to run your code? can you please attach the file as .lsp and what is the command i have to use for executing this code.

  • @ Kotesh

    Just copy a code, saves it as LSP file and run with APPLOAD command.

    regards, Vaidas
  • must be "save it as " :)
  • i have saved it as extract blocks.lsp,  and added it to appload list.

    where i can find the run command?

  • @ Kotesh

    Updated, run EXTBLOCKS:

    [code]
    (defun extblocks ()
    (while (setq b (tblnext "BLOCK"))
     (setq b (cdr (assoc 2 b)))
     (if (= "*" (substr b 1 1)) (setq b (strcat "anonymous-" (substr b 2))))
     (vl-cmdf "_wblock" (strcat "c:\\folder\\" b ".dwg") b)
    )
    (princ)
    )
    [/code]
  • (extblocks)
  • hai,

    i am getting the following error

    Loading C:\Users\ps2\Desktop\extractblocks.lsp
    Comando: (LOAD "C:/Users/ps2/Desktop/extractblocks.lsp")EXTBLOCKS
    Comando: extblocks

    Unable to recognize command "EXTBLOCKS". Please try again.

  • I'm writing it on-fly, not tested :)
  • i am getting the following error

    A point is needed. Please try again.
    Select entities to copy: c:\folder\Nc.dwg
    A point is needed. Please try again.
    Select entities to copy: Nc
    A point is needed. Please try again.
    Select entities to copy: _wblock
    A point is needed. Please try again.
    Select entities to copy: c:\folder\No.dwg
    A point is needed. Please try again.
    Select entities to copy: No
    A point is needed. Please try again.
    Select entities to copy:
    Select entities to copy:
    Opposite Corner:
    Entities in set: 11
    Select entities to copy:
    Current copy mode: Single



  • To run without brackets:

    (defun c:extblocks ()
    (while (setq b (tblnext "BLOCK"))
     (setq b (cdr (assoc 2 b)))
     (if (= "*" (substr b 1 1)) (setq b (strcat "anonymous-" (substr b 2))))
     (vl-cmdf "_wblock" (strcat "c:\\folder\\" b ".dwg") b)
    )
    (princ)
    )
  • thanks a lot sir. your code is working perfectly. you have helped me a lot.

    once again lot of thanks. if you can give the modification code to attached .lsp please?

  • Glad to hear!
  • @ Kotesh
    Find a code attached.

    extblocks.lsp

  • It loolks like I did no attached the code. Find it fo rnow.

    wblock.lsp

  • OOps, the problems with attachments in this forum?
  • Heh, interesting :)
    I can't see my code attached still I'm connected with the Meeting Point and it is visible when I'm unconnected :)
    OK, please do not use the last one, please use extblocks.lsp file attached before.
    regards, Vaidas
  • @ Stephan

    Sure, you are right about second run, because to get first item from the list it's required to execute [code](tblnext "BLOCK" T)[/code]

    regards, Vaidas
  • I would suggest not extracting anonymous block. There are all sorts of anonymous blocks: *U, *D (dimensions!), *T, and no doubt there are others. The average user does not want to extract these blocks.

    @ Stephan: I can't reproduce your "not found" issue.
  • Thanks for the feedback.
    Maybe I get the error because of using a German version?
    This is my command line history:[code]: (defun c:extblocks ( / b fname)
    (_> (while (setq b (tblnext "BLOCK" (not b)))
    ((_>  (setq b (cdr (assoc 2 b)))
    ((_>  (if (= "*" (substr b 1 1)) (setq b (strcat "anonymous-" (substr b 2))))
    ((_>  (vl-cmdf "_wblock" (strcat "S:\\" b ".dwg") b)
    ((_> )
    (_> (princ)
    (_> )
    C:EXTBLOCKS
    : EXTBLOCKS
    : _wblock
    Dateiname für neue Zeichnung/Block: S:\anonymous-U1.dwg
    EINGABETASTE drücken, um Objekte zu wählen/& um mehrere Blöcke zu wählen/* für die komplette Zeichnung/ : anonymous-U1
    -- Block anonymous-U1 nicht gefunden. --
    EINGABETASTE drücken, um Objekte zu wählen/& um mehrere Blöcke zu wählen/* für die komplette Zeichnung/ : [/code]
  • Stephan, I think you may be right. The "" option is missing in your command line history. And this bit is strange:
    [code]...für die komplette Zeichnung/ : anonymous-U1[/code]
    You would expect an additional option after the last "/".

    My command line history:
    [code]: (defun c:extblocks ( / b fname)
    (_> (while (setq b (tblnext "BLOCK" (not b)))
    ((_>  (setq fname (cdr (assoc 2 b)))
    ((_>  (if (= "*" (substr fname 1 1)) (setq fname (strcat "anonymous-" (substr fname 2))))
    ((_>  (vl-cmdf "_wblock" (strcat "C:\\" fname ".dwg") (cdr (assoc 2 b)))
    ((_> )
    (_> (princ)
    (_> )
    C:EXTBLOCKS
    : EXTBLOCKS
    : _wblock
    File name for new drawing/block: C:\anonymous-U2.dwg
    ENTER to select entities/& to include multiple blocks/* for whole drawing/ : *U2
    : _wblock
    File name for new drawing/block: C:\anonymous-U3.dwg
    ENTER to select entities/& to include multiple blocks/* for whole drawing/ : *U3[/code]

    BTW: I didn't know you could copy/paste a complete lisp function to the command line. That is a nice tip. Thanks for that.
  • I should know better by now... The "Pointy Bracket Problem" has hit me again!

    The first line of my previous post should read:
    Stephan, I think you may be right. The "<Block to save as WBlock>" option is missing in your command line history. And this bit is strange:
  • OK, this is "hilarious" (but not really...): Of course my command line history as well as Stephan's also suffer from this "Pointy Bracket Problem"
    [code]
    My command line history should look like this:
    : (defun c:extblocks ( / b fname)
    (_> (while (setq b (tblnext "BLOCK" (not b)))
    ((_>  (setq fname (cdr (assoc 2 b)))
    ((_>  (if (= "*" (substr fname 1 1)) (setq fname (strcat "anonymous-" (substr fname 2))))
    ((_>  (vl-cmdf "_wblock" (strcat "C:\\" fname ".dwg") (cdr (assoc 2 b)))
    ((_> )
    (_> (princ)
    (_> )
    C:EXTBLOCKS
    : EXTBLOCKS
    : _wblock
    File name for new drawing/block: C:\anonymous-U2.dwg
    ENTER to select entities/& to include multiple blocks/* for whole drawing/ <Block to save as WBlock>: *U2
    : _wblock
    File name for new drawing/block: C:\anonymous-U3.dwg
    ENTER to select entities/& to include multiple blocks/* for whole drawing/ <Block to save as WBlock>: *U3
    [/code]
  • BTW: Some sentences in the thread are only partly visible... I think some CSS issue may be to blame. Post #1, #23 and #27 are affected.
This discussion has been closed.