Jump to content

Recommended Posts

Posted (edited)

Hi,

 

Ive not written any lisps before, been reading for about 2 weeks now, looking at code ect. Ive manged to piece together a lisp, it works as 2 halves but I cant get it to work all together.

 

I have lots of parts drawn with the same block next to it called "head" and a tag of "PCE_NAM". with different values per part.

 

I want to select a window of part & block, then wblock to a newfile with the name from the tag. then just automatically loop to do it again.

 

This is what Ive pieced together took me well over a week lol.

 

(defun c:nest ( / file sel1 LM:GetAttributeValue ss attValue name)
(setq p1 (getpoint "\nFirst Corner: "))
(setq p2 (getcorner p1 "\nSecond Corner: "))
(setq sel1 (ssget "_W" p1 p2 ))
(vl-load-com)
 (defun LM:GetAttributeValue (blk tag / val enx)
   (while
     (and
       (null val)
       (= "ATTRIB"
          (cdr (assoc 0 (setq enx (entget (setq blk (entnext blk))))))
       )
     )
      (if (= (strcase tag) (strcase (cdr (assoc 2 enx))))
        (setq val (cdr (assoc 1 enx)))
      )
   )
 )

 (if (and (setq ss (ssget "_W" p1 p2 '((0 . "INSERT") (2 . "Head") (66 . 1))))
          (setq attValue (LM:GetAttributeValue (ssname ss 0) "PCE_NAM"))
     )
   (prompt (strcat "\n[Attribute Value] : " attValue))
)
(command "FILEDIA" "0")
(COMMAND "-WBLOCK" (strcat "C:\\autocad\\" attvalue "Y" "" "0,0" sel1 ""))
(command "oops" )
(prompt "\nWBlocking complete.")
(princ)
 );defun

 

I get the first bit to work make a selection and it tells me the tag value.

I can also get the selection to wblock to a file, but I cant get it wblock with the tag value as the file name.

 

Any help and pointer in the right direction would be greatly appreciated.

P12.dwg

Ive attached an example file.

 

Thanks

Russ

Edited by SLW210
Posted

Sorry just realized I didn't wrap my code, and cant find the edit button :oops:

Posted
(defun c:nest ( / file sel1 LM:GetAttributeValue ss attValue name)
(setq p1 (getpoint "\nFirst Corner: "))
(setq p2 (getcorner p1 "\nSecond Corner: "))
(setq sel1 (ssget "_W" p1 p2 ))
(vl-load-com)
 (defun LM:GetAttributeValue (blk tag / val enx)
   (while
     (and
       (null val)
       (= "ATTRIB"
          (cdr (assoc 0 (setq enx (entget (setq blk (entnext blk))))))
       )
     )
      (if (= (strcase tag) (strcase (cdr (assoc 2 enx))))
        (setq val (cdr (assoc 1 enx)))
      )
   )
 )

 (if (and (setq ss (ssget "_W" p1 p2 '((0 . "INSERT") (2 . "Head") (66 . 1))))
          (setq attValue (LM:GetAttributeValue (ssname ss 0) "PCE_NAM"))
     )
   (prompt (strcat "\n[Attribute Value] : " attValue))
)
(command "FILEDIA" "0")
(COMMAND "-WBLOCK" (strcat "C:\\autocad\\" attvalue "Y" "" "0,0" sel1 ""))
(command "oops" )
(prompt "\nWBlocking complete.")
(princ)
 );defun

Posted

Try changing your wblock command call to this:

(command "-WBLOCK" (strcat "C:\\autocad\\" attvalue) "Y" "" '(0. 0. 0.) (ssname ss 0) "")

Posted
Thanks,

 

Now got it working.

 

Cheers

 

Glad to help :)

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...