What's wrong with my code?

What's wrong with my code?

Anonymous
Not applicable
1,001 Views
6 Replies
Message 1 of 7

What's wrong with my code?

Anonymous
Not applicable

It's been a while, so excuse the crudeness of this routine. I don't know what is wrong with it. It is obvious what it is suppose to do. I'm not asking for someone to write a better or more sleek version. Can't learn that way. Please just tell me what's wrong with this code. TIA

 

(defun c:ISOMODECYCLE()
  (cond
    ((= (getvar "snapstyl") 0)
     (progn (setvar "snapstyl" 1) (setvar "SNAPISOPAIR" 0))
     )
    ((and (= (getvar "snapstyl") 1) (= (getvar "snapisopair") 0)) (setvar "snapisopair" 1))
    ((and (= (getvar "snapstyl") 1) (= (getvar "snapisopair") 1)) (setvar "snapisopair" 2))
    ((and (= (getvar "snapstyl") 1) (= (getvar "snapisopair") 2)) (setvar "snapstyl" 0))
  )
)

0 Likes
Accepted solutions (1)
1,002 Views
6 Replies
Replies (6)
Message 2 of 7

ВeekeeCZ
Consultant
Consultant
Accepted solution

Is nothing the correct answer?

 

BTW You do realize that the COND function does test all the conditions until some is True? That said, if you exclude earlier condition, you don't need to test the opposite. The code should look like this:

 

(defun c:ISOMODECYCLE ()
  (cond
    ((= (getvar "snapstyl") 0)
     (setvar "snapstyl" 1)   ; no need for progn here, but does not hurt
     (setvar "SNAPISOPAIR" 0)
     )
    ((= (getvar "snapisopair") 0)      (setvar "snapisopair" 1))
    ((= (getvar "snapisopair") 1)      (setvar "snapisopair" 2))
    ((= (getvar "snapisopair") 2)      (setvar "snapstyl" 0))
    )
  )

 

Or clever version...

(cond ((= (getvar "snapstyl") 0)
         (setvar "snapstyl" 1)
         (setvar "SNAPISOPAIR" 0)
         )
        ((= (getvar "snapisopair") 2)
         (setvar "snapstyl" 0))
        (T
         (setvar "snapisopair" (1+ (getvar "snapisopair")))))

 

0 Likes
Message 3 of 7

Anonymous
Not applicable

Thank you. In case it isn't truly obvious, my intention is to redefine the F5 key to run this routine. We switch between ISO an RECTANGULAR all of the time within drawings. This just adds rectangular into the F5 cycle.

0 Likes
Message 4 of 7

ВeekeeCZ
Consultant
Consultant

Sure, why not. I don't use isometric view at all, so your intention really wasn't obvious to me. 

My F5 actually ISOLATEs layers.

 

BTW for F5 key would be more suitable a diesel macro... soo you've learned a bit of LISP right now, how about diesel now? 😉

0 Likes
Message 5 of 7

Anonymous
Not applicable

Sure. Lay it on me. I want the F5 key to act like it already does but also cycle to rectangular mode and back again.

0 Likes
Message 6 of 7

ВeekeeCZ
Consultant
Consultant

Well, the benefit of macros is that can easily work transparently. 

 

^P$M=$(if,$(=,$(getvar,snapstyl),0),'_snapstyl 1 '_.snapisopair 0,$(if,$(=,$(getvar,snapisopair),2),'_.snapstyl 0,'_.snapisopair $(+,$(getvar,snapisopair),1)))
0 Likes
Message 7 of 7

Anonymous
Not applicable

Thank you. Now how do I modify my F5 key to utilize that?

0 Likes