Jump to content

Recommended Posts

Posted

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

 

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.

Posted

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

Posted

Also when you are setting variables i would use (setvar "variablename" variable)

Posted

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

 

:)

  • Like 1
Posted

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!

Posted

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.

Posted
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

Posted

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.

Posted

No problem - If you do have anything else that is confusing, just shout :)

Posted
No problem - If you do have anything else that is confusing, just shout :)

 

Absolutely anytime you need 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...