Jump to content

Recommended Posts

Posted

I would like to be able to have this ask me if I would like to make the new layer the current layer. How do I do this?

 

(defun c:nl ( / name color )
 (while
   (or
     (not (snvalid (setq name (getstring t "\nSpecify Layer Name: "))))
     (tblsearch "LAYER" name)
   )
   (princ "\nLayer Name Invalid or Already Exists.")
 )
 (if (setq color (acad_colordlg 7 nil))
   (entmake
     (list
       (cons 0 "LAYER")
       (cons 100 "AcDbSymbolTableRecord")
       (cons 100 "AcDbLayerTableRecord")
       (cons 2 name)
       (cons 70 0)
       (cons 62 color)
     )
   )
 )
 (princ)
)

Posted
(initget 1 "Yes No")
(getkword "\nYes or no? ")

Posted
(initget "Yes No")
(getkword "\nSet newly created layer as current? [Yes/No]: ")

Posted

ok but now that its ask for that. how do i make it actually set the layer?

Posted
(initget "Yes No")
(if (eq (getkword "\nSet newly created layer as current? [Yes/No] <No>: ") "Yes")
 (setvar 'CLAYER name)
)

Posted

great thanks. what is the "EQ" used for though?

Posted
great thanks. what is the "EQ" used for though?

It's comparing to see if the result returned from getkword is equal to the "Yes" string I have at the end.

Posted

ok thanks. I understand.

 

If you guys might find this helpful. Hereis the final lisp.

I added a command in the end to be easily set the layer back to 0, if needed.

 

thanks

 

(defun c:nl ( / name color )
 (while
   (or
     (not (snvalid (setq name (getstring t "\nSpecify Layer Name: "))))
     (tblsearch "LAYER" name)
   )
   (princ "\nLayer Name Invalid or Already Exists.")
 )
 (if (setq color (acad_colordlg 7 nil))
   (entmake
     (list
       (cons 0 "LAYER")
       (cons 100 "AcDbSymbolTableRecord")
       (cons 100 "AcDbLayerTableRecord")
       (cons 2 name)
       (cons 70 0)
       (cons 62 color)
     )
   )
 )

(initget "Yes No")
(if (eq (getkword "\nSet newly created layer as current? [Yes/No] <No>: ") "Yes")
 (setvar 'CLAYER name)
)

 (princ)
)

(defun C:l0 ()
(setvar 'CLAYER "0")
(princ)
)

Posted

I use the following...

 

;MAKE A LAYER
(defun c:LM () (command "-layer" "make" ) (princ))

(defun AT:DummyLayer (name color plot / ss)
 (setq ss (ssget "_I"))
 (cond
   ((eq (strcase name) (strcat (getvar 'clayer)))
    (princ (strcat "\nLayer: \"" name "\" is the current layer."))
   )
   ((tblsearch "layer" name)
    (vl-cmdf "_.layer" "_t" name "_s" name "_p" plot name "")
    (princ (strcat "\nLayer: \"" name "\" is the current layer."))
   )
   ((vl-cmdf "_.layer" "_m" name "_c" color name "_p" plot name "")
    (princ (strcat "\nLayer: \"" name "\" has been created."))
   )
 )
 (if ss
   ((lambda (i / e)
      (while (setq e (ssname ss (setq i (1+ i))))
        (vla-put-layer (vlax-ename->vla-object e) name)
      )
      (princ (strcat "\n" (itoa (sslength ss)) " object(s) moved to layer: \"" name "\""))
    )
     -1
   )
 )
)




;"ALAN" LAYER
(defun c:ALAN (/) (AT:DummyLayer "ALAN" 2 "P") (princ))

;"TEMP" LAYER
(defun c:TEMP (/) (AT:DummyLayer "TEMP" 7 "P") (princ))

;"DEFPOINTS" LAYER
(defun c:DEF (/) (AT:DummyLayer "Defpoints" 7 "N") (princ))

;"VP" LAYER
(defun c:VP (/) (AT:DummyLayer "VP" 4 "N")(princ))

;"HIDE" LAYER
(defun c:HI (/) (AT:DummyLayer "HIDE" 210 "N")(princ))

;"0" LAYER
(defun c:L0 (/) (AT:DummyLayer "0" 7 "P")(princ))

The AT: DummyLayer is sloppy but for something simple like this, it does the trick - I also did this a long time ago. The nice thing is, if you have anything selected when you issue a command using the AT: DummyLayer sub, it will place those objects on that layer.

Posted

hmm, I really like it to be able to set the current selected object to the new layer. how could I incorporate that part from yours into what I have in mine?

Posted
hmm, I really like it to be able to set the current selected object to the new layer. how could I incorporate that part from yours into what I have in mine?

Take the selection line at the beginning and the selection set processing at the end.

Posted

cant believe its working (im new to lisp)

 

thanks alot

Posted
cant believe its working (im new to lisp)

 

thanks alot

No problem.

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