Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

wblock lisp routine

15 REPLIES 15
Reply
Message 1 of 16
cadiehl
6231 Views, 15 Replies

wblock lisp routine

I found a lisp routine that "almost" does exactly what I am looking for....

 

I basically nest many parts on several plates in one cad file. I would like to be able to wblock each plate separately into it's own new cad file (while retaining the plate in the current cad file), and be able to have whatever insertion point I choose be inserted into the newly created cad file as 0,0,0.

 

This routine below is so close to working perfectly, but has a glitch somewhere.

 

(defun c:qwblock (/ DIR ENTXT SS TXT PT)
  (setq Dir (getvar "DWGPREFIX"))
  (while (AND (vl-file-directory-p Dir)
          (setq enTxt (car(entsel "\nSelect Block name Text: ")))
          (eq (cdr (assoc 0 (entget enTxt))) "TEXT")
          (setq txt (cdr (assoc 1 (entget enTxt))))
          (not (findfile (setq txt (strcat Dir txt))))
          (setq pt (getpoint "\nPick Insertion Point: "))
          (setq ss (ssget))
          )
     (progn
    (vl-cmdf "ucs" "o" pt)    ;move 0,0,0 to new point)
    (vl-cmdf "_-wblock" txt "" pt ss "")    
          (vl-cmdf "_-insert" txt pt "" "" "")
      )
    )
  (princ)
)

----------------------------------------------------------------------

The routine is not retaining the plates in the cad file for some reason. They are being removed. Below is what is in the autocad text window.

-----------------------------------------------------------------------

Command: qwblock
Select Block name Text:
Pick Insertion Point:
Select objects: Specify opposite corner: 25 found

Select objects:  ucs
Current ucs name:  *WORLD*
Specify origin of UCS or [Face/NAmed/OBject/Previous/View/World/X/Y/Z/ZAxis]
<World>: o
Specify new origin point <0,0,0>:
Command: _-wblock Enter name of output file:
C:\~PROJECTS\1323-LAIRD-MISENER\NEST FILE = MISENER123_NEST_BH01_r0.DWG
Enter name of existing block or
[= (block=output file)/* (whole drawing)] <define new drawing>: Specify
insertion base point:
Select objects:   25 found

Select objects:
Command: _-insert Enter block name or [?]: C:\~PROJECTS\1323-LAIRD-MISENER\NEST
FILE = MISENER123_NEST_BH01_r0.DWG Warning: If you are trying to insert the
file: C:\~PROJECTS\1323-LAIRD-MISENER\NEST FILE
it must be inserted using the <block>=<filename> syntax.

Command:
Command: QWBLOCK Unknown command "QWBLOCK".  Press F1 for help.

Command: QWBLOCK Unknown command "QWBLOCK".  Press F1 for help.

Command: QWBLOCK Unknown command "QWBLOCK".  Press F1 for help.

Command:
Select Block name Text:
Pick Insertion Point:
Select objects: Specify opposite corner: 25 found

---------------------------------------------------------------------

 

Any help would be greatly appreciated.

Thanks

CD

15 REPLIES 15
Message 2 of 16
3wood
in reply to: cadiehl

You can try BLOCKOUT.vlx

http://sites.google.com/site/cadkits/home/blockout

Once you wblocked all blocks out to a certain folder, you can create printable schedules from all blocks in that folder with LISTBLOCKS.vlx

http://sites.google.com/site/cadkits/home/listblocks

Message 3 of 16
cadiehl
in reply to: 3wood

3wood,

 

I am not trying to wblock blocks, I am trying to wblock parts of the drawing. They are nested parts drawn on many 10' x 40' plates that all need to be separate cad files. I do all the plates in one cad file, then wblock each plate individually and assign a unique drawing name to each. They are not blocks. The code I have posted will do it, but it removes (deletes) each plate instead retaining them in the main cad file. If someone could fix that in the code I would be set!

 

Thanks for the advice though!

CD

Message 4 of 16
3wood
in reply to: cadiehl

I have amended your code a bit, hope it works on your computer as well:

 

(defun c:qwblock (/ DIR ENTXT SS TXT PT TXT0 oldos)
  (setq oldos (getvar "osmode"))
  (setq Dir (getvar "DWGPREFIX"))
  (command "_undo" "be")
  (vl-cmdf "ucs" "w" "")
  (while (AND (vl-file-directory-p Dir)
       (setq enTxt (car(entsel "\nSelect Block name Text: ")))
       (eq (cdr (assoc 0 (entget enTxt))) "TEXT")
       (setq txt0 (cdr (assoc 1 (entget enTxt))))
       (not (findfile (setq txt (strcat Dir txt0))))
       (setq pt (getpoint "\nPick Insertion Point: "))
       (setq ss (ssget))
       )
    (progn
      (vl-cmdf "ucs" "o" pt)    ;move 0,0,0 to new point)
      (vl-cmdf "_-wblock" txt "" pt ss "")
      (setvar "osmode" 0)
      (vl-cmdf "_-insert" (strcat TXT0 "=" txt) "scale" "" pt "")
      (vl-cmdf "ucs" "w")
      (setvar "osmode" oldos)
      )
    )
  (command "_undo" "end")
  (princ)
  )

 

Message 5 of 16
cadiehl
in reply to: cadiehl

3wood, you are AWESOME!.... this works perfectly.... this is going to be a huge time saver.... thank you, thank you, thank you.

 

CD

Message 6 of 16
cadiehl
in reply to: 3wood

3wood, I may have spoken too soon. It seems as though it works on some drawings and not on others. It still removes the selection set from the master drawing, but not on every drawing I try it on. I wonder if there is a setting that needs to be changed in autocad to prevent this?

 

Also, it is making the selection set into a block in the master drawing, which I do not want. I basically want nothing changed in the master drawing at all.

 

This is so close...

Message 7 of 16
3wood
in reply to: cadiehl

It is much easier if you don't need convert selected objects as block, please try amended codes below:

(defun c:qwblock (/ DIR ENTXT SS TXT PT TXT0)
  (setq Dir (getvar "DWGPREFIX"))
  (command "_undo" "be")
  (while (AND (vl-file-directory-p Dir)
       (setq enTxt (car(entsel "\nSelect Block name Text: ")))
       (eq (cdr (assoc 0 (entget enTxt))) "TEXT")
       (setq txt0 (cdr (assoc 1 (entget enTxt))))
       (not (findfile (setq txt (strcat Dir txt0))))
       (setq pt (getpoint "\nPick Insertion Point: "))
       (setq ss (ssget))
       )
    (progn
      (vl-cmdf "ucs" "o" pt)    ;move 0,0,0 to new point)
      (vl-cmdf "_-wblock" txt "" pt ss "")
      (command "oops")
      )
    )
  (command "_undo" "end")
  (princ)
  )

 

3wood

CAD KITS

Message 8 of 16
cadiehl
in reply to: 3wood

Not sure what you mean by "It is much easier if you don't need convert selected objects as block"

 

I don't need anything converted to a block. Just a new drawing that contains whatever I selected in the master drawing. No block generation required at all on either file.

 

This one seems to work great. Is there a way to have the newly created drawings be zoomed to extents?

 

I greatly appreciate your help on this 3wood... thank you so much.

 

CD

Message 9 of 16
3wood
in reply to: cadiehl

Please try updated codes below which create new block files with extended zoom view.

Hope it helps.

 

(defun c:qwblock (/ DIR ENTXT SS TXT PT TXT0)
  (setq Dir (getvar "DWGPREFIX"))
  (vl-cmdf "_undo" "be")
  (while (AND (vl-file-directory-p Dir)
       (setq enTxt (car(entsel "\nSelect Block name Text: ")))
       (eq (cdr (assoc 0 (entget enTxt))) "TEXT")
       (setq txt0 (cdr (assoc 1 (entget enTxt))))
       (not (findfile (setq txt (strcat Dir txt0))))
       (setq pt (getpoint "\nPick Insertion Point: "))
       (setq ss (ssget))
       )
    (progn
      (vl-cmdf "_undo" "mark")
      (vl-cmdf "_move" ss "" pt "0,0,0")
      (vl-cmdf "_zoom" "object" "p" "")
      (vl-cmdf "_-wblock" txt "" pt ss "")
      (vl-cmdf "_undo" "back")
      )
    )
  (vl-cmdf "_undo" "end")
  (princ)
  )

 

3wood

CAD KITS

Message 10 of 16
cadiehl
in reply to: 3wood

Incredible 3wood... this is going to be a big help for me. It seems to work perfectly. Thank you so much.

 

CD

Message 11 of 16
lamensterms
in reply to: 3wood

Hi 3wood,

 

Thanks so much for providing this code, it is coming in very handy.

 

One thing I have noticed (and it doesn't hugely affect the routine) is that the INSBASE point is not "0,0,0" in the newly created WBLOCK DWG.  The items are inserted correctly at "0,0,0" in the new drawing, but it seems that the INSBASE point of the new drawing is that of the WBLOCK base point from the source drawing (if you follow).  I have made a minor change to your code, I hope you don't mind.

 

(defun c:qwb (/ DIR ENTXT SS TXT PT TXT0)
(setq Dir (getvar "DWGPREFIX"))
(vl-cmdf "_undo" "be")
(while (AND (vl-file-directory-p Dir)
(setq enTxt (car(entsel "\nSelect Block name Text: ")))
(eq (cdr (assoc 0 (entget enTxt))) "TEXT")
(setq txt0 (cdr (assoc 1 (entget enTxt))))
(not (findfile (setq txt (strcat Dir txt0))))
(setq pt (getpoint "\nPick Insertion Point: "))
(setq ss (ssget))
)
(progn
(vl-cmdf "_undo" "mark")
(vl-cmdf "_move" ss "" pt "0,0,0")
(vl-cmdf "_zoom" "object" "p" "")
(vl-cmdf "_-wblock" txt "" "0,0,0" ss "")
(vl-cmdf "_undo" "back")
)
)
(vl-cmdf "_undo" "end")
(princ)
)


Message 12 of 16
rene.dewet
in reply to: 3wood

Hi 3wood,

 

I downloaded your blockout file from your site. But this is the result I received:

 

Command: BLOCKOUT
Invalid option keyword.
; error: Function cancelled
Include AutoCAD Map information in the export? [Yes/No] <Y>:

 

I'm using Civil 3D 2015, and I want to start a library with all the blocks used in different drawings, and thought this would be the perfect tool.

 

Please assist. 

René

Message 13 of 16
3wood
in reply to: rene.dewet

You need load the routine with command APPLOAD before using it.

Message 14 of 16
Vuxvix
in reply to: lamensterms

Hi!
How to Instead of "select text name" to "Enter name". Thanks

Message 15 of 16
Kent1Cooper
in reply to: Vuxvix


@Vuxvix wrote:

How to Instead of "select text name" to "Enter name". Thanks


....

(while (AND (vl-file-directory-p Dir)
;; (setq enTxt (car(entsel "\nSelect Block name Text: "))) ;; don't do this
;; (eq (cdr (assoc 0 (entget enTxt))) "TEXT") ;; don't do this
;; (setq txt0 (cdr (assoc 1 (entget enTxt)))) ;; don't do this
(setq txt0 (getstring "\nEnter name: "))
(not (findfile (setq txt (strcat Dir txt0))))

....

Kent Cooper, AIA
Message 16 of 16
Vuxvix
in reply to: cadiehl

Hi @Kent1Cooper 
This is not the first time I have received your help. Thank you very much

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost