mostafa badran Posted April 16, 2014 Posted April 16, 2014 Hi all,can anyone clarify what's the problem in this code and how can I fix it. (setq lnam (getstring"\nEnter lay name:")) (if ( = lnam t) (setvar "clayer" lnam)) (if ( = lnam nil) (setvar "clayer" "0")) Quote
MSasu Posted April 16, 2014 Posted April 16, 2014 The lnam variable is expected to hold a string, so cannot compare it with T; may help also to validate existance of layer inputted by user: (if (and (setq lnam (getstring"\nEnter lay name:")) (tblsearch "LAYER" lnam)) (setvar "CLAYER" lnam) (setvar "CLAYER" "0") ) Quote
Lee Mac Posted April 16, 2014 Posted April 16, 2014 Since getstring will return an empty string on the user pressing enter, you can use: (if (tblsearch "layer" (setq l (getstring t "\nLayer name: "))) (setvar 'clayer l) (setvar 'clayer "0") ) Quote
mostafa badran Posted April 17, 2014 Author Posted April 17, 2014 The lnam variable is expected to hold a string, so cannot compare it with T; may help also to validate existance of layer inputted by user: (if (and (setq lnam (getstring"\nEnter lay name:")) (tblsearch "LAYER" lnam)) (setvar "CLAYER" lnam) (setvar "CLAYER" "0") ) Since getstring will return an empty string on the user pressing enter, you can use: (if (tblsearch "layer" (setq l (getstring t "\nLayer name: "))) (setvar 'clayer l) (setvar 'clayer "0") ) Thanks guys for respond, it work fine . I need another thing I want to create layer with entmake and add it to the previous code I am try but it dos not work it create layer but not but it current layer how can i fix this. thanks for help . try this (defun c:test (/) (if (and (setq lnam (getstring"\nEnter lay name:")) (tblsearch "LAYER" lnam)) (setvar "CLAYER" lnam) (setvar "CLAYER" "0") ) (entmake (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 lnam) '(70 . 0) '(62 . 2) '(6 . "Continuous"))) ) or this (defun c:test (/) (if (tblsearch "layer" (setq l (getstring t "\nLayer name: "))) (setvar 'clayer l) (setvar 'clayer "0") ) (entmake (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 lnam) '(70 . 0) '(62 . 2) '(6 . "Continuous"))) ) Quote
MSasu Posted April 17, 2014 Posted April 17, 2014 (edited) Like this? (if (not (tblsearch "layer" (setq lnam (getstring t "\nLayer name: ")))) (if (entmake (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 lnam) '(70 . 0) '(62 . 2) '(6 . "Continuous"))) (setvar "CLAYER" lnam) (setvar "CLAYER" "0") ) ) Edited April 17, 2014 by MSasu Fixed code Quote
MSasu Posted April 17, 2014 Posted April 17, 2014 Please pay attention that you need to close only DEFUN statement, IF was aleady closed. Quote
mostafa badran Posted April 17, 2014 Author Posted April 17, 2014 Please pay attention that you need to close only DEFUN statement, IF was aleady closed. I am sorry I think is there something wrong It does not work with me . Quote
MSasu Posted April 17, 2014 Posted April 17, 2014 (edited) Hope this will help you understand the issue: (defun c:test( / lnam ) (if (not (tblsearch "layer" (setq lnam (getstring t "\nLayer name: ")))) (if (entmake (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 lnam) '(70 . 0) '(62 . 2) '(6 . "Continuous"))) (setvar "CLAYER" lnam) (setvar "CLAYER" "0") ) ) (princ) ) Edited April 17, 2014 by MSasu Fixed code Quote
mostafa badran Posted April 17, 2014 Author Posted April 17, 2014 Hope this will help you understand the issue: (defun c:test( / lnam ) (if (not (tblsearch "layer" (setq lnam (getstring t "\nLayer name: ")))) (if (entmake (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 lnam) '(70 . 0) '(62 . 2) '(6 . "Continuous")) (setvar "CLAYER" lnam) (setvar "CLAYER" "0") ) ) (princ) ) I am really appreciate your effort. Did you test it ? not work again !! Quote
MSasu Posted April 17, 2014 Posted April 17, 2014 I edited the code here, so missed a parenthesis; I have fixed it now. Please try it again. Sorry for inconvenience! Quote
mostafa badran Posted April 17, 2014 Author Posted April 17, 2014 I edited the code here, so missed a parenthesis; I have fixed it now. Please try it again. Sorry for inconvenience! Thank man Its work now. Quote
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.