samifox Posted March 10, 2013 Share Posted March 10, 2013 Hi i got a function that should freeze/thaw layer status, but i want to send the layer name as an argument so i can reuse. defun c:layFreezeTogg(layerName / l ) (cond ( (= (strcase (getvar 'clayer)) (strcase layer)) (princ "\nCannot freeze the current layer.") ) ( (setq l (tblobjname "LAYER" layerName)) (setq l (vlax-ename->vla-object l)) (vlax-put l 'freeze (~ (vlax-get l 'freeze))) (command "REGEN") ) ( (princ (strcat "\nLayer " layerName " does not exist."))) ) (princ) ) (vl-load-com) (princ) its made sense to me to type in the autocad command line (after loading it) : layFreezeTogg("guides") but its not working that way Thanks Shay Quote Link to comment Share on other sites More sharing options...
David Bethel Posted March 10, 2013 Share Posted March 10, 2013 You really shouldn't try to pass arguments to c: commands. You would literally have to type (c:layFreezeTogg "GUIDES") on the command line. -David Quote Link to comment Share on other sites More sharing options...
samifox Posted March 10, 2013 Author Share Posted March 10, 2013 its a frontdoor way or backdoor one? this is the native way to pass arguments to a function? Quote Link to comment Share on other sites More sharing options...
samifox Posted March 10, 2013 Author Share Posted March 10, 2013 Command: (c:layFreezeTogg "GUIDES") ; error: bad argument type: stringp nil Quote Link to comment Share on other sites More sharing options...
David Bethel Posted March 10, 2013 Share Posted March 10, 2013 I'd try something like this : [b][color=BLACK]([/color][/b]defun tog_lay [b][color=FUCHSIA]([/color][/b]l / td fl[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]cond [b][color=NAVY]([/color][/b][b][color=MAROON]([/color][/b]not [b][color=GREEN]([/color][/b]snvalid l[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]alert [color=#2f4f4f]"Not A Valid LAyer Name"[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b][b][color=MAROON]([/color][/b]not [b][color=GREEN]([/color][/b]setq td [b][color=BLUE]([/color][/b]tblsearch [color=#2f4f4f]"LAYER"[/color] l[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]alert [b][color=GREEN]([/color][/b]strcat [color=#2f4f4f]"Layer "[/color] l [color=#2f4f4f]" Does Not Exist"[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b][b][color=MAROON]([/color][/b]eq l [b][color=GREEN]([/color][/b]getvar [color=#2f4f4f]"CLAYER"[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]alert [b][color=GREEN]([/color][/b]strcat [color=#2f4f4f]"Cannot Freeze Current Layer "[/color] l[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]T [b][color=MAROON]([/color][/b]if [b][color=GREEN]([/color][/b]= [b][color=BLUE]([/color][/b]logand [b][color=RED]([/color][/b]cdr [b][color=PURPLE]([/color][/b]assoc 70 td[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b] 1[b][color=BLUE])[/color][/b] 1[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]command [color=#2f4f4f]"_.LAYER"[/color] [color=#2f4f4f]"_T"[/color] l [color=#2f4f4f]""[/color][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]command [color=#2f4f4f]"_.LAYER"[/color] [color=#2f4f4f]"_F"[/color] l [color=#2f4f4f]""[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] l[b][color=BLACK])[/color][/b] (tog_lay "0") -David Quote Link to comment Share on other sites More sharing options...
samifox Posted March 10, 2013 Author Share Posted March 10, 2013 how to call it? Quote Link to comment Share on other sites More sharing options...
David Bethel Posted March 10, 2013 Share Posted March 10, 2013 how to call it? ? You would call this from another function: (defun c:test (/ l) (setq l (strcase (getstring "\nLayer To Toggle: "))) (tog_lay l) (prin1)) -David Quote Link to comment Share on other sites More sharing options...
samifox Posted March 10, 2013 Author Share Posted March 10, 2013 i mean i want to set a button in my tool palatte or menue item and call it from there Quote Link to comment Share on other sites More sharing options...
David Bethel Posted March 10, 2013 Share Posted March 10, 2013 Sorry, I know nothing about buttons or CUI menus. -David Quote Link to comment Share on other sites More sharing options...
samifox Posted March 10, 2013 Author Share Posted March 10, 2013 how do i call it from the commandline than...? Quote Link to comment Share on other sites More sharing options...
David Bethel Posted March 10, 2013 Share Posted March 10, 2013 This should help : http://www.cadtutor.net/forum/showthread.php?1390-How-to-use-the-LISP-routines-in-this-archive Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 10, 2013 Share Posted March 10, 2013 Command: (c:layFreezeTogg "GUIDES") ; error: bad argument type: stringp nil You receive this error because you have not renamed one of the variables in my code: [color=red]([/color]defun layfreezetogg ( layername / l ) (cond ( (= (strcase (getvar 'clayer)) (strcase [color=red]layername[/color])) (princ "\nCannot freeze the current layer.") ) ( (setq l (tblobjname "LAYER" layername)) (setq l (vlax-ename->vla-object l)) (vlax-put l 'freeze (~ (vlax-get l 'freeze))) (command "[color=red]_.[/color]regen") ) ( (princ (strcat "\nLayer " layername " does not exist."))) ) (princ) ) (vl-load-com) (princ) Since the function now requires arguments, the 'c:' prefix is no longer required since the function can no longer be called directly at the command-line as a command (you would receive a 'too few arguments' error). You can now call the above function using: (layfreezetogg "GUIDES") Quote Link to comment Share on other sites More sharing options...
samifox Posted March 10, 2013 Author Share Posted March 10, 2013 running this code gives this error: User warning: assignment to protected symbol: acNative what does it mean? 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.