Jump to content

Create New Current Layer


bapatri

Recommended Posts

 

I found this lisp from (http://autolispgs.blogspot.com/2013/02/create-new-layer.html), and I would like the new created layer to become the current layer.

 

Ty

 

(defun c:Newlayer (/ Layername Color)

;;Author:Ganesh Shetty, Copyright © 2013 -http://autolispgs.blogspot.in

(setq Layername(getstring "\nEnter New Layer Name:"))

(if (not (Tblsearch "LAYER" Layername))

(progn

(setq color(getint "\nEnter Color Type for New Layer:"))

(command "_Layer" "New" layername "c" color layername "")

(princ(strcat "\nLayer \"" layername "\"Created ."))

)

(princ "\nLayer Name Already exist.")

)

(princ)

);end defun

Link to comment
Share on other sites

 

I found this lisp on autolispgs.blogspot.com, and was wondering is anyone could add to it. I want the new layer created to become the current layer.

 

(defun c:Newlayer (/ Layername Color)

;;Author:Ganesh Shetty, Copyright © 2013 -http://autolispgs.blogspot.in

(setq Layername(getstring "\nEnter New Layer Name:"))

(if (not (Tblsearch "LAYER" Layername))

(progn

(setq color(getint "\nEnter Color Type for New Layer:"))

(command "_Layer" "New" layername "c" color layername "")

(princ(strcat "\nLayer \"" layername "\"Created ."))

)

(princ "\nLayer Name Already exist.")

)

(princ)

);end defun

 

Ty.

Link to comment
Share on other sites

Welcome to CADTutor.

 

Perhaps this will work for you?

 

(defun c:NewLayer () (command "._-layer" "_m" pause "_c" pause "" "") (princ))

 

 

 

Cheers

 

 

 

P.S. - Please use [ CODE ] Tags. :thumbsup:

Link to comment
Share on other sites

Sorry , I was paying attention to the OP to put that in consideration :o

 

The -LAYER Command's Make (_m) keyword utilizes the LayerTable Object's Add() Method (aka vla-Add), which will either get, or create the corresponding LayerTableRecord, given the supplied name parameter as string provided.

 

So as a quick example, this:

 

(defun _GetOrCreateLayer (doc layerName)
 (vlax-invoke
   (vla-get-layers doc)
   (if (tblsearch "layer" layerName)
     'item
     'add
   )
   layerName
 )
)

 

 

... Can be replaced with:

 

(defun _GetOrCreateLayer2 (doc layerName)
 (vla-add (vla-get-layers doc) layerName)
)

 

 

... Which is not only more concise, it's also more efficient in terms of performance.

 

 

 

Perfect, Thank you

 

You're welcome, bapatri; I'm happy to help.

 

Cheers

Link to comment
Share on other sites

Set current

 

(command "_Layer" "New" layername "c" color layername "")
new 
(command "_Layer" "New" layername "c" color layername "S" layername "")
or 
command "_Layer" "New" layername "c" color layername "")(setvar "clayer" layername)

Link to comment
Share on other sites

Try this:

(defun c:Newlayer (/ Layername Color)
;;Author:Ganesh Shetty, Copyright © 2013 -http://autolispgs.blogspot.in
;  -a small modification: If a new layer is created, it will become the current one
;  -Fuccaro M.  2015-01-22
(setq Layername(getstring "\nEnter New Layer Name:"))
(if (not (Tblsearch "LAYER" Layername))
(progn
(setq color(getint "\nEnter Color Type for New Layer:"))
(command "_Layer" "Make" layername "c" color layername "")
(princ(strcat "\nLayer \"" layername "\"Created ."))
)
(princ "\nLayer Name Already exist.")
)
(princ)
);end defun 

+

 

I see you have already get answers to your request, I will merge the two threads

Link to comment
Share on other sites

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