Jump to content

Recommended Posts

Posted

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

Posted

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

Posted

its a frontdoor way or backdoor one? this is the native way to pass arguments to a function?

Posted

Command: (c:layFreezeTogg "GUIDES") ; error: bad argument type: stringp nil

Posted

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

Posted
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

Posted

i mean i want to set a button in my tool palatte or menue item and call it from there

Posted

Sorry, I know nothing about buttons or CUI menus. -David

Posted

how do i call it from the commandline than...?

Posted
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")

Posted

running this code gives this error:

User warning: assignment to protected symbol: acNative

 

what does it mean?

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...