There is something wrong with my lisp?

There is something wrong with my lisp?

Anonymous
Not applicable
1,205 Views
11 Replies
Message 1 of 12

There is something wrong with my lisp?

Anonymous
Not applicable

(defun C:TH ()

(setvar "cmdecho" 0)
(setq osv (getvar "osmode"))
(setvar "osmode" 0)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(setq A (getpoint "\n Specify first corner of rectangle: "))
(initget (+ 1 2 4))
(setq B (getreal "\n Specify length: "))
(initget (+ 1 2 4))
(setq C (getreal "\n Specify width: "))

 

(initget (+ 1 2 4))
(setq L1 (getreal "\n Offset from the left side: "))
(initget (+ 1 4))
(setq L2 (getreal "\n Offset from first circle: "))


(initget (+ 1 2 4))

(initget 0 "Point") 
(setq F (getreal "\n Specify diameter or [Point]: "))

 

(setq A2 (polar A 0 B))
(setq A3 (polar A2 (/ pi 2) C))
(setq A4 (polar A (/ pi 2) C))

(setq A5 (polar A 0 L1))
(setq C1 (polar A5 (/ pi 2) (/ C 2)))
(setq C2 (polar C1 0 L2))

 

(command ".pline" A A2 A3 A4 "close")
(setvar "regenmode" 1)
;;;;;;;;;;;;;;;;;;;;;;;;;
(cond
  ((= (strcase F) "P") (command ".point" C1 "" ".point" C2 ""))
  ((\= (strcase F) "P") (command ".circle" C1 "_d" F "" ".circle" C2 "_d" F ""))
)
;;;;;;;;;;;;;;;;;;;;;;

(setvar "osmode" osv)
(setvar "cmdecho" 1)
)

 

 

-----------------------------

There is something wrong with my lisp? I try I draw a rectange with 2 holes, Instead of holes I choose Point for it!

0 Likes
Accepted solutions (1)
1,206 Views
11 Replies
Replies (11)
Message 2 of 12

ВeekeeCZ
Consultant
Consultant

@Anonymous wrote:

(defun C:TH ()

(setvar "cmdecho" 0)
(setq osv (getvar "osmode"))
(setvar "osmode" 0)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(setq A (getpoint "\n Specify first corner of rectangle: "))
(initget (+ 1 2 4))
(setq B (getreal "\n Specify length: "))
(initget (+ 1 2 4))
(setq C (getreal "\n Specify width: "))

 

(initget (+ 1 2 4))
(setq L1 (getreal "\n Offset from the left side: "))
(initget (+ 1 4))
(setq L2 (getreal "\n Offset from first circle: "))


(initget (+ 1 2 4))

(initget 0 "Point") 
(setq F (getreal "\n Specify diameter or [Point]: "))

 

(setq A2 (polar A 0 B))
(setq A3 (polar A2 (/ pi 2) C))
(setq A4 (polar A (/ pi 2) C))

(setq A5 (polar A 0 L1))
(setq C1 (polar A5 (/ pi 2) (/ C 2)))
(setq C2 (polar C1 0 L2))

 

(command ".pline" A A2 A3 A4 "close")
(setvar "regenmode" 1)
;;;;;;;;;;;;;;;;;;;;;;;;;
(cond
  ((= (strcase F) "P") (command ".point" C1 "" ".point" C2 ""))
  ((\= (strcase F) "P") (command ".circle" C1 "_d" F "" ".circle" C2 "_d" F ""))
)
;;;;;;;;;;;;;;;;;;;;;;

(setvar "osmode" osv)
(setvar "cmdecho" 1)
)

 

 

-----------------------------

There is something wrong with my lisp? I try I draw a rectange with 2 holes, Instead of holes I choose Point for it!


Getreal never returns just "P". 

Message 3 of 12

hak_vz
Advisor
Advisor

@Anonymous 

(setq F (getreal "\n Specify diameter or [Point]: "))
....
((= (strcase F) "P") .... F is real so strcase will not work
((\= (strcase F) ....it is /=

 

Use getkword after initget

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 4 of 12

ВeekeeCZ
Consultant
Consultant
Accepted solution

There are many more flaws. Compare both versions to see the difference.

 

(defun C:TH ()

(setvar "cmdecho" 0)
(setq osv (getvar "osmode"))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(setq A (getpoint "\n Specify first corner of rectangle: "))
(initget (+ 1 2 4))
(setq B (getreal "\n Specify length: "))
(initget (+ 1 2 4))
(setq C (getreal "\n Specify width: "))

 

(initget (+ 1 2 4))
(setq L1 (getreal "\n Offset from the left side: "))
(initget (+ 1 4))
(setq L2 (getreal "\n Offset from first circle: "))


;(initget (+ 1 2 4))

(initget 0 "Point") 
(setq F (getreal "\n Specify diameter or [Point]: "))

 

(setq A2 (polar A 0 B))
(setq A3 (polar A2 (/ pi 2) C))
(setq A4 (polar A (/ pi 2) C))

(setq A5 (polar A 0 L1))
(setq C1 (polar A5 (/ pi 2) (/ C 2)))
(setq C2 (polar C1 0 L2))

 
(setvar "osmode" 0)
(command ".pline" A A2 A3 A4 "close")
(setvar "regenmode" 1)

  (if (= F "Point")
    (command ".point" C1 ".point" C2 )
    (command ".circle" C1 "_d" F ".circle" C2 "_d" F)
)

(setvar "osmode" osv)
(setvar "cmdecho" 1)
)

 

0 Likes
Message 5 of 12

pbejse
Mentor
Mentor

 

 

(initget 0 "Point") 
(setq F (getreal "\n Specify diameter or [Point]: "))

 

 

There are 4 possible outcome from this statement
1. the user enter "p" or "P" : result is "Point"
2. The user enter a real number or integer : 50 or 50.00 will give you a real number
3. The user press enter : result is nil
4. The user press escape : result is "error: Function cancelled"

 

 

(cond
  ((= (strcase F) "P") (command ".point" C1 "" ".point" C2 ""))
  ((\= (strcase F) "P") (command ".circle" C1 "_d" F "" ".circle" C2 "_d" F ""))
)

 

 

 

  • (Strcase F) will fail if the value is not a string
  • (= f "P") even if you take out strcase and the value is a valid string and not a real number the statement will always be false as typing "P" or "p" will give you give you "Point" and not "P

Say the user did enter  a real/int for diameter, Your code did not acount if the user for that result

 

To prevent the user from pressing enter, a negative value or 0 use initget 7

 

Hope this makes sense

 

0 Likes
Message 6 of 12

Kent1Cooper
Consultant
Consultant

@pbejse wrote:

....

There are 4 possible outcome from this statement

....

Say the user did enter  a real/int for diameter, Your code did not acount if the user for that result

....


There's a 5th possible outcome:

5.  The User types any non-numerical entry other than P or p [or one of those plus more of the word]: the result is that it will scold them and ask again.

 

And a real/integer entry for the diameter is  accounted for, in the second condition [to draw the Circles], though the test argument for it is not correct.

Kent Cooper, AIA
0 Likes
Message 7 of 12

pbejse
Mentor
Mentor

@Kent1Cooper wrote:

And a real/integer entry for the diameter is  accounted for, in the second condition [to draw the Circles], though the test argument for it is not correct.


--- Your code did not acount if the user for that result --- 

(strcase f) will always produce an error for real/integer input. My point is regardless, what the input,  the cond will not work.

 

0 Likes
Message 8 of 12

Kent1Cooper
Consultant
Consultant

My point was that, although it is not accounted for in a workable  way [because the test argument is not correct], it is accounted for [i.e. they did  include something for the routine to do with a numerical User input].  They just need to fix the test argument to get that condition to function.

Kent Cooper, AIA
0 Likes
Message 9 of 12

Anonymous
Not applicable

Thank you for yourhelping! It works for me!

0 Likes
Message 10 of 12

pbejse
Mentor
Mentor

Oh I see now, yes indeed. It must be the second bottle of whiskey that threw me off. 🙂 

 

 

0 Likes
Message 11 of 12

Anonymous
Not applicable

I want to change 2 holes or 2 points in to layer name is "33" after command is finished, how can I do? I am a new autolisper, So......

0 Likes
Message 12 of 12

pbejse
Mentor
Mentor

@Anonymous wrote:

I want to change 2 holes or 2 points in to layer name is "33" after command is finished, how can I do? I am a new autolisper, So......


(defun C:TH ( / _Createthis ipoints) 
(defun _Createthis (n l r lst)
    (foreach pt	lst
      (setq ent (list (cons 0 n) (cons 8 l) (cons 10 pt)))
      (entmake (if r
		 (append ent (list (cons 40 r)))
		 ent
	       )
      )
    )
  )  

(setvar "cmdecho" 0)
(setq osv (getvar "osmode"))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  
(setq lname "33");<----- Your layer name or you can change this to prompt for layer name
  
(setq A (getpoint "\n Specify first corner of rectangle: "))
(initget (+ 1 2 4))
(setq B (getreal "\n Specify length: "))
(initget (+ 1 2 4))
(setq C (getreal "\n Specify width: "))

 

(initget (+ 1 2 4))
(setq L1 (getreal "\n Offset from the left side: "))
(initget (+ 1 4))
(setq L2 (getreal "\n Offset from first circle: "))

;(initget (+ 1 2 4))

(initget 0 "Point") 
(setq F (getreal "\n Specify diameter or [Point]: "))

(setq A2 (polar A 0 B))
(setq A3 (polar A2 (/ pi 2) C))
(setq A4 (polar A (/ pi 2) C))

(setq A5 (polar A 0 L1))
(setq C1 (polar A5 (/ pi 2) (/ C 2)))
(setq C2 (polar C1 0 L2))
(setq ipoints (list c1 c2))  

 
(setvar "osmode" 0)
(command ".pline" A A2 A3 A4 "close")
(setvar "regenmode" 1)

  (if (= F "Point")
    (_Createthis "POINT" lname nil ipoints)
    (_Createthis "CIRCLE" lname f ipoints)
    
)
(setvar "osmode" osv)
(setvar "cmdecho" 1)
)

HTH

 

0 Likes