Jump to content

Recommended Posts

Posted

Hello all! I have been trying to find a lisp routine thatwould make a specific layer based on user input. I have been reading theseforums for a long time and the community here is so great I thought I would askfor some assistance!

I would like to create a lisp routine that would ask theuser for the layer they wanted, and only create the layer specified. Where Iwork we use many different layers for different systems, and depending on whichproject we are working on, we might need some layers and not others.

I thought if we had a lisp routine that had all theproperties for every layer we use we could type in a command like"Mlayers" and it would prompt for a "layer" then typing ina small section of the layer it would create it with the correct color, line type,and line weight.

Example would be when it prompts for "layer" wecould type "Test" and it would create 001_Test_Main_ with a color of25, line type Continuous, and a line weight of .25.

Does this make sense? Is it possible? I would appreciate anyhelp I could get!

Thank you,

Posted

Welcome to CADTutor :)

 

You should be able to construct your described program using the information in this post.

Just ask if you require further assistance.

 

Lee

Posted

Dear churchryn!

 

(defun newlay(a b c d) 
(if (not (tblsearch "layer" a)) (command "-layer" "n" a "c" b a "l" c a "lw" d a "")
(command "-layer" "s" a "c" b a "l" c a "lw" d a "")))
;;; Phraseological: [b](newlay "name" color index "laytype" lineweight)[/b], few examples:
(defun C:laykt()
(newlay "KT-CENLine" 2 "CENTER2"    0.13)
(newlay "KT-ENVLine" 2 "CONTINUOUS" 0.30)
.........................................
(prompt "\nCreate layer completed\n"))

 

Good luck and have fun!

Posted

Thank you for the reply and welcome Lee!

I looked at the thread and well very informative and descriptive, it’s notquite what I am looking for.

I don’t want it to create all the layers, only a layer specified. Maybe thetutorial had that and I just didn’t understand. I am not sure if"If/Then" statements would be the best option, but I was hoping thatit would prompt for a layer needed and we could type in a specific word. Thenbased on the word that was entered the respected layer would be created.

Maybe I am wanting too much. I know I can make a lisp that will just createevery layer, or a command for each layer needed. I just wanted to reduce the amountof key strokes my guys had to do.

Example:

"Mlayer"

"Specify Layer name:"

"sample"

The lisp would create 001_Sample_Project_Test (or whatever layer that isassociated with "sample")

Using the same command we would get a different layer if we typed in "Current",it would make 002_Current_Project_

I am probably not explaining it correctly, I am fairly new to lisp routines.I apologize.

Posted

Here is an example that might help explain it better, I know this code doesnt work. But maybe it will better illustrate what I am looking for.

(defun c:mlayer (/ if then)

(if (setq name (getstring t "Specify layer name: ")))

(if name="Sample")

(then(command "_.Layer" "_Make" "001-Sample-Project-" "_Color" "140" "" "LType" "Continuous" "" ""))

(if name="Current")

(then(command "_.Layer" "_Make" "002-Current-Project-" "_Color" "4" "" "LType" "Continuous" "" ""))

(if name="Test")

(then(command "_.Layer" "_Make" "003-Test-System-" "_Color" "4" "" "LType" "Continuous" "" ""))

(princ)

)

 

These layers are not what I really would be using, and we have roughly 60~ layers that I will add to this. Please let me know if this cant be done!

Again, thank you for your time!

Posted

Try this one , and be careful the the Layer name is case-sensitive which means that Sample is not equal to sample .

 

(defun c:MkLayer (/ Layer nm)
 (defun Layer (x c)
   (entmake (list '(0 . "LAYER")
                  '(100 . "AcDbSymbolTableRecord")
                  '(100 . "AcDbLayerTableRecord")
                  (cons 2 x)
                  (cons 62 c)
                  '(6 . "Continuous")
                  '(70 . 0)
            )
   )
 )

 (if (and (/= "" (setq nm (getstring t "\n Specify layer Name :")))
          (if (not (snvalid nm))
            (princ "\n invalid Layer name <Try Again> !!")
            t
          )
          (if (not (tblsearch "LAYER" nm))
            t
            (princ "\n Layer is already existed <Try Again> !!")
          )
     )
   (cond ((eq nm "Sample") (Layer nm 140))
         ((eq nm "Current") (layer nm 4))
         ((eq nm "Test") (layer nm 4))
         (t (layer nm 256))
   )
 )
 (princ)
)

Posted

Thank you Tharwat!!!

That worked perfectly!

 

I greatly appreciate the help and quick response!

Posted
Thank you Tharwat!!!

That worked perfectly!

 

I greatly appreciate the help and quick response!

 

Excellent , You're very welcome :)

 

The link that was given and prepared by Lee is very informative and a great start for users to lean how to create and deal with Layers progarmatically .

Posted

I have it open and been reading through it and trying to practice what is listed.

 

I have also been looking at other tutorials on his page!

Lisp routines can be very helpful! But very frustrating!!!

haha, thanks again.

Posted

Lisp routines can be very helpful! But very frustrating!!!

 

Correct . :lol:

Posted

If you will be choosing from a list of predefined layers, you could choose from a list box.

eg.

 

(defun c:MKLayer (/ layers data)

 (setq layers '(("SAMPLE" "001-Sample-Project-" 140 "Continuous")
                ("CURRENT" "002-Current-Project-" 4 "Continuous")
                ("TEST" "003-Test-System-" 4 "Continuous")
               )
 )

 (cond ((not
          (setq data (cdr (assoc (car (AT:ListSelect
                                        "Select layer filter name to create layer"
                                        ""
                                        20
                                        15
                                        "false"
                                        (vl-sort (mapcar 'car layers) '<)
                                      )
                                 )
                                 layers
                          )
                     )
          )
        )
       )
       ((entmake (list '(0 . "LAYER")
                       '(100 . "AcDbSymbolTableRecord")
                       '(100 . "AcDbLayerTableRecord")
                       (cons 2 (car data))
                       (cons 62 (cadr data))
                       (cons 6 (caddr data))
                       '(70 . 0)
                 )
        )
        (princ (strcat "\nLayer: \"" (setvar 'CLAYER (car data)) "\" has been created."))
       )
       ((princ "\nLayer could not be created."))
 )
 (princ)
)


(defun AT:ListSelect (title label height width multi lst / fn fo d item f)
 ;; List Select Dialog (Temp DCL list box selection, based on provided list)
 ;; title - list box title
 ;; label - label for list box
 ;; height - height of box
 ;; width - width of box
 ;; multi - selection method ["true": multiple, "false": single]
 ;; lst - list of strings to place in list box
 ;; Alan J. Thompson, 09.23.08 / 05.17.10 (rewrite)
 (setq fo (open (setq fn (vl-filename-mktemp "" "" ".dcl")) "w"))
 (foreach x (list (strcat "list_select : dialog { label = \"" title "\"; spacer;")
                  (strcat ": list_box { label = \"" label "\";" "key = \"lst\";")
                  (strcat "allow_accept = true; height = " (vl-princ-to-string height) ";")
                  (strcat "width = " (vl-princ-to-string width) ";")
                  (strcat "multiple_select = " multi "; } spacer; ok_cancel; }")
            )
   (write-line x fo)
 )
 (close fo)
 (new_dialog "list_select" (setq d (load_dialog fn)))
 (start_list "lst")
 (mapcar (function add_list) lst)
 (end_list)
 (setq item (set_tile "lst" "0"))
 (action_tile "lst" "(setq item $value)")
 (setq f (start_dialog))
 (unload_dialog d)
 (vl-file-delete fn)
 (if (= f 1)
   ((lambda (s / i s l)
      (while (setq i (vl-string-search " " s))
        (setq l (cons (nth (atoi (substr s 1 i)) lst) l))
        (setq s (substr s (+ 2 i)))
      )
      (reverse (cons (nth (atoi s) lst) l))
    )
     item
   )
 )
)

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