TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Adesu on March 17, 2005, 12:54:20 AM

Title: How to work user input for this program
Post by: Adesu on March 17, 2005, 12:54:20 AM
The scenario for this program,is if in your area drawing there are string,as like 10 20 30 40 .....etc,now you please click 10 20 etc,then the program would ask,what you want to do ( "Select Add Subtracts Divides Multiply"),then ask again where you would put for text in area drawing,the result final would display as gave them input,but in "opt" this program can't work,anyones can help how to solve this script,thanks. :(

Code: [Select]
; cco is stand for create count object
;        Design by Ade Suharna <mteybid@yuasabattery.co.id>
;        15 March 2005
;        Program no.213/03/2005
;        Edit by
(defun c:cco (/ ss ssl cnt ssn opt ttl)
  (prompt "\nCLICK OBJECT TO BE EVALUATION")
  (setq ss (ssget))
  (setq ssl (sslength ss))
  (setq cnt 0)
  (repeat ssl
    (setq ssn (ssname ss cnt))
    (setq sse (entget ssn))
    (setq as1 (atoi (cdr (assoc 1 sse))))  
    (set (read (strcat "ss" (itoa cnt))) as1)
    )
(prompt "Select Add Subtracts Divides Multiply")
(initget " A S D M ")
(setq opt (getkword "\nCHOOSE ONES <A/S/D/M>: "))
(cond ((eq opt "A")(setq opt +))
      ((eq opt "S")(setq opt -))
      ((eq opt "D")(setq opt /))
      ((eq opt "M")(setq opt *))
      )
(if ss
  (cond
    ((eq ssl 1)(alert "\nInvalid selected,not enough to evaluation"))
    ((eq ssl 2)(setq ttl (opt ss0 ss1)))
    ((eq ssl 3)(setq ttl (opt ss0 ss1 ss2)))
    ((eq ssl 4)(setq ttl (opt ss0 ss1 ss2 ss3)))
    ((eq ssl 5)(setq ttl (opt ss0 ss1 ss2 ss3 ss4)))
    ((eq ssl 6)(setq ttl (opt ss0 ss1 ss2 ss3 ss4 ss5)))
    ((eq ssl 7)(setq ttl (opt ss0 ss1 ss2 ss3 ss4 ss5 ss6)))
    ((eq ssl 8)(setq ttl (opt ss0 ss1 ss2 ss3 ss4 ss5 ss6 ss7)))
    ((eq ssl 9)(setq ttl (opt ss0 ss1 ss2 ss3 ss4 ss5 ss6 ss7 ss8)))
    ((eq ssl 10)(setq ttl (opt ss0 ss1 ss2 ss3 ss4 ss5 ss6 ss7 ss8 ss9)))
    ((> ssl 10)(alert "\nSorry your selected,too over"))
    )
  )
  (setq loc (getpoint "\nCLICK LOCATION FOR RESULT OBJECT: "))
  (setq hei 1)
  (command "_text" loc hei "" ttl "")
  (princ ttl)
  )
Title: How to work user input for this program
Post by: Kerry on March 17, 2005, 01:04:23 AM
Adesu,

Do you know how to use the debugger in the Visual Lisp IDE ?
Title: How to work user input for this program
Post by: Kerry on March 17, 2005, 01:11:26 AM
It would help anyone testing or using this if this line

(prompt "\nCLICK OBJECT TO BE EVALUATION")

read

(prompt "\nSelect TEXT to be evaluated.")



... I assume it's text because of this : (assoc 1 sse)  

Is it meant to select text ??

added : and is the value meant to be a string representation of an integer
Title: How to work user input for this program
Post by: Kerry on March 17, 2005, 01:44:02 AM
I have made some serious assumptions here :


look for these markers
;; added kwb
;; revised kwb

Particularly these :
The cnt variable for the ssNo  was not being incremented in the repeat loop
;; revised kwb : quoted the additive and multiplicative symbols

;; revised kwb : changed (setq ttl (opt ....)
;; to ((eval opt) ss0 ss1 ... ... ... )))

Code: [Select]

;;revised as noted : kwb@theSwamp

(defun c:cco (/ ss ssl cnt ssn opt ttl)
  ;; revised kwb
  ;;(prompt "\nCLICK OBJECT TO BE EVALUATION")
  (prompt "\nSelect TEXT to be evaluated.")
  ;; /revised kwb

  (setq ss  (ssget)
        ssl (sslength ss)
        cnt 0
  )
  (repeat ssl
    (setq ssn (ssname ss cnt)
          sse (entget ssn)
          as1 (atoi (cdr (assoc 1 sse)))
    )
    (set (read (strcat "ss" (itoa cnt))) as1)
   
    ;; added kwb
    (setq cnt (1+ cnt))
    ;;/added
  )
  (prompt "Select Add Subtracts Divides Multiply")
  (initget " A S D M ")
  (setq opt (getkword "\nCHOOSE ONES <A/S/D/M>: "))
 
  ;; revised kwb : quoted the additive and multiplicative symbols
  (cond ((eq opt "A") (setq opt '+))
        ((eq opt "S") (setq opt '-))
        ((eq opt "D") (setq opt '/))
        ((eq opt "M") (setq opt '*))
  )  
  ;; /revised kwb :

 
  (if ss
    ;; revised kwb : changed (setq ttl (opt ....)
    ;; to ((eval opt) ss0 ss1 ... ... ... )))
    (cond
      ((eq ssl 1) (alert "\nInvalid selected,not enough to evaluation"))
      ((eq ssl 2) (setq ttl ((eval opt) ss0 ss1)))
      ((eq ssl 3) (setq ttl ((eval opt) ss0 ss1 ss2)))
      ((eq ssl 4) (setq ttl ((eval opt) ss0 ss1 ss2 ss3)))
      ((eq ssl 5) (setq ttl ((eval opt) ss0 ss1 ss2 ss3 ss4)))
      ((eq ssl 6) (setq ttl ((eval opt) ss0 ss1 ss2 ss3 ss4 ss5)))
      ((eq ssl 7) (setq ttl ((eval opt) ss0 ss1 ss2 ss3 ss4 ss5 ss6)))
      ((eq ssl 8) (setq ttl ((eval opt) ss0 ss1 ss2 ss3 ss4 ss5 ss6 ss7)))
      ((eq ssl 9) (setq ttl ((eval opt) ss0 ss1 ss2 ss3 ss4 ss5 ss6 ss7 ss8)))
      ((eq ssl 10)(setq ttl ((eval opt) ss0 ss1 ss2 ss3 ss4 ss5 ss6 ss7 ss8 ss9)))
      ((> ssl 10) (alert "\nSorry your selected,too over"))
    )
  )
  ;; /revised kwb :
 
  ;; revised kwb
;;;  (setq loc (getpoint "\nCLICK LOCATION FOR RESULT OBJECT: ")
;;;        hei 1
;;;  )
  (setq loc (getpoint "\nSelect Location for New Text : ")
        hei 1
  )  
  ;; /revised kwb

  ;; revised kwb
;;;  (command "_text" loc hei "" ttl "" "")
  (command "_text" loc hei "" ttl 0)
  ;; /revised kwb
 
  (princ ttl)
  (princ)
)
Title: How to work user input for this program
Post by: Kerry on March 17, 2005, 02:00:11 AM
.. and just a courtesy note .. can you please add code tags to your posts, they make the code more readable .. well for me anyway.
If you dont know how, please ask.
Title: How to work user input for this program
Post by: Adesu on March 17, 2005, 03:51:44 AM
Quote from: Kerry Brown
.. and just a courtesy note .. can you please add code tags to your posts, thet make the code readable .. well for me anyway.
If you dont know how, please ask.


Hi Kerry Brown,after your revised,that code become work,perfect !!,thanks a lot for your suggest.
I am not understanding what do you mean "can you please add code tags to your posts, thet make the code readable",can you more detail for this your argument,sorry for rather stupid my question
Title: How to work user input for this program
Post by: Mark on March 17, 2005, 04:06:06 AM
Quote from: Adesu
I am not understanding what do you mean "can you please add code tags to your posts, thet make the code readable",can you more detail for this your argument,sorry for rather stupid my question

Have a look here Adesu. http://www.theswamp.org/phpBB2/faq.php?mode=bbcode#5
Title: How to work user input for this program
Post by: Adesu on March 17, 2005, 04:22:39 AM
Quote from: Mark Thomas
Quote from: Adesu
I am not understanding what do you mean "can you please add code tags to your posts, thet make the code readable",can you more detail for this your argument,sorry for rather stupid my question

Have a look here Adesu. http://www.theswamp.org/phpBB2/faq.php?mode=bbcode#5


Hi Mark ,thanks for your suggest,sorry for post before,because I new in this forum,especialy for posting.
by the way,are you not yet sleeping for this time ?
Title: How to work user input for this program
Post by: Mark on March 17, 2005, 04:56:29 AM
Quote from: Adesu
Hi Mark ,thanks for your suggest,sorry for post before,because I new in this forum,especialy for posting.
by the way,are you not yet sleeping for this time ?

Nope, not sleeping.  :cry:   It is going to be a long day!!
Title: How to work user input for this program
Post by: MP on March 17, 2005, 07:01:49 AM
I feel your pain brother, sorry to hear it.
Title: How to work user input for this program
Post by: Kerry on March 17, 2005, 08:12:09 AM
Quote from: Adesu
>>> ,after your revised,that code become work,perfect !!,thanks a lot for your suggest. <<<<


You're welcome.

Good to see you got the code tags working too. :)

Stay well,
Kerry
Title: How to work user input for this program
Post by: daron on March 17, 2005, 08:14:22 AM
Oops! I edited his post and added the code tags, so it could be read.
Title: How to work user input for this program
Post by: MP on March 17, 2005, 08:37:37 AM
Perhaps view this instruction (http://theswamp.org/phpBB2/viewtopic.php?t=4429) Adesu.

Cheers.

:)
Title: How to work user input for this program
Post by: Kerry on March 17, 2005, 08:37:49 AM
most excellent Daron.

kwb
Title: How to work user input for this program
Post by: Adesu on March 17, 2005, 07:58:43 PM
Quote from: MP
Perhaps view this instruction (http://theswamp.org/phpBB2/viewtopic.php?t=4429) Adesu.

Cheers.

:)


Hi Daron and MP,thanks very much for your tutorial and suggest,it mean if we send thread ,as like this
Code: [Select]

(defun.....bla..bla...
.......
(princ)
)

sorry if my question too stupid,what function your add [code] at begin and finish text?
Title: How to work user input for this program
Post by: Adesu on March 17, 2005, 08:04:45 PM
Quote from: Kerry Brown
Adesu,

Do you know how to use the debugger in the Visual Lisp IDE ?


Hi Kerry,yes I am not familiar with  the debugger ,and never use it,would you give me how to use it,thanks for your spend time.
Title: How to work user input for this program
Post by: Kerry on March 17, 2005, 08:18:55 PM
From the Visual Lisp IDE

Select Help from The Menu

Select Visual Lisp Help Topics

When the help file opens select AutoLisp Tutorial.

Read the first 3 Chapters.


That will save us both a lot of aggravation.
Title: How to work user input for this program
Post by: Adesu on March 17, 2005, 10:42:38 PM
Quote from: Kerry Brown
From the Visual Lisp IDE
Select Help from The Menu
Select Visual Lisp Help Topics
When the help file opens select AutoLisp Tutorial.
Read the first 3 Chapters.
That will save us both a lot of aggravation.




On Visual Lisp editor I put a "(setq ss (ssget "x" '((0 . "LINE"))))",and then
I am trying to how you show me ,and I attempt to tested it,now I sort and hightlite "(setq ss (ssget "x" '((0 . "LINE"))))",and then
1.click debug on file menu
2.click add watch...
3.displayed Add watch dialog box with contain "(setq ss   (ssget "x" '((0 . "LINE"))))"
4.click Ok
5.displayed watch dialog box with contain;
  *Last-Value*=
  (setq ss (sget "x" (quote ((0...=<selec....
6.sort or highlite "(setq ss (sget "x" (quote ((0...=<selec....",and then double click
7.displayed Inspeck :PICKSET dialog box with contain
   at first line <Selection set :28>
   at second line
8. sort again or highlite and double click again
9.displayed Acad Line dialog box with contain
  at first line <Entity name : 147fd88>
  at second line {handle} "49" {layer} "0" ...etc

I usually copy clicp "(setq ss (ssget "x" '((0 . "LINE"))))" to Visual Lisp Console and then hit "enter" as like this

_$ (setq ss (ssget "x" '((0 . "LINE"))))
<Selection set: 5c>
_$

How comment you ,is it as you suggest ?