Quattro_Trip Posted May 31, 2011 Posted May 31, 2011 Hello: Good day. Im a newbie and trying to figure out if there is a lisp that can help me out. I need to go through 200 drawings and change certain layers to a certain lineweight. Heres what i need to do: Select Layermanager search *furn* -select all- change lineweight to 0.05 search *eqpm* if *eqpm* has `mv-` as a prefix, lineweight remain as is, else change lineweight to 0.05 search *pfix* - select all- change lineweight to 0.05 etc... Thanks for your help. -Kel Quote
Lee Mac Posted May 31, 2011 Posted May 31, 2011 Hi Kel, and Welcome to CADTutor, I hope you will like it here Your best option is to use either a script to open each drawing, run a LISP program to change your layer lineweights, then save/close the drawing and move onto the next drawing; or use ObjectDBX which, although more complicated to set up, can process all the drawings without opening them (hence it could process hundreds of drawings in less than a minute). Let me know which route you wish to follow and I'll help you through it. Lee Quote
Lee Mac Posted May 31, 2011 Posted May 31, 2011 For starters, try this code on a single drawing: (defun c:LWChange ( / n ) (vlax-for l (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) (if (and (wcmatch (setq n (strcase (vla-get-name l))) "*FURN*,*EQPM*,*PFIX*") (not (wcmatch n "MV-*EQPM*")) ) (vla-put-lineweight l acLnWt005) ) ) (princ) ) (vl-load-com) (princ) Not sure how to run the code? Read this. Quote
Quattro_Trip Posted May 31, 2011 Author Posted May 31, 2011 thanks lee mac, I have been a fan and have been reading in thise forum for quite some time now, its just recent that I need help. I think Im gonna be running the Lisp routine - that would be my best bet for know. since im not familiar with ObjectDBX. although time is in the essence, I think I can go through each drawing and run the lisp command. in that way i can also see if i need to change anything as well. Thanks a lot. You guys are the best Quote
Quattro_Trip Posted May 31, 2011 Author Posted May 31, 2011 looks great. can we modify it to prompt me/ or ask for a lineweight Quote
Lee Mac Posted May 31, 2011 Posted May 31, 2011 Cool, no worries If you do decide to go the ObjectDBX route, an easy way would be to load this program in a blank new drawing, then load and run this: (defun c:DBXLWChange nil (foreach x (LM:ODBX (function (lambda ( x / n ) (vlax-for l (vla-get-layers x) (if (and (wcmatch (setq n (strcase (vla-get-name l))) "*FURN*,*EQPM*,*PFIX*") (not (wcmatch n "MV-*EQPM*")) ) (vla-put-lineweight l acLnWt005) ) ) ) ) nil t ) (princ (strcat "\n--> Drawing: " (car x) (if (vl-catch-all-error-p (cdr x)) (strcat "\n Error: " (vl-catch-all-error-message (cdr x))) "\nSuccessful." ) ) ) ) (princ) ) (vl-load-com) (princ) Lee Quote
Lee Mac Posted May 31, 2011 Posted May 31, 2011 looks great. can we modify it to prompt me/ or ask for a lineweight Sure, something like: (defun c:LWChange ( / lws lw n ) (setq lws '(-3.00 0.00 0.05 0.09 0.13 0.15 0.18 0.20 0.25 0.30 0.35 0.40 0.50 0.53 0.60 0.70 0.80 0.90 1.00 1.06 1.20 1.40 1.58 2.00 2.11 ) ) (while (and (setq lw (getreal "\nSpecify Lineweight (-3 for Default): ")) (not (member lw lws)) ) (princ "\n--> Invalid Lineweight.") ) (if lw (progn (setq lw (if (<= 0 lw) (fix (* 100 lw)) (fix lw))) (vlax-for l (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) (if (and (wcmatch (setq n (strcase (vla-get-name l))) "*FURN*,*EQPM*,*PFIX*") (not (wcmatch n "MV-*EQPM*")) ) (vla-put-lineweight l lw) ) ) ) ) (princ) ) (vl-load-com) (princ) Quote
Quattro_Trip Posted June 1, 2011 Author Posted June 1, 2011 You just made my life a little bit easier. and again, thanks. Quote
Lee Mac Posted June 1, 2011 Posted June 1, 2011 It works. thats awesome! thanks! You're welcome - just curious, which code were you referring to, the ObjectDBX one? You just made my life a little bit easier. and again, thanks. Quote
Quattro_Trip Posted June 1, 2011 Author Posted June 1, 2011 Hello again, how to add to do a search for "*BFREE*, *CLEAR*" and then freeze those layers. thanks Quote
Quattro_Trip Posted June 1, 2011 Author Posted June 1, 2011 As I said, which code are you referring to? HAHA. sorry. my bad. (defun c:LWChange ( / n ) (vlax-for l (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) (if (and (wcmatch (setq n (strcase (vla-get-name l))) "*FURN*,*EQPM*,*PFIX*") (not (wcmatch n "MV-*EQPM*")) ) (vla-put-lineweight l acLnWt005) ) ) (princ) ) (vl-load-com) (princ) thanks. Quote
Lee Mac Posted June 1, 2011 Posted June 1, 2011 Just add another IF statement within the vlax-for loop: (defun c:LWChange ( / n ) (vlax-for l (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) (if (and (wcmatch (setq n (strcase (vla-get-name l))) "*FURN*,*EQPM*,*PFIX*") (not (wcmatch n "MV-*EQPM*")) ) (vla-put-lineweight l acLnWt005) ) (if (wcmatch n "*BFREE*,*CLEAR*") (vla-put-freeze l :vlax-true) ) ) (princ) ) (vl-load-com) (princ) Quote
Quattro_Trip Posted June 1, 2011 Author Posted June 1, 2011 WONDERFUL!! Thanks alot. cheers, Kel Quote
ILoveMadoka Posted June 7, 2011 Posted June 7, 2011 Lee... A variation on this theme question... We bring drawings in from Solidworks and it assigns all sorts of lineweights to layers which really screws up our plots if we forget to manually change them all to Default. I'd like to be able to change ALL layers to Default (-3) in one step. I know that I'd have to get the layer table but I don't know how to page through them all and make that change to each. Help Please? Quote
Lee Mac Posted June 7, 2011 Posted June 7, 2011 I'd like to be able to change ALL layers to Default (-3) in one step. I know that I'd have to get the layer table but I don't know how to page through them all and make that change to each. Help Please? The above examples demonstrate how to iterate through the Layer Objects in the Layer Collection, using a vlax-for loop. Removing the IF statement, you are left with: (defun c:test1 nil (vlax-for l (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) (vla-put-lineweight l acLnWtByLwDefault) ) (princ) ) Or, if you wanted to take the Vanilla route... (defun c:test2 ( / d e ) (while (setq d (tblnext "LAYER" (null d))) (setq e (entget (tblobjname "LAYER" (cdr (assoc 2 d))))) (entmod (subst (cons 370 -3) (assoc 370 e) e)) ) (princ) ) Quote
ILoveMadoka Posted June 7, 2011 Posted June 7, 2011 Awesome!!!!!!! While Vanilla is easier on my brain, I do appreciate seeing both ways! I cannot thank you enough Lee!! Quote
Lee Mac Posted June 7, 2011 Posted June 7, 2011 You're very welcome For this particular task, I think the VL method is more concise, but the Vanilla method is likely to be faster. Lee 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.