Choose 3 options for my autolisp! Please correct it for me! Thank you very much!

Choose 3 options for my autolisp! Please correct it for me! Thank you very much!

Anonymous
Not applicable
902 Views
5 Replies
Message 1 of 6

Choose 3 options for my autolisp! Please correct it for me! Thank you very much!

Anonymous
Not applicable

(defun C:test ()

 

(defun thang ()
(setq A (getpoint "Fist pick 1: "))
(setq B (getpoint "Second pick 2: "))
(command "line" A B "")
)

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

(defun tron ()
(setq C (getpoint "Center: "))
(setq D (getdist "Diameter: "))
(command "circle" C D "")
)

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

(defun Hinhchunhat ()
(setq A (getpoint "\n First pick: "))
(initget (+ 1 2 4))
(setq B (getreal "\n Length: "))
(initget (+ 1 2 4))
(setq C (getreal "\n width: "))

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

(command ".pline" A A1 A2 A3 "close")
)

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

(iniget 1 "Thang Tron Hinhchunhat")
(setq E (getkword "\n Choose Thang\Tron\Hinhchunhat: "))
(if (= E nil)(thang)
    (= E "Tron") (tron)
    (= E "Hinhchunhat") (Hinhchunhat)
)
)

-------------------------------
Please help me to correct my autolisp!

I want to set "Thang" is default and when I enter it will perfome defun "Thang" .
When I press T it will be "Tron", H it will be "Hinhchunhat"

I am a beginner, thank you very much for your replies!

 

0 Likes
Accepted solutions (2)
903 Views
5 Replies
Replies (5)
Message 2 of 6

pbejse
Mentor
Mentor
Accepted solution

@Anonymous wrote:

I want to set "Thang" is default and when I enter it will perfome defun "Thang" .
When I press T it will be "Tron", H it will be "Hinhchunhat" 


Remove 1 from initget as 1 means:

Prevents the user from responding to the request by entering only Enter.

Also.

(initget "Thang TRon Hinhchunhat")
(setq E (getkword "\nChoose [Thang/TRon/Hinhchunhat]<Thang>: "))
(cond
  ( (or (null E)
         (= E "THang"))(thang)
   )
  ((eq E "TRon") (tron))
  ((eq E "Hinhchunhat") (Hinhchunhat))
 )

HTH

 

Message 3 of 6

ВeekeeCZ
Consultant
Consultant
Accepted solution

Further possible improvements.

 

(defun C:test ( / thang tron Hinhchunhat)
     
  (defun thang (/ a b)
    (setq A (getpoint "Fist pick 1: "))
    (setq B (getpoint "Second pick 2: "))
    (command "line" "_non" A "_non" B "")
    )
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  
  (defun tron ( / c d)
    (setq C (getpoint "Center: "))
    (setq D (getdist "Diameter: "))
    (command "circle" "_non" C D "")
    )
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  
  (defun Hinhchunhat (/ a b c a1 a2 a3)
    (setq A (getpoint "\n First pick: "))
    (initget (+ 1 2 4))
    (setq B (getdist "\n Length: "))
    (initget (+ 1 2 4))
    (setq C (getdist "\n Width: "))
    
    (setq A1 (polar A 0. B))
    (setq A2 (polar A1 (/ pi 2) C))
    (setq A3 (polar A (/ pi 2) C))
    
    (command ".pline" "_non" A "_non" A1 "_non" A2 "_non" A3 "close")
    )
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  
  (or *tst-e* (setq *tst-e* "Thang"))  ; default
  (initget "Thang tRon Hinhchunhat") ; 
  (setq *tst-e* (cond ((getkword (strcat "\n Choose [Thang/tRon/Hinhchunhat] <" *tst-e* ">: "))) (*tst-e*)))
  ((eval (read *tst-e*))) ; since kwords and function names are the same
  )

 

 
Message 4 of 6

pbejse
Mentor
Mentor

@ВeekeeCZ wrote:

Further possible improvements.

  ...
(or *tst-e* (setq *tst-e* "Thang")) ; default (initget "Thang tRon Hinhchunhat") ; (setq *tst-e* (cond ((getkword (strcat "\n Choose [Thang/tRon/Hinhchunhat] <" *tst-e* ">: "))) (*tst-e*))) ((eval (read *tst-e*))) ; since kwords and function names are the same )

 

 

Nooice... 👍

0 Likes
Message 5 of 6

Anonymous
Not applicable

Thank you very much! Perpect!!!!

0 Likes
Message 6 of 6

Anonymous
Not applicable

Many thanks for your reply! ^^

0 Likes