Author Topic: WBLOCK - multiple drawings  (Read 745 times)

0 Members and 1 Guest are viewing this topic.

like_citrus

  • Newt
  • Posts: 77
WBLOCK - multiple drawings
« on: February 15, 2021, 06:02:19 AM »
Is there a LISP routine which would apply WBLOCK to multiple drawings?
There is 1 dynamic block per drawing.

Lee Mac

  • Seagull
  • Posts: 12488
  • London, England
Re: WBLOCK - multiple drawings
« Reply #1 on: February 15, 2021, 06:18:32 AM »
I would suggest using a Script for this task.

Set FILEDIA=0 prior to running the Script and call the -WBLOCK command from the Script, specifying the output filename/path and either the block name or "=" if the block name is the same as the output filename.

like_citrus

  • Newt
  • Posts: 77
Re: WBLOCK - multiple drawings
« Reply #2 on: February 15, 2021, 07:04:56 AM »
Thanks for responding.
I couldn't see any examples online for something similar.
Is the coding for the script in AutoCAD different to say a Windows application.

Lee Mac

  • Seagull
  • Posts: 12488
  • London, England
Re: WBLOCK - multiple drawings
« Reply #3 on: February 15, 2021, 08:05:50 AM »
Here's a tutorial I've written some time ago to help get you started: An Introduction to Script Writing

like_citrus

  • Newt
  • Posts: 77
Re: WBLOCK - multiple drawings
« Reply #4 on: February 15, 2021, 08:58:43 AM »
OK great, this has answered a few things such as processing each file, opening, saving and closing.
I just need to sort out how to carry out each step in the WBLOCK process, specifying the block (same as filename) and the output folder.
When I went to the command line (after running WBLOCK), there isn't anything which gives a clue as to what the code may be. The only thing I see is "Command: WBLOCK" but nothing after that.

roy_043

  • Water Moccasin
  • Posts: 1870
  • BricsCAD 18
Re: WBLOCK - multiple drawings
« Reply #5 on: February 15, 2021, 01:46:37 PM »
Try using '-wblock' (with a dash) instead.

Lee Mac

  • Seagull
  • Posts: 12488
  • London, England
Re: WBLOCK - multiple drawings
« Reply #6 on: February 15, 2021, 03:13:29 PM »
Set FILEDIA=0 ... and call the -WBLOCK command..., specifying the output filename/path and either the block name or "=" if the block name is the same as the output filename.

BIGAL

  • Swamp Rat
  • Posts: 711
  • 30 + years of using Autocad
Re: WBLOCK - multiple drawings
« Reply #7 on: February 15, 2021, 06:32:53 PM »
Like the others, look at what wblock asks for the "N" is applicable if using CIV3D.

Code: [Select]
(command "-wblock"  (strcat "d:\\acadtemp\\" dwgname) "" "0,0" ss2 "" "N")

(command "_.-wblock" fn "_Y")
A man who never made a mistake never made anything

like_citrus

  • Newt
  • Posts: 77
Re: WBLOCK - multiple drawings
« Reply #8 on: February 15, 2021, 08:12:26 PM »
Thank you, I should have paid more attention to the first response. The code is actually getting a result now.
I added another "_.qsave" and "_.close" as there are 2 drawings being handled per cycle.

With the new block, this will be used in a menu file, and needs to be the same type of block when using WBLOCK manually. You can tell the block is different when opening the file, the message should be: "Blk_1_new.dwg contains authoring elements. Open in Block Editor?". But this message does not come up.

Code: [Select]
_.open "C:\TestScr\Blk_1.dwg" -WBLOCK "C:\TestScr\New\Blk_1_new.dwg" * _.qsave _.close _.qsave _.close

Lee Mac

  • Seagull
  • Posts: 12488
  • London, England
Re: WBLOCK - multiple drawings
« Reply #9 on: February 16, 2021, 04:55:29 AM »
I added another "_.qsave" and "_.close" as there are 2 drawings being handled per cycle.

This shouldn't be necessary - what was happening when you omitted one set of 'qsave & close' commands?

You can tell the block is different when opening the file, the message should be: "Blk_1_new.dwg contains authoring elements. Open in Block Editor?". But this message does not come up.

Code: [Select]
_.open "C:\TestScr\Blk_1.dwg" -WBLOCK "C:\TestScr\New\Blk_1_new.dwg" * _.qsave _.close _.qsave _.close

This is because you are supplying the "*" option to the -WBLOCK command, which will WBLOCK the entire drawing rather than just the block definition - you should instead specify the name of the block to be exported, or use the "=" option if the block name matches the filename of the new drawing.

like_citrus

  • Newt
  • Posts: 77
Re: WBLOCK - multiple drawings
« Reply #10 on: February 16, 2021, 07:47:49 AM »
Thank you. I think it's all good now.
The snippet below works. It gives the block with the message ""... contains authoring elements. Open in Block Editor?". The program also closes with one set of "_.qsave _.close ". Note that there is a space after the last close, maybe this is what I missed before.
I couldn't get it to work with "=" as it asked for prompts after the base drawing was opened, instead the name of the block was written.

Code: [Select]
_.open "C:\Test_W_block\dwg_1.dwg" -WBLOCK "C:\Test_W_block\New\dwg_1_new.dwg" block_1 _.qsave _.close
_.open "C:\Test_W_block\dwg_2.dwg" -WBLOCK "C:\Test_W_block\New\dwg_2_new.dwg" block_2 _.qsave _.close

Lee Mac

  • Seagull
  • Posts: 12488
  • London, England
Re: WBLOCK - multiple drawings
« Reply #11 on: February 16, 2021, 08:05:29 AM »
Thank you. I think it's all good now.
The snippet below works. It gives the block with the message ""... contains authoring elements. Open in Block Editor?". The program also closes with one set of "_.qsave _.close ". Note that there is a space after the last close, maybe this is what I missed before.

Excellent  :-)

I couldn't get it to work with "=" as it asked for prompts after the base drawing was opened, instead the name of the block was written.

Code: [Select]
_.open "C:\Test_W_block\dwg_1.dwg" -WBLOCK "C:\Test_W_block\New\dwg_1_new.dwg" block_1 _.qsave _.close
_.open "C:\Test_W_block\dwg_2.dwg" -WBLOCK "C:\Test_W_block\New\dwg_2_new.dwg" block_2 _.qsave _.close

As noted, the "=" option is used if the block name matches the output filename (i.e. if you were exporting a block with block name "dwg_1_new") - note that when you insert your dynamic block into new drawings, the block name will be dwg_1_new instead of block_1 - this may or may not be desirable.

like_citrus

  • Newt
  • Posts: 77
Re: WBLOCK - multiple drawings
« Reply #12 on: February 16, 2021, 08:35:10 AM »
Yes I did try various attempts with the "=" sign. I got the first drawing to output at one point but forgot how I did it.
At this stage I can't see any issue with the name of the block being the same as the filename.
Thanks for your help.

like_citrus

  • Newt
  • Posts: 77
Re: WBLOCK - multiple drawings
« Reply #13 on: February 17, 2021, 01:33:16 AM »
If this assists anyone, it's an Excel macro to automatically write the code by processing each file in a selected folder.
The data is first written into Excel and then converted to a script file in the same directory.
A sub-folder is created for the WBLOCKS to be saved when the script is run in AutoCAD.

If you are new to macros, in Excel, go to the Developer tab and click Macros to run the macro. The only input is to select the folder.
The code can be adjusted if you go to Developer, Visual Basic.