DVDM Posted July 15, 2009 Posted July 15, 2009 Hello all, I have a situation where a lot of our older drawings have layers with incorrect linetypes. These layers have linetypes 'CENTER', 'HIDDEN' & 'PHANTOM', whereas they should all be 'CENTER2', 'HIDDEN2' & 'PHANTOM2' from acadiso.lin. The layer names could be anything, so I can't use those for assigning correct linetypes. Is there a way to simply changes all layers with linetype 'HIDDEN' to linetype 'HIDDEN2', etc? Also, some of these older drawings have had the linetype scale of individual lines changed to something other than 1. How can I set all lines in the entire drawing to ltscale 1 in one go? I can use quick select to get all objects with linetypescale unequal to 1, but I can't use quick select in a lisp routine. While I can do both things manually with a few simple steps, I have ten people here who find that difficult, confusing, too complex, and too much effort, so I want to give them a simple button to press So far I have a routine that sets all variables that influence the appearance of linetypes, but I'd like to take it one step further if possible: (command "ltscale" "1") (command "psltscale" "1") (command "msltscale" "1") (command "measurement" "1") (foreach lt '("CENTER2" "HIDDEN2" "PHANTOM2")(if(not(tblsearch "ltype"lt))(command "_.-linetype" "_l" lt "acadiso.lin" ""))) ;Loads linetypes if they aren't loaded yet. (foreach lt '("CENTER2" "HIDDEN2" "PHANTOM2")(if(=(tblsearch "ltype"lt))(command "_.-linetype" "_l" lt "acadiso.lin" "y" ""))) ;Re-loads linetypes if they have been loaded. (foreach lay (layoutlist) (setvar "CTAB" lay)(command "psltscale" "1") (command "regenall")) ;Cycles through all layouts to set psltscale. Quote
Commandobill Posted July 15, 2009 Posted July 15, 2009 you can add this bit of code to your code (defun c:lty ( / laylst lay lt ss) (setq laylst (list (tblobjname "LAYER" (cdr (assoc 2 (tblnext "LAYER" T)))))) (while (setq lay (tblnext "LAYER")) (setq laylst (append (list (tblobjname "LAYER" (cdr (assoc 2 lay))))laylst))) (mapcar '(lambda (z) (if (or (= (setq lt (vla-get-linetype z)) "HIDDEN") (= lt "PHANTOM") (= lt "CENTER")) (vla-put-linetype z (strcat lt "2")))) (mapcar 'vlax-ename->vla-object laylst)) (if (setq ss (ssget "X" (list (cons -4 "<not") (cons 48 1.0) (cons -4 "not>") (cons 0 "*line")))) (mapcar '(lambda (z) (vla-put-linetypescale z 1)) (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex ss)))) ) ) Quote
Commandobill Posted July 15, 2009 Posted July 15, 2009 Also when you are setting variables i would use (setvar "variablename" variable) Quote
Lee Mac Posted July 15, 2009 Posted July 15, 2009 Exactly, you could replace: (command "ltscale" "1") (command "psltscale" "1") (command "msltscale" "1") (command "measurement" "1") With either: (mapcar 'setvar '("LTSCALE" "PSLTSCALE" "MSLTSCALE" "MEASUREMENT") '(1 1 1 1)) or (mapcar '(lambda (x) (setvar x 1)) '("LTSCALE" "PSLTSCALE" "MSLTSCALE" "MEASUREMENT")) 1 Quote
DVDM Posted July 16, 2009 Author Posted July 16, 2009 Thanks guys, As you can probably tell, when I make my own code I'm very commandline-centric (The first 4 lines i wrote myself, the rest is a cut-n-paste) It does make a lot of sense setting those variables using setvar, and I went through my routines and changed it everywhere. Commandobill, thanks for that routine, it works great! I added it to my routine, ran it to fix up a drawing... still some lines weren't showing up correctly. What's going on? Turns out these lines had their linetype changed individually to 'center' as well! I wouldn't know how to modify your routine to include this as well, but I googled for a fix, and came across a litte (commandline) routine that could fix it: (command "change" "all" "" "p" "LT" "bylayer" "LW" "bylayer" "") It works as long as I tell my routine to switch to modelspace first, and I could have included ltscale in that as well I guess, but I take it your routine would be quicker because it only changes objects that need changing, instead of every single object in modelspace? Lee Mac, I can follow your first example, and after reading help I now understand what that lambda thing does in your second example. But one thing that's still a bit mysterious to me, is what the apostrophy before 'setvar etc. does? (mapcar 'setvar '("LTSCALE" "PSLTSCALE" "MSLTSCALE" "MEASUREMENT") '(1 1 1 1)) Anyway, armed with this I do have my one-click solution for this very annoying reoccuring problem. Thanks! Quote
Lee Mac Posted July 16, 2009 Posted July 16, 2009 The apostrophe before setvar tells the interpreter (the thing that converts the code into machine talk), not to evaluate setvar as a function but rather as an argument for mapcar. Quote
Commandobill Posted July 16, 2009 Posted July 16, 2009 The apostrophe before setvar tells the interpreter (the thing that converts the code into machine talk), not to evaluate setvar as a function but rather as an argument for mapcar. Thats true. On top of that the apostrophe in front of the ("LTSCALE" "PSLTSCALE" "MSLTSCALE" "MEASUREMENT") and the (1 1 1 1) is so that vlisp recognizes them as lists. so you could also write it like this (mapcar (function setvar) (list "LTSCALE" "PSLTSCALE" "MSLTSCALE" "MEASUREMENT") (list 1 1 1 1)) hope this helps Quote
DVDM Posted July 17, 2009 Author Posted July 17, 2009 That definately helps. When it comes to lisp I'm a notorious cut 'n paster of other peoples work, but I do like to get a grasp of what exactly it is that's going on in these routines. I'm slowly learning more and more this way. Thanks guys. Quote
Lee Mac Posted July 17, 2009 Posted July 17, 2009 No problem - If you do have anything else that is confusing, just shout Quote
Commandobill Posted July 17, 2009 Posted July 17, 2009 No problem - If you do have anything else that is confusing, just shout Absolutely anytime you need 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.