bapatri Posted January 21, 2015 Share Posted January 21, 2015 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 Quote Link to comment Share on other sites More sharing options...
bapatri Posted January 21, 2015 Author Share Posted January 21, 2015 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. Quote Link to comment Share on other sites More sharing options...
BlackBox Posted January 21, 2015 Share Posted January 21, 2015 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. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 21, 2015 Share Posted January 21, 2015 To check if the New Layer Name is valid , is one of the important issues in this regard . Quote Link to comment Share on other sites More sharing options...
BlackBox Posted January 21, 2015 Share Posted January 21, 2015 To check if the New Layer Name is valid , is one of the important issues in this regard . You haven't tested the code, have you? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted January 21, 2015 Share Posted January 21, 2015 You haven't tested the code, have you? Sorry , I was paying attention to the OP to put that in consideration Quote Link to comment Share on other sites More sharing options...
bapatri Posted January 21, 2015 Author Share Posted January 21, 2015 Perfect, Thank you Quote Link to comment Share on other sites More sharing options...
BlackBox Posted January 21, 2015 Share Posted January 21, 2015 Sorry , I was paying attention to the OP to put that in consideration 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 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted January 22, 2015 Share Posted January 22, 2015 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) Quote Link to comment Share on other sites More sharing options...
fuccaro Posted January 22, 2015 Share Posted January 22, 2015 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 Quote Link to comment Share on other sites More sharing options...
SLW210 Posted January 22, 2015 Share Posted January 22, 2015 Please read the Code Posting Guidelines and edit your posts to include the Code in Code Tags. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.