Jump to content

Change color, command, change back


dan03432

Recommended Posts

I am trying to write a lisp that will change the current color (not layer color), execute a user input command, then change it back to bylayer.

 

(defun C:revc ()
(command "color" "240")
(command "revcloud")
(command "color" "bylayer")
) ;end_defun

 

If I remove the command to change the color back to bylayer it will execute fine. I think it is having an issue when I don't pause it and wait for the user to finish the "revcloud" command.

Link to comment
Share on other sites

You may use the CECOLOR system variable instead:

(setvar "CECOLOR" "240")
;your code here
(setvar "CECOLOR" "ByLayer")

 

Regards,

Mircea

Link to comment
Share on other sites

 
(defun c:revc nil
(setvar 'Cecolor "240")
      (command "_.Revcloud")
       (while (> (getvar 'Cmdactive) 0)
                     (command pause))
       (setvar 'Cecolor "256")(princ)
     )

 

EDIT: Ooops.. didnt see your post there Mircea :)

Link to comment
Share on other sites

No matter what the layer status color is . :D

 

(defun c:TesT nil
 (command "_.revcloud")
 (while
   (= (getvar 'cmdactive) 1)
    (command pause)
 )
 (command "_.chprop" (entlast) "" "_color" 240 "")
 (princ)
)

Link to comment
Share on other sites

Be careful...

 

Command: revc
_.Revcloud
Minimum arc length: 0.5000   Maximum arc length: 0.5000   Style: Normal
Specify start point or [Arc length/Object/Style] <Object>: [color=red]*Cancel*[/color]

Command: [color=red]; error: Function cancelled[/color]

 

;)

Link to comment
Share on other sites

No matter what the layer status color is . :D

 

I believe the intent is to draw the revcloud in the desired color, and not change afterward.

 

:lol: Busted!!

 

Example with error handling:

 

(defun c:revc  ( / *error*)

 (defun *error*  (msg)
   (and oldCecolor (setvar 'cecolor oldCecolor))
   (cond ((not msg))                                                   ; Normal exit
         ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
         ((princ (strcat "\n** Error: " msg " ** "))))                 ; Fatal error, display it
   (princ))

 ((lambda (oldCecolor)
    (setvar 'cecolor "240")
    (command "._revcloud")
    (while (= (logand 1 (getvar 'cmdactive)) 1) (command pause))
    (*error* nil))
   (getvar 'cecolor)))

 

** Edit - This way, both when the command is completed, and if the user escapes out, the original Cecolor is restored.

Link to comment
Share on other sites

Another:

 

(vl-load-com)
(if (null *revcloudreactor*)
   (setq *revcloudreactor*
       (vlr-command-reactor nil
          '(
               (:vlr-commandwillstart . revcloudstore)
               (:vlr-commandended     . revcloudrestore)
               (:vlr-commandfailed    . revcloudrestore)
               (:vlr-commandcancelled . revcloudrestore)
           )
       )
   )
)
(defun revcloudstore ( reactor params )
   (if (wcmatch (strcase (car params)) "*REVCLOUD")
       (progn
           (setq *cecolor* (getvar 'CECOLOR))
           (setvar 'CECOLOR "240")
       )
   )
   (princ)
)
(defun revcloudrestore ( reactor params )
   (if (and *cecolor* (wcmatch (strcase (car params)) "*REVCLOUD"))
       (progn
           (setvar 'CECOLOR *cecolor*)
           (setq *cecolor* nil)
       )
   )
   (princ)
)
(princ)

Link to comment
Share on other sites

Example with error handling:

 

(defun c:revc ( / *error*)
(defun *error* (msg)
(and oldCecolor (setvar 'cecolor oldCecolor))
..... 

 

This way, both when the command is completed, and if the user escapes out, the original Cecolor is restored.

 

Yup :thumbsup:

 

I knew i couldnt type and code as fast as your Renderman so i didnt even try :lol:

Link to comment
Share on other sites

Using a Command Reactor is my preferred method of standardizing active layer, color, etc. for multiple commands.

 

Very concise, Lee. :thumbsup:

Link to comment
Share on other sites

I knew i couldnt type and code as fast as your Renderman so i didnt even try :lol:

 

That is kind of you to say, but please know that trying to both offer the (or at least a) solution to a post, and do so before Lee, etc. beat me to it is what helped me learn all that I have... A little friendly, and respectful competition can be a good thing.

 

Don't ever feel that you couldn't, or shouldn't contribute because I or others have jumped in... Helping others is a great way to learn yourself. :beer:

Link to comment
Share on other sites

I wish I could deal with reactors one day .

 

Who are you, and what have you done with the Tharwat that I know!?!? :unsure:

 

You can tackle reactors - just know the rules, and plan for contingencies the way you would with any other routine. :thumbsup:

Link to comment
Share on other sites

Who are you, and what have you done with the Tharwat that I know!?!? :unsure:

 

You can tackle reactors - just know the rules, and plan for contingencies the way you would with any other routine. :thumbsup:

 

I am overwhelmed by work nowadays , and reactor need a very calm mind to avoid getting crazy .:D

 

Sooner or later will get through it deeply .

 

Thanks mate for the head up .

Link to comment
Share on other sites

That is kind of you to say, but please know that trying to both offer the (or at least a) solution to a post, and do so before Lee, etc. beat me to it is what helped me learn all that I have... A little friendly, and respectful competition can be a good thing.

 

Don't ever feel that you couldn't, or shouldn't contribute because I or others have jumped in... Helping others is a great way to learn yourself. :beer:

 

Wilco, :)

 

Thank you Renderman and Cheers :beer:

Link to comment
Share on other sites

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...