russ079 Posted January 30, 2018 Posted January 30, 2018 (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 February 1, 2018 by SLW210 Quote
russ079 Posted January 30, 2018 Author Posted January 30, 2018 Sorry just realized I didn't wrap my code, and cant find the edit button Quote
russ079 Posted January 30, 2018 Author Posted January 30, 2018 (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 Quote
ronjonp Posted January 30, 2018 Posted January 30, 2018 Try changing your wblock command call to this: (command "-WBLOCK" (strcat "C:\\autocad\\" attvalue) "Y" "" '(0. 0. 0.) (ssname ss 0) "") Quote
russ079 Posted February 1, 2018 Author Posted February 1, 2018 Thanks, Now got it working. Cheers Quote
ronjonp Posted February 1, 2018 Posted February 1, 2018 Thanks, Now got it working. Cheers Glad to help Quote
Recommended Posts
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.