Unable to use the setvar function properly in lisp routine

Unable to use the setvar function properly in lisp routine

Anonymous
Not applicable
1,358 Views
2 Replies
Message 1 of 3

Unable to use the setvar function properly in lisp routine

Anonymous
Not applicable

Please take a look at the code and let me know where does it need modification.

As it is not working the way I intended it to work

what I want to do is

1. get the current layer and store it in a variable

2. set the current layer to "clouds"

3. invoke the "_revcloud" command

4. set the current layer back from the one stored in variable.

 

any help would be appreciated

(defun c:RC()
(setq X (getvar "clayer"))
(setvar "clayer" "CLOUDS")
(command "_revcloud" "" "NO")
(setvar "clayer" X)
(princ)
)

 

0 Likes
1,359 Views
2 Replies
Replies (2)
Message 2 of 3

cadffm
Consultant
Consultant

First problem: (setvar "clayer" "CLOUDS")

1. You don't check if the layer CLOUDS really exist. *crash*
2. You don't make sure that the "CLOUDS" Layer is thawed. *crash*

 

Second Problem: (command "_revcloud" "" "NO")

Note: You mixed international and local calls, you should use international commands and options only (or locals, but mixing is nonsens)

NO=english vs _NO=international

 

3. I don't know in which Version this whould work, what version do you have?
For 2013-2019 your line start the Revcloud command,

the following ENTER "" start the OBJECT option and

then  your "No" isn't a valid input! In your version not?

Send (command "_revcloud" "" "NO") into commandline. Is it working without problems? Check it in your Textscreen [F2]

Without error trapping: (command "_revcloud" PAUSE "_no"), but it would be better to select an object first

and if done (only then) - start the Layer command.

4.You don't check if the "oldlayer" is unlocked or not. *crash*

 

Also a very simple kind, but more safety

(defun c:RC (/ AWS OLDLAYER) ; local symbols
(while (not(setq AWS (ssget "_:S:L" '((0 . "CIRCLE,ELLIPSE,*POLYLINE,SPLINE")))))) ; valid object types and unlocked layers
(setq OLDLAYER (getvar "clayer"))
(command "_.-LAYER" "_thaw" "CLOUDS" "_make" "CLOUDS" "") ; make sure CLOUDS exist and current, thawed
(command "_.REVCLOUD" "_object" (ssname AWS 0) "_no")
(setvar "CLAYER" OLDLAYER)
(princ)
)

Sebastian

0 Likes
Message 3 of 3

dlanorh
Advisor
Advisor

Try this, taking into account @cadffm 's comments above :

 

(vl-load-com)

(defun c:RC( / c_doc c_lyrs c_lyr)

  (setq c_doc (vla-get-activedocument (vlax-get-acad-object))
        c_lyrs (vla-get-layers c_doc)
  );end_setq
  
  (cond ( (not (tblobjname "layer" "CLOUDS")) (vla-add c_lyrs "CLOUDS"))
        (t 
          (setq lyr (vla-item c_lyrs "CLOUD"))
          (mapcar '(lambda (x) (vlax-put-property lyr x y)) (list 'lock 'freeze 'on) (list :vlax-false :vlax-false :vlax-true))
        )  
  );end_cond

  (setq c_lyr (getvar 'clayer))
  (setvar 'clayer "CLOUDS")
  (vl-cmdf "_revcloud" "_S" "_N" "_O" pause "_NO")
  (setvar 'clayer c_lyr)
  (princ)
);end_defun

I am not one of the robots you're looking for

0 Likes