tgibbo Posted March 15, 2015 Share Posted March 15, 2015 Hi Can somebody help me this Lisp file. It almost works and can I have the 2 functions in the one file? ("Center" & "Phantom") ;Create Center line; (defun C:tozacentre () (tozacentre) ) (setq oldlay (getvar "clayer")) (setvar "clayer" "Centre") (command "_line") (while (= (getvar "cmdactive") 1 ) (command pause) ) (setvar "clayer" oldlay) ;Create Pahntom line; (defun C:tozaphantom () (tozaphantom) ) (setq oldlay (getvar "clayer")) (setvar "clayer" "Phantom") (command "_line") (while (= (getvar "cmdactive") 1 ) (command pause) ) (setvar "clayer" oldlay) Quote Link to comment Share on other sites More sharing options...
tombu Posted March 15, 2015 Share Posted March 15, 2015 Try: ;Create Center line; (defun C:tozacentre (/ oldlay) (setq oldlay (getvar "clayer")) (setvar "clayer" "Centre") (command "_line") (while (= (getvar "cmdactive") 1 ) (command pause)) (setvar "clayer" oldlay) ) ;Create Pahntom line; (defun C:tozaphantom (/ oldlay) (setq oldlay (getvar "clayer")) (setvar "clayer" "Phantom") (command "_line") (while (= (getvar "cmdactive") 1 ) (command pause)) (setvar "clayer" oldlay) ) Quote Link to comment Share on other sites More sharing options...
tgibbo Posted March 15, 2015 Author Share Posted March 15, 2015 Hi Tombu Thanks for that I have it working now and would like to ask you if you can help again ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;Create Centre line;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun C:tozacentre (/ oldlay) (/ oldline) (setq oldlay (getvar "clayer")) (setq oldline (getvar "linetype")) (setvar "clayer" "Lines") (setvar "linetype" "CENTERTOZA") (command "_line") (while (= (getvar "cmdactive") 1 ) (command pause)) (setvar "clayer" oldlay) (setvar "linetype" oldline) ) ;End of file I'm trying to get my different linetypes all on the same layer but having a different linrtype. I've done this wrong and hoping you can see away. Thanks again Quote Link to comment Share on other sites More sharing options...
tombu Posted March 16, 2015 Share Posted March 16, 2015 1. Look at the defun function 2. You needed an *ERROR* function in case someone hits Esc or enters anoher command. 3. CeLtype is the system variable for current entity linetype. 4. This thread should have been in the AutoLISP, Visual LISP & DCL forum! (defun C:tozacentre (/ *ERROR* oldlay oldline) (defun *ERROR* (s) ; If an error (such as CTRL-C) occurs ; while this command is active... (if (/= s "Function cancelled") (princ (strcat "\nError: " s)) ) (setvar "clayer" oldlay) ; current layer (setvar "celtype" oldline) ; current entity linetype (princ) ) (setq oldlay (getvar "clayer")) (setq oldline (getvar "celtype")) (setvar "clayer" "Lines") (setvar "celtype" "HIDDEN2") (command "_line") (while (= (getvar "cmdactive") 1 ) (command pause)) (setvar "clayer" oldlay) (setvar "celtype" oldline) (princ) ) Hope that gets you started. Lisp can be really helpful. Quote Link to comment Share on other sites More sharing options...
tombu Posted March 16, 2015 Share Posted March 16, 2015 Saw your other thread and modified the lisp to be able to create whatever using whatever layer, linetype, and lineweight you want. Added *error* function in case user hits Esc or enters another command, also took in account layer and linetype may not be in the drawing yet. (defun tozacentre (clayer celtype celweight command / *ERROR* filedia oldlay oldline) (defun *ERROR* (s) ; If an error (such as CTRL-C) occurs ; while this command is active... (if (/= s "Function cancelled") (princ (strcat "\nError: " s)) ) (setvar "filedia" filedia) ; display dialog box? (setvar "clayer" oldlay) ; current layer (setvar "celtype" oldline) ; current entity linetype (setvar "celweight" oldlwght) ; current entity linetype in hundredths of millimeters (princ) ) (setq oldlay (getvar "clayer")) (setq filedia (getvar "filedia")) (setvar "filedia" 0) (command "-LAYER" "Make" clayer "") ; sets current layer, makes it if nessisary (or(tblsearch "ltype" "HIDDEN2")(command "-LINETYPE" "Load" "HIDDEN2" "" "")) ; add linetype if needed, still only works if linetype definition is in lin file. (setq oldline (getvar "celtype")) (setq oldlwght (getvar "celweight")) (setvar "clayer" clayer) (setvar "celtype" celtype) (setvar "celweight" celweight) (command "_line") (while (= (getvar "cmdactive") 1 ) (command pause)) (setvar "filedia" filedia) ; display dialog box? (setvar "clayer" oldlay) (setvar "celtype" oldline) (setvar "celweight" oldlwght) (princ) ) Celweight stores current entity linetype in hundredths of millimeters so putting: (tozacentre "Lines" "CENTERTOZA" 9 "Line") in a macro draws Lines on Layer Lines with linetype CENTERTOZA and lineweight 0.09 Quote Link to comment Share on other sites More sharing options...
tgibbo Posted March 16, 2015 Author Share Posted March 16, 2015 Tombu Thank you very much for the help you have given me. I really appreciate it. I have used what you have helped me with and came up with a very productive solution. I have a template (dwt) I use for all my work which contains a "Lines" & "Construction" layer and the necessary line types. The following code now works perfectly. This takes care of all the line types I use in my daily drafting. Thanks again. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;Create Construction line;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun C:tozaconstruction (/ oldlay) (setq oldlay (getvar "clayer")) (setvar "clayer" "Construction") (command "_line") (while (= (getvar "cmdactive") 1 ) (command pause)) (setvar "clayer" oldlay) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;Create Centre line;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun C:tozacenter (/ *ERROR* oldlay oldline) (defun *ERROR* (s) (if (/= s "Function cancelled") (princ (strcat "\nError: " s)) ) (setvar "clayer" oldlay) (setvar "celtype" oldline) (princ) ) (setq oldlay (getvar "clayer")) (setq oldline (getvar "celtype")) (setvar "clayer" "Lines") (setvar "celtype" "CENTERTOZA") (command "_line") (while (= (getvar "cmdactive") 1 ) (command pause)) (setvar "clayer" oldlay) (setvar "celtype" oldline) (princ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;Create Hidden line;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun C:tozahidden (/ *ERROR* oldlay oldline) (defun *ERROR* (s) (if (/= s "Function cancelled") (princ (strcat "\nError: " s)) ) (setvar "clayer" oldlay) (setvar "celtype" oldline) (princ) ) (setq oldlay (getvar "clayer")) (setq oldline (getvar "celtype")) (setvar "clayer" "Lines") (setvar "celtype" "HIDDEN") (command "_line") (while (= (getvar "cmdactive") 1 ) (command pause)) (setvar "clayer" oldlay) (setvar "celtype" oldline) (princ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;Create Hidden2 line;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun C:tozahidden2 (/ *ERROR* oldlay oldline) (defun *ERROR* (s) (if (/= s "Function cancelled") (princ (strcat "\nError: " s)) ) (setvar "clayer" oldlay) (setvar "celtype" oldline) (princ) ) (setq oldlay (getvar "clayer")) (setq oldline (getvar "celtype")) (setvar "clayer" "Lines") (setvar "celtype" "HIDDEN2") (command "_line") (while (= (getvar "cmdactive") 1 ) (command pause)) (setvar "clayer" oldlay) (setvar "celtype" oldline) (princ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;Create Phantom line;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun C:tozaphantom (/ *ERROR* oldlay oldline) (defun *ERROR* (s) (if (/= s "Function cancelled") (princ (strcat "\nError: " s)) ) (setvar "clayer" oldlay) (setvar "celtype" oldline) (princ) ) (setq oldlay (getvar "clayer")) (setq oldline (getvar "celtype")) (setvar "clayer" "Lines") (setvar "celtype" "PHANTOMTOZA") (command "_line") (while (= (getvar "cmdactive") 1 ) (command pause)) (setvar "clayer" oldlay) (setvar "celtype" oldline) (princ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;Create Continuous .18 line;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun C:18grey (/ *ERROR* oldlay oldcolor) (defun *ERROR* (s) (if (/= s "Function cancelled") (princ (strcat "\nError: " s)) ) (setvar "clayer" oldlay) (setvar "celtype" oldcolor) (princ) ) (setq oldlay (getvar "clayer")) (setq oldcolor (getvar "cecolor")) (setvar "clayer" "Lines") (setvar "cecolor" "08") (command "_line") (while (= (getvar "cmdactive") 1 ) (command pause)) (setvar "clayer" oldlay) (setvar "celtype" oldcolor) (princ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;Create Continuous .25 line;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun C:25white (/ *ERROR* oldlay oldcolor) (defun *ERROR* (s) (if (/= s "Function cancelled") (princ (strcat "\nError: " s)) ) (setvar "clayer" oldlay) (setvar "celtype" oldcolor) (princ) ) (setq oldlay (getvar "clayer")) (setq oldcolor (getvar "cecolor")) (setvar "clayer" "Lines") (setvar "cecolor" "07") (command "_line") (while (= (getvar "cmdactive") 1 ) (command pause)) (setvar "clayer" oldlay) (setvar "celtype" oldcolor) (princ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;Create Continuous .35 line;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun C:35yellow (/ *ERROR* oldlay oldcolor) (defun *ERROR* (s) (if (/= s "Function cancelled") (princ (strcat "\nError: " s)) ) (setvar "clayer" oldlay) (setvar "celtype" oldcolor) (princ) ) (setq oldlay (getvar "clayer")) (setq oldcolor (getvar "cecolor")) (setvar "clayer" "Lines") (setvar "cecolor" "02") (command "_line") (while (= (getvar "cmdactive") 1 ) (command pause)) (setvar "clayer" oldlay) (setvar "celtype" oldcolor) (princ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;Create Continuous .50 line;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun C:50red (/ *ERROR* oldlay oldcolor) (defun *ERROR* (s) (if (/= s "Function cancelled") (princ (strcat "\nError: " s)) ) (setvar "clayer" oldlay) (setvar "celtype" oldcolor) (princ) ) (setq oldlay (getvar "clayer")) (setq oldcolor (getvar "cecolor")) (setvar "clayer" "Lines") (setvar "cecolor" "01") (command "_line") (while (= (getvar "cmdactive") 1 ) (command pause)) (setvar "clayer" oldlay) (setvar "celtype" oldcolor) (princ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;Create Continuous .70 line;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun C:70cyan (/ *ERROR* oldlay oldcolor) (defun *ERROR* (s) (if (/= s "Function cancelled") (princ (strcat "\nError: " s)) ) (setvar "clayer" oldlay) (setvar "celtype" oldcolor) (princ) ) (setq oldlay (getvar "clayer")) (setq oldcolor (getvar "cecolor")) (setvar "clayer" "Lines") (setvar "cecolor" "04") (command "_line") (while (= (getvar "cmdactive") 1 ) (command pause)) (setvar "clayer" oldlay) (setvar "celtype" oldcolor) (princ) ) Quote Link to comment Share on other sites More sharing options...
ReMark Posted March 17, 2015 Share Posted March 17, 2015 If you are using a template why didn't you include the linetypes in the template itself thus negating the need for using a custom lisp routine to load the linetypes in the first place? Quote Link to comment Share on other sites More sharing options...
tgibbo Posted March 17, 2015 Author Share Posted March 17, 2015 Thanks ReMark for your comments. I was using that method but there are too many layers and I have to revert back to a particular layer each time after the line command. It's the way my software works. I use Autodesk Advance Steel and it needs to remain in the "Standard" layer for some functions to work correctly. So this lisp allows me to draw different lines and then change back to "Standard: layer. Quote Link to comment Share on other sites More sharing options...
tgibbo Posted March 17, 2015 Author Share Posted March 17, 2015 Hi Tombu After I draw a line and want to finish I need to press the right mouse button to end and the layer changes back to "oldlay" but if I press escape when I finish the line the routine ends and the layer doesn't revert back. Do you know if it is possible to have the option to either use escape or right mouse to end? Regards tony 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.