Gratitude1977 Posted December 16, 2010 Posted December 16, 2010 Hi all, I am trying to modify an existing list that I got from a fellow member for blocks. the difference in what I am trying to accomplish is instead of inserting a block I would like this to create a line with a specific linetype on a specific layer and then revert to the previous layer again after the command is finished. Here is what I have tried and still not working. (defun c:Gas (/ *error* oldLayer layerName pt) ;; Error handler (defun *error* nil (if oldLayer (setvar 'clayer oldLayer))) ;; Main code (setq oldLayer (getvar 'clayer)) (if (not (tblsearch "layer" (setq layerName "generalgas"))) (command "._-layer" "_new" layerName "")) (setvar 'clayer layerName) (command ".-linetype;S;"GAS_LINE2";;LINE) (setvar 'clayer oldLayer) (princ)) Thanks for any and all input. Quote
Lee Mac Posted December 16, 2010 Posted December 16, 2010 This may be a quick fix, although it currently assumes the linetype to be loaded in the drawing: (defun c:Gas ( / *error* layer ltype old v ) (setq layer "generalgas" ltype "GAS_LINE2") (defun *error* ( msg ) (if old (mapcar 'setvar v old)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ) ) (setq old (mapcar 'getvar (setq v '(CLAYER CELTYPE)))) (if (not (tblsearch "LAYER" layer)) (entmake (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 layer) (cons 70 0) ) ) ) (mapcar 'setvar v (list layer ltype)) (command "_.line") (while (= 1 (logand 1 (getvar 'CMDACTIVE))) (command pause) ) (mapcar 'setvar v old) (princ) ) Quote
David Bethel Posted December 16, 2010 Posted December 16, 2010 I think I'd go more like this: [b][color=BLACK]([/color][/b]defun c:gas [b][color=FUCHSIA]([/color][/b]/ gas_lt p1 p2 pl[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq gas_lt [color=#2f4f4f]"GAS_LINE2"[/color][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]if [b][color=NAVY]([/color][/b]not [b][color=MAROON]([/color][/b]tblsearch [color=#2f4f4f]"LTYPE"[/color] gas_lt[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]progn [b][color=MAROON]([/color][/b]alert [b][color=GREEN]([/color][/b]strcat [color=#2f4f4f]"LineType "[/color] gas_lt [color=#2f4f4f]" Needs To Be Loaded - Aborting"[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]exit[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]initget 1[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq p1 [b][color=NAVY]([/color][/b]getpoint [color=#2f4f4f]"\nLINE From point: "[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq pl [b][color=NAVY]([/color][/b]list p1[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]setq p2 [b][color=MAROON]([/color][/b]getpoint p1 [color=#2f4f4f]"\nTo point: "[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]grdraw p1 p2 2 3[b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]setq pl [b][color=MAROON]([/color][/b]cons p2 pl[b][color=MAROON])[/color][/b] p1 p2[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]if [b][color=NAVY]([/color][/b]> [b][color=MAROON]([/color][/b]length pl[b][color=MAROON])[/color][/b] 1[b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]repeat [b][color=MAROON]([/color][/b]1- [b][color=GREEN]([/color][/b]length pl[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]entmake [b][color=GREEN]([/color][/b]list [b][color=BLUE]([/color][/b]cons 0 [color=#2f4f4f]"LINE"[/color][b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]cons 6 gas_lt[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]cons 8 [color=#2f4f4f]"GENERALGAS"[/color][b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]cons 10 [b][color=RED]([/color][/b]car pl[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]cons 11 [b][color=RED]([/color][/b]cadr pl[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] [color=#8b4513];;;Set These Groups To Suite:[/color] [color=#8b4513]; [b][color=BLUE]([/color][/b]cons 39 0[b][color=BLUE])[/color][/b][/color] [color=#8b4513]; [b][color=BLUE]([/color][/b]cons 48 1[b][color=BLUE])[/color][/b][/color] [color=#8b4513]; [b][color=BLUE]([/color][/b]cons 62 256[b][color=BLUE])[/color][/b][/color] [color=#8b4513]; [b][color=BLUE]([/color][/b]cons 210 [b][color=RED]([/color][/b]trans '[b][color=PURPLE]([/color][/b]0 0 1[b][color=PURPLE])[/color][/b] 1 0[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][/color] [b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq pl [b][color=GREEN]([/color][/b]cdr pl[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] CLAYER will fail if the layer is frozen, not in an ( entmake ) call. Loading a LINETYPE via Autolisp can be fraught with problems. -David Quote
The Buzzard Posted December 16, 2010 Posted December 16, 2010 Hi all, I am trying to modify an existing list that I got from a fellow member for blocks. the difference in what I am trying to accomplish is instead of inserting a block I would like this to create a line with a specific linetype on a specific layer and then revert to the previous layer again after the command is finished. Here is what I have tried and still not working. (defun c:Gas (/ *error* oldLayer layerName pt) ;; Error handler (defun *error* nil (if oldLayer (setvar 'clayer oldLayer))) ;; Main code (setq oldLayer (getvar 'clayer)) (if (not (tblsearch "layer" (setq layerName "generalgas"))) (command "._-layer" "_new" layerName "")) (setvar 'clayer layerName) (command ".-linetype;S;"GAS_LINE2";;LINE) (setvar 'clayer oldLayer) (princ)) Thanks for any and all input. Give this a shot. GL.lsp 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.