Jump to content

Recommended Posts

Posted

I need some help with a lisp routine to make wblocks of my library.

I have a single drawing (master drawing) that contains entities for 5000 "would be" blocks. The entities are ready to be wblocked out but, since I go through several steps to create each one, I thought a lisp routine could help speed up the process. First, each of the "would be" blocks has a piece of text below it indicating what the actual block file name should be. This piece of text is not included in the wblock itself - it's just a label to ensure the correct file name. To wblock out manually, I normally select the text with ddedit and do a ctrl+c and then ctrl+v when prompted for the file name. Basically I would like to have the lisp routine do all of the following steps.

 

Prompt for a center point - to be used as insertion point for the wblock and also sets ucs origin to same point so individual wblock is located at 0,0,0 in the new file.

 

I used this code to get insertion point for each wblock:

(command "UCS" "O" "center" (setq insertpt (getpoint "\nSet 0,0,0 origin and Insert Point for Block")))

 

Get the value of the text below entities (for wblock filename)

 

-Wblock to d:\blocks\"value from text string"

(the path itself can be hard-coded or... even better would be to prompt for "folder location" at the beginning of the routine)

 

Select entities to wblock (window)

if file name exists, prompt to overwrite or enter new file name

 

Insert the newly created block back in to the "master drawing" at current 0,0,0 (same point)

 

Repeat - Prompt for next wblock insertion point...

 

*********

 

Any help would be greatly appreciated!!

Posted

Thanks for the reply.

That is a handy routine to have but it doesn't do what I need. Exportblocks.lsp is looking for existing blocks within my master drawing. I don't have any blocks in the drawing... I just have the raw entities ready to be wblocked out.

Posted

Sorry I didn't read it properly. How's this?

(defun c:qwblock (/ ENTXT SS TXT PT)
 (if (AND (setq enTxt (car(entsel "\nSelect Block name Text: ")))
      (eq (cdr (assoc 0 (entget enTxt))) "TEXT")
      (setq txt (cdr (assoc 1 (entget enTxt))))
      (not (findfile txt))
      (setq pt (getpoint "\nPick Insertion Point: "))
      (setq ss (ssget))
      )
   (progn
      (vl-cmdf "_-wblock" txt "" pt ss "")
      (vl-cmdf "_-insert" txt "0,0" "" "" "")
     )
   )
 (princ)
 )

Note, if the block already exists it won't continue (do you always want to replace a block if it exists?)

Posted

It works great! A heck of a lot better than the crude code I came up with. Is there a way to set the UCS origin to the same point as "pt" before it does the wblock command? I tried to use

 

(setvar "ucsorg" pt)

but it said "variable setting rejected".

I also tried this:

(command "ucs" "o"(setq pt (getpoint "\nPick Insertion Point: ")))

That one does set the new origin to the same point but the routine stops immediately after.

 

Also, the wblocks are being saved to the "my document" folder. Is there a way for me to select where the wblocks should be saved?... If not, I can live with just moving them after I'm finished.

 

I don't necessarily want to overwrite a block if it exists. It would be nice to be prompted, in case I've duplicated "block name text".

 

Finally, is there a way to loop or keep the routine running so I can wblock continuously?

 

This is great! I thank you SOOOO much for your help.

Posted

are you meaing this

 

(vl-cmdf "_-insert" txt pt "" "" "")

Posted

I need the ucs origin to be moved to the same point picked as the insert point for each wblock (pt). This way, in each new file being created, the object's insert point will actually reside at 0,0,0.

Posted

I would say Seth (flowerrobot) is right, though maybe I'm not following...

 

I just changed the if to a while so it would keep looping for you.

 

I've also added a folder variable Dir you can change that will be the path to save the block in.

(defun c:qwblock (/ DIR ENTXT SS TXT PT)
 (setq Dir "X:/")
 (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 "_-wblock" txt "" pt ss "")
     (vl-cmdf "_-insert" txt pt "" "" "")
     )
   )
 (princ)
 )

Alternatively, if you want the directory as the same folder as the drawing use:

(setq Dir (getvar "DWGPREFIX"))

How'd it go?

Posted

You are awesome! And thank you to Seth too.

That does exactly what I was looking for. I did add the following just after the (progn

(vl-cmdf "ucs" "o" pt)    ;move 0,0,0 to new point 

You just made my week!!

Posted

Ah good work. Btw you can remove the progn and associated parentheses, it's not needed for while loops.

Glad it's made your week :)

Posted
I would say Seth (flowerrobot)

 

Mate how did you find my name?, I have posted it once is some code. :D

Posted
Mate how did you find my name?, I have posted it once is some code. :D

Hehe, your lazy man's system variables thread on the swamp. Sorry if it was meant to be a secret, it's also in your email address :)

Posted

ahh sneaky sneaky, Nah mate not a secret just flagged me as some people i know in the flesh dont even know me by my real name.. Must say you are very abservant

  • 6 months later...
Posted

Is there any way to modify this code to simply create the new drawing and have the insertion point I pick in the master drawing go to 0,0,0 in the new file? I do not want anything created in the master file, no blocks, nothing. Right now it is actually removing what I pick in the master file, and not retaining it. This is an awesome tool if I could get it to work properly. This could be a great time saver.

 

Thanks in advance!

CD

Posted
Is there any way to modify this code to simply create the new drawing and have the insertion point I pick in the master drawing go to 0,0,0 in the new file? I do not want anything created in the master file, no blocks, nothing. Right now it is actually removing what I pick in the master file, and not retaining it. This is an awesome tool if I could get it to work properly. This could be a great time saver.

 

Thanks in advance!

CD

 

Sorry I'm not entirely sure what you're after. The insertion point you pick in the master drawing will already be 0,0 in the new file.

If you don't want the newly created block put back into the master file then you can just remove one line (highlighted below):

(defun c:qwblock (/ DIR ENTXT SS TXT PT)
 (setq Dir "X:/")
 (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 "_-wblock" txt "" pt ss "")
     [color=Red];;(vl-cmdf "_-insert" txt pt "" "" "")[/color]
     )
   )
 (princ)
 )

Posted

Thanks Steve.... will doing that retain the selection set in the master cad file? Right now it disappears.... as if I am picking "delete from drawing" in the 'wblock' dialog box.

Posted

Steve, this is the code I am using... it works perfectly, except the selection sets I choose in the master cad file disappear after each new cad file is created.

 

(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))

 

(vl-cmdf "ucs" "o" pt) ;move 0,0,0 to new point)

(vl-cmdf "_-wblock" txt "" pt ss "")

)

)

(princ)

)

Posted

Hi,

 

All this code is doing is getting some user input then running the wblock command, and that command removes the entities once they are made into a block (so the selection set is removed). The previous line that I highlighted to remove then inserts that block back into the master model - I thought you didn't want that. Perhaps you want to keep the entities in the master file but not as a block, in which case I can only think to insert the block again and then explode it. Not sure what else you could try..

 

steve

Posted

Steve, below is the code that does exactly what I want.

 

(defun c:qw (/ 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)

)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...