Modify Existing Layer Linetype & Lineweight

Modify Existing Layer Linetype & Lineweight

arkelec
Collaborator Collaborator
777 Views
8 Replies
Message 1 of 9

Modify Existing Layer Linetype & Lineweight

arkelec
Collaborator
Collaborator

I have to clean up around 100 existing drawings & I want to do the following:

 

  1. Convert existing Layer names to new ones.
  2. Change existing layer colours to new ones.
  3. Set all linetypes to "continuous".
  4. Set all lineweights to "default".
  5. Ensure all content on designated layers is "By Layer" for colour, linetype & lineweight.

 

I found some code (attached) to change existing Layer Name & Colour (1 & 2 in the above list), but it doesn't include the change to the linetype & lineweight.  I'm assuming the the code can be modified to do this?

 

I'm really not strong on LISP, I can't even find the correct syntax for Linetype & Lineweight (as in, the equivalent for Colour, that being < command "_LAYER" "_CO" >.

 

If someone could point me in the right direction as to where I might find the library resources to access the functions (3 & 4 in the above list), I'd be grateful.

 

There's also the solution to item 5 in the list above, but first things first.

 

Thanks in advance.

0 Likes
778 Views
8 Replies
Replies (8)
Message 2 of 9

cadffm
Consultant
Consultant

Hi,

 

 

in your case (change ALL layers

and (change ALL objects (unnested/not part of a block)

You can easily use the CHANGE or CHPROP command

similiar to use it in commandline

 

run your RNL for rename and color

and these line for all other changes

 

(command "_.-LAYER" "_lw" "_default" "*" "_ltype" "Continuous" "*" "")

make sure you are in the space you want to edit objects, like MODEL for example

(command "_.CHPROP" "_all" "" "_co" "ByLayer" "_ltype" "ByLayer" "_lw" "ByLayer" "")

 

 

Sebastian

Message 3 of 9

arkelec
Collaborator
Collaborator

Great @cadffm, thanks for that.

 

A couple of questions:

 

The '_.-LAYER' & '_lw' variables, where would I be able to read up on them & their use?  I searched the in the AutoLISP section but nothing specific is returned.

 

Also, there will be some existing layers to which I won't actually want to be affected by the linetype change.  Is it possible to apply the change only to the layers listed in the .TBL file?

0 Likes
Message 4 of 9

cadffm
Consultant
Consultant

Hi,

 

1. I don't like to comment the .lsp/.tbl file, 

   wait for some others.

 

2. You can't read about it in Lisp documentation, because all three are normal commands!

 

(Command....) is Lisp, what will send the content to your commandline,

as you can do the same by hand.

 

Type in:

-LAYER<enterhit>

[F1] 

Cheers

 

 

 

 

Sebastian

0 Likes
Message 5 of 9

paullimapa
Mentor
Mentor

How’s about AutoCADs Setbylayermode and Setbylayer command

(command "setbylayer" "all" "" "y" "y")

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 9

jreidKVSUZ
Advocate
Advocate

You can give this a try.

 

It will change your layers names to your table, set all Colors to Bylayer and set one of them to color 3 per your table and change all Linetypes to Bylayer.

 

Just load and type RNL as you had before.

 

Hope this works for you.

Thanks, JRR!

0 Likes
Message 7 of 9

arkelec
Collaborator
Collaborator

Thanks @cadffm.  I get the -LAYER structure now.

 

@paullimapa - I think I understand what that does, buy I'm not sure how it does what it does & how that fits my goal (given my post after yours & this one).

 

@jreidKVSUZ - Thanks, I tried it but it didn't work.

 

If I've understood the original code properly (shown below), Line 17 sets up the reading of the list (the external file), the 'car', 'cadr' & 'caddr' locate the 1st, 2nd & 3rd elements of the list.

 

Ideally, I'd like to add a 4th & 5th element, being Linetype & Lineweight, and then add the necessary lines of code to effect the change, using the 'nth' function.

 

What I don't know is if I could/should retain the 'cad, cadr, caddr' functions & add the 'nth' in, or restructure that whole part just using 'nth'.

Nor do I know how to access the Linetype & Lineweight elements.  

 

I'm going to have a stab at modifying the code to try the above, using the info @cadffm gave in his posts, but formatting it in a similar structure to the original code.

 

;Renames layers according to RNL.TBL
;
;(^v^) CAD Studio, 1998
;updated 6-98: optional new colors
;
(defun C:RNL ( / cmde tbf tbl lin lis)
 (setq cmde (getvar "CMDECHO"))
 (setvar "CMDECHO" 0)
 (setq tbf (findfile "RNL.TBL"))
 (if tbf
  (progn
   (princ "Renaming from table RNL.TBL ...")
   (setq tbl (open tbf "r"))
   (while (setq lin (read-line tbl))
    (if (/= ";" (substr lin 1 1))
     (progn
      (setq lis (read (strcat "(" lin ")"))) ; (OLD NEW) or (OLD NEW NEWCOLOR)
      (if (tblsearch "LAYER" (car lis))
       (if (tblsearch "LAYER" (cadr lis))
        (princ (strcat "\nCannot rename " (car lis) " to " (cadr lis) " - already exists"))
        (progn
         (princ (strcat "\n" (car lis) "->" (cadr lis)))
         (command "_RENAME" "_LA" (car lis) (cadr lis))
         (if (caddr lis) (command "_LAYER" "_CO" (caddr lis) (cadr lis) ""))
        )
       );if
     );if
    ));if
   );while
   (princ "\nDone.")
  );else
  (prompt "Table RNL.TBL not found!")
 );if
 (setvar "CMDECHO" cmde)
 (princ)
)

(princ "\nRNL - tabular layer renaming,  (^v^) CAD Studio, http://www.cadstudio.cz")
(princ)

 

 

 

0 Likes
Message 8 of 9

arkelec
Collaborator
Collaborator

OK, some success with the following:

;Renames layers according to RLN.TBL
;
;(^v^) CAD Studio, 1998
;updated 6-98: optional new colors
;
(defun C:RNL ( / cmde tbf tbl lin lis)
 (setq cmde (getvar "CMDECHO"))
 (setvar "CMDECHO" 0)
 (setq tbf (findfile "RNL.TBL"))
 (if tbf	;1
  (progn
   (princ "Renaming from table RNL.TBL ...")
   (setq tbl (open tbf "r"))
   (while (setq lin (read-line tbl))
    (if (/= ";" (substr lin 1 1))	;2
     (progn
      (setq lis (read (strcat "(" lin ")"))) ; (OLD NEW) or (OLD NEW NEWCOLOR)
      (if (tblsearch "LAYER" (nth 0 lis))	;3
       (if (tblsearch "LAYER" (nth 1 lis))	;4
        (princ (strcat "\nCannot rename " (nth 0 lis) " to " (nth 1 lis) " - already exists"))
        (progn
         (princ (strcat "\n" (nth 0 lis) "->" (nth 1 lis)))
         (command "_RENAME" "_LA" (nth 0 lis) (nth 1 lis))
         (if (nth 2 lis) (command "_LAYER" "_CO" (nth 2 lis) (nth 1 lis) ""))		;5
		  (if (nth 3 lis) (command "_LAYER" "_ltype" (nth 3 lis) (nth 1 lis) ""))	;6
		   (if (nth 4 lis) (command "_LAYER" "_lw" (nth 4 lis) (nth 1 lis) ""))		;7
		  );if7
		 );if6
		);if5
       );if4
     );if3
    ));if2
   );while
   (princ "\nDone.")
  );else
  (prompt "Table RNL.TBL not found!")
 );if1
 (setvar "CMDECHO" cmde)
 (princ)
)

 

This actually works, however there is a bad argument error on line 18 (screen grab below):

 

RNLT Bad Argument Error.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Having searched on this sort of error, there a suggestion that I should be using 'cond' instead of 'if'.

 

Any comments gratefully received.

 

 

0 Likes
Message 9 of 9

Sea-Haven
Mentor
Mentor

This is just the way I would start to approach this task. you can look at the length of each sub item in the laylst is it 1 2 3 4 etc so then with a cond call the correct change layer. One thing I did do to make life easier is removed the quotes as accept that the text is all strings, I would use a comma as Seperator then can change layer names that have a space in them.

 

(defun c:chklay ( / lay lst laylst dummy lin)

(defun dolay2 ( / )
 (if (tblsearch "LAYER" (nth 0 lay))
  (command "-layer" "rename" (nth 0 lay) (nth 1 lay))
 )
)
(defun dolay3 ( / )
 (if (tblsearch "LAYER" (nth 0 lay))
  (command "-layer" "rename" (nth 0 lay) (nth 1 lay) "c" (atoi (nth 2 lay)) (nth 1 lay)  "")
 )
)
(defun dolay4 ( / )
 (if (tblsearch "LAYER" (nth 0 lay))
  (command "-layer" "rename" (nth 0 lay) (nth 1 lay) "c" (atoi (nth 2 lay)) (nth 1 lay) "LT" (nth 3 lnr) (nth 1 lay) "")
 )
)

; tab 9 space 32 (chr 32) comma 44 semicolum 59 slash / 47
; thanks to Lee-mac for this defun
(defun csv->lst ( str / pos )
(if (setq pos (vl-string-position 32 str))
    (cons (substr str 1 pos) (csv->lst (substr str (+ pos 2))))
    (list str)
    )
)

(setq laylst '())
(setq tbl (open tbf "r"))
(setq dummy (read-line tbl))
(setq dummy (read-line tbl))
(while (setq lin (read-line tbl))
  (setq lst (csv->lst lin))
  (setq laylst (cons lst laylst))
)
(close tbl)


(foreach lay laylst
(cond
  ((= (length lay) 2)(dolay2))
  ((= (length lay) 3)(dolay3))
  ((= (length lay) 4)(dolay4))
)
)

(princ)
) ; chklay
;List of renamed layers for RNL.LSP
;format: ORIGINALNAME NEWNAME newcolor
YYY BBB
CCC DDD
AAA XXX 3
EEE FFF 4 DASHED
0 Likes