Adding Prefix and Suffix options for newly created Layer names

Adding Prefix and Suffix options for newly created Layer names

Anonymous
Not applicable
776 Views
1 Reply
Message 1 of 2

Adding Prefix and Suffix options for newly created Layer names

Anonymous
Not applicable

Dear Experts,

 

I got a code from this forum only, which can create layers for selected polylines.

 

The requirement is to ask the user for Prefix and Suffix names for newly created layers at command prompt.

 

Thanks a lot in advance.

 

(Defun c:CPL ( / checkName made _reMade _newLay ss i ent lay clay p f)
(defun checkName  (s n)
      (while (tblsearch
                        "Layer"
                        (Setq ln (Strcat s "_" (itoa n))))
            (Setq n (1+ n)))
      (list ln n)
      )
      
(defun _reMade (cly / f)
      (if (setq f (assoc cly made))
          (progn
           	(setq gn (checkName cly (1+ (Cadr f)))
                      made (subst (list cly (Cadr gn)) f made))
                (car gn)
          		)
                      )
      )
(defun _newLay (cly n / gn)
      (setq gn (checkName cly n))
      (setq made (cons (list cly (cadr gn)) made))
      (Car gn)
      )
      
      
(if (setq ss (ssget "_:L" '((0 . "LWPOLYLINE"))));<-- this could be filtered for exclusion of ---
  	(repeat (Setq i (sslength ss))
  		(setq ent (entget (ssname ss (Setq i (1- i)))))
              	(Setq lay (entget (tblobjname  "LAYER"
                                        (setq clay (Cdr (Assoc 8 ent))))))
              	(Setq nlay 
              		(cond
                      		((and
                                       (wcmatch clay "*_#*")
                                       (Setq p (vl-string-position  95 clay))
                                       (numberp  (setq n (read (substr clay (+ 2 p)))))
                                       )
                                        (if (setq f (_reMade (substr clay 1 p))) f
                                            (_newLay (substr clay 1 p) n)
                                            )
                                 	)
                                ( (setq f (_reMade clay))	)
                              	( (_newLay clay 1) 		)
                              )
                      )                      	
              	(entmake (append
				(list (cons 0 "LAYER")
		                 	(cons 100 "AcDbSymbolTableRecord")
		                 	(cons 100 "AcDbLayerTableRecord")
		                 	(cons 2 nlay)
                                      )
                                      (mapcar '(lambda (d)(assoc d lay)) '(70 62 6 290 370))))
              	(entmod (subst (cons 8 nlay) (assoc 8 ent) ent))
              )
	)
    	
      (princ)
      )

 

0 Likes
777 Views
1 Reply
Reply (1)
Message 2 of 2

pbejse
Mentor
Mentor

@Anonymous wrote:

I got a code from this forum only, which can create layers for selected polylines.

The requirement is to ask the user for Prefix and Suffix names for newly created layers at command prompt.


 

That code looks very familiar. 

Are you sure you understand what the reference code is for and what it does? Are you aware that its creating a unique layer name per object? 

 

Show us what you need, describe what exactly what layers will look like. 

0 Likes