TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: pedroantonio on March 24, 2014, 09:36:50 AM

Title: help with a lisp
Post by: pedroantonio on March 24, 2014, 09:36:50 AM
I am trying to learn some things in lisp so i need help.

I write this code but a lot of things is missing .I want this lisp to do

1) Select a close polyline
2)give sd and sk
3)use the area of the close polyline to calculate D and K


Code - Auto/Visual Lisp: [Select]
  1. (DEFUN C:TEST (/ area sd sk)
  2.  
  3. ;Select a close polyline and use the area to calculate
  4. ;d and k
  5.  
  6.   (SETQ SD ("\ngive sd (example 1.2): ")
  7.   (SETQ SK ("\ngive sk (exmple 0.70 or 70%): ")
  8.   (PRINC (STRCAT "\n D = " ((RTOS (* area sd) 2 2) " sq.m")
  9.                  "\n K = " ((RTOS (* area sk) 2 2) " sq.m")
  10.           )
  11.           (PRINC)
  12.  

Thanks
Title: Re: help with a lisp
Post by: efernal on March 24, 2014, 03:29:01 PM
Code - Auto/Visual Lisp: [Select]
  1. (DEFUN c:test (/ area dxf ent sd sk)
  2.   (IF (AND (SETQ ent (CAR (ENTSEL "\n-> Select a closed polyline : ")))
  3.            (WCMATCH (CDR (ASSOC 0 (SETQ dxf (ENTGET ent)))) "*POLYLINE")
  4.            (MEMBER (CDR (ASSOC 70 dxf)) '(1 129))
  5.       )
  6.     (PROGN
  7.       (INITGET 7)
  8.       (SETQ sd (GETREAL "\n Give sd (example 1.2) : "))
  9.       (INITGET 7)
  10.       (SETQ sk (GETREAL "\n Give sk in % (example 0.70) : "))
  11.       (SETQ area (VLAX-GET-PROPERTY (VLAX-ENAME->VLA-OBJECT ent) 'area))
  12.       (PRINC
  13.         (STRCAT "\n D = " (RTOS (* area sd) 2 2) " sq.m" "\n K = " (RTOS (* area sk) 2 2) " sq.m")
  14.       )
  15.     )
  16.     (PRINC "\n-> No valid polyline selected...")
  17.   )
  18.   (PRINC)
  19. )
  20.  
Title: Re: help with a lisp
Post by: alanjt on March 24, 2014, 03:34:55 PM
You could also use vlax-curve-getArea. Then you wouldn't have to convert it to a vla-object.
Title: Re: help with a lisp
Post by: efernal on March 24, 2014, 04:53:20 PM
As suggested by Alanjt

Code - Auto/Visual Lisp: [Select]
  1. (DEFUN c:test (/ area dxf ent sd sk)
  2.   (IF (AND (SETQ ent (CAR (ENTSEL "\n-> Select a closed polyline : ")))
  3.            (WCMATCH (CDR (ASSOC 0 (SETQ dxf (ENTGET ent)))) "*POLYLINE")
  4.            (MEMBER (CDR (ASSOC 70 dxf)) '(1 129))
  5.       )
  6.     (PROGN
  7.       (INITGET 7)
  8.       (SETQ sd (GETREAL "\n Give sd (example 1.2) : "))
  9.       (INITGET 7)
  10.       (SETQ sk (GETREAL "\n Give sk in % (example 0.70) : "))
  11.       (SETQ area (VLAX-CURVE-GETAREA ent))
  12.       (PRINC
  13.         (STRCAT "\n D = " (RTOS (* area sd) 2 2) " sq.m" "\n K = " (RTOS (* area sk) 2 2) " sq.m")
  14.       )
  15.     )
  16.     (PRINC "\n-> No valid polyline selected...")
  17.   )
  18.   (PRINC)
  19. )
Title: Re: help with a lisp
Post by: pedroantonio on March 24, 2014, 06:00:33 PM
Thank you for the help
Title: Re: help with a lisp
Post by: pedroantonio on March 26, 2014, 12:32:05 PM
i want to update this lisp with few thing and i need help

first i want to add an oprtion menu

1)Choose 1 for this ...
2)Choose 2 for this ...
3)Choose 3 for this ...
4)Choose 4 for this ...

for 1

if Area < 700 sqm then D = 240 sqm    and K = Area * 0.60
if Area >=700 sqm then D = 400 sqm    and K = Area * 0.60
if Area =< 200 sqm then D = Area  sqm    and K = Area * 0.70

for 2

D = Area * 0.80   but max D= 400sqm
K= Area * 0.60

for 3

if Area = 4000 sqm then D = 200 sqm    and K = Area * 0.10
if 4000 sqm < Area =<8000 sqm then D = 200 + (Area - 4000)*0.02    and K = Area * 0.10
if Area > 8000 sqm then D = 280 + (Area - 8000)*0.01    and K = Area * 0.10
if 750 sqm =< Area <1200 sqm then D = 100 + ((Area - 750) / 9)    and K = Area * 0.10
if 1200 sqm =< Area =<2000 sqm then D = 150 + ((Area - 1200) / 16)    and K = Area * 0.10

for 4

Is the code we have already

Thanks
Title: Re: help with a lisp
Post by: Kerry on March 26, 2014, 07:03:04 PM
Untested basic shell.

Code - Auto/Visual Lisp: [Select]
  1.  
  2.  
  3. (defun c:test4
  4.        (/ _option1 _option2 _option3 _option4 area dxf ent sdarea skarea)
  5.   (defun _option1 ()
  6.     (cond ((<= area 200)
  7.            (setq sdarea area
  8.                  skarea (* area 0.7)
  9.            )
  10.           )
  11.           ((< area 700)
  12.            (setq sdarea 240
  13.                  skarea (* area 0.6)
  14.            )
  15.           )
  16.           ((>= area 700)
  17.            (setq sdarea 400
  18.                  skarea (* area 0.6)
  19.            )
  20.           )
  21.     )
  22.   )
  23.   (defun _option2 () (alert "Option 2\nTo be Completed by Client ") (_Option4))
  24.   (defun _option3 () (alert "Option 3\nTo be Completed by Client") (_Option4))
  25.   (defun _option4 ()
  26.     (initget 7)
  27.     (setq sdarea (* area (getreal "\n Give sd (example 1.2) : ")))
  28.     (initget 7)
  29.     (setq skarea (* area (getreal "\n Give sk in % (example 0.70) : ")))
  30.   )
  31.   ;; Main -----
  32.   (if (and (setq ent (car (entsel "\n-> Select a closed polyline : ")))
  33.            (wcmatch (cdr (assoc 0 (setq dxf (entget ent)))) "*POLYLINE")
  34.            (member (cdr (assoc 70 dxf)) '(1 129))
  35.       )
  36.     (progn
  37.       (initget 7)
  38.       (setq area   (vlax-curve-getarea ent)
  39.             option (getint "Select Option 1 to 4 : ")
  40.       )
  41.       (cond ((= option 1) (_Option1))
  42.             ((= option 2) (_Option2))
  43.             ((= option 3) (_Option3))
  44.             ((= option 4) (_Option4))
  45.             (t (alert "Read the prompt, Idiot\nUsing Option 4. ") (_Option4))
  46.       )
  47.       (princ (strcat "\n Selected Area = "
  48.                      (rtos area 2 2)
  49.                      "\n D = "
  50.                      (rtos sdarea 2 2)
  51.                      " sq.m"
  52.                      "\n K = "
  53.                      (rtos skarea 2 2)
  54.                      " sq.m"
  55.              )
  56.       )
  57.     )
  58.     (princ "\n-> No valid polyline selected...")
  59.   )
  60.   (princ)
  61. )
  62.  
Title: Re: help with a lisp
Post by: pedroantonio on March 27, 2014, 02:44:23 AM
Thank you Kerry for the help . I add a start up menu but samething is wrong. I coplete options 2 and option 3 but i need to check the code

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test4
  2.        (/ _option1 _option2 _option3 _option4 area dxf ent sdarea skarea)
  3.   (defun _option1 ()
  4.     (cond ((<= area 200)
  5.            (setq sdarea area
  6.                  skarea (* area 0.7)
  7.            )
  8.           )
  9.           ((< area 700)
  10.            (setq sdarea 240
  11.                  skarea (* area 0.6)
  12.            )
  13.           )
  14.           ((>= area 700)
  15.            (setq sdarea 400
  16.                  skarea (* area 0.6)
  17.            )
  18.           )
  19.     )
  20.   )
  21.   (defun _option2 ()
  22.   (cond ((<= sdarea 400)  ; I don't know if this is correct maxD = 400
  23.            (setq sdarea (* area 0.8)
  24.                  skarea (* area 0.6)
  25.            )
  26.           )          
  27.     )
  28.   )
  29.   (defun _option3 ()
  30.  
  31.     (cond ((<= area 4000)
  32.            (setq sdarea (= 200)
  33.                  skarea (* area 0.10)
  34.            )
  35.           )
  36.       (( 4000 < area =<8000) ; I don't know how to write it
  37.            (setq sdarea (+ 200 ( * 0.02 (- area 4000))) ; please check it  200 + (Area - 4000)*0.02
  38.                  skarea (* area 0.1)
  39.            )
  40.           )
  41.           ((> area 8000)
  42.            (setq sdarea (+ 280 ( * 0.01 (- area 8000))) ; please check it  280 + (Area - 8000)*0.01
  43.                  skarea (* area 0.1)
  44.            )
  45.           )
  46.      (( 750 =< Area < 1200); I don't know how to write it
  47.            (setq sdarea (+ 280 ( / 9 (- area 750))) ; please check it   D = 100 + ((Area - 750) / 9)
  48.                  skarea (* area 0.1)
  49.            )
  50.           )
  51.         (( 1200 =< Area =< 2000); I don't know how to write it
  52.            (setq sdarea (+ 150 ( / 16 (- area 1200))) ; please check it    D = 150 + ((Area - 1200) / 16)
  53.                  skarea (* area 0.1)
  54.            )
  55.           )
  56.     )
  57.   )
  58.  
  59.   (defun _option4 ()
  60.     (initget 7)
  61.     (setq sdarea (* area (getreal "\n Give sd (example 1.2) : ")))
  62.     (initget 7)
  63.     (setq skarea (* area (getreal "\n Give sk in % (example 0.70) : ")))
  64.   )
  65.   ;; Main -----
  66.   (if (and (setq ent (car (entsel "\n-> Select a closed polyline : ")))
  67.            (wcmatch (cdr (assoc 0 (setq dxf (entget ent)))) "*POLYLINE")
  68.            (member (cdr (assoc 70 dxf)) '(1 129))
  69.       )
  70.     (progn
  71.       (initget 7)
  72.   (PROMPT
  73.     "\n choose option :
  74.  
  75.   1. Choose 1 for this ...
  76.   2. Choose 2 for this ...
  77.   3. Choose 3 for this ...
  78.   4. Choose 4 for this ...
  79.  
  80. " )
  81.       (setq area   (vlax-curve-getarea ent)
  82.             option (getint "Select Option 1 to 4 : ")
  83.       )
  84.       (cond ((= option 1) (_Option1))
  85.             ((= option 2) (_Option2))
  86.             ((= option 3) (_Option3))
  87.             ((= option 4) (_Option4))
  88.             (t (alert "Read the prompt, Idiot\nUsing Option 4. ") (_Option4))
  89.       )
  90.       (princ (strcat "\n Selected Area = "
  91.                      (rtos area 2 2)
  92.                      "\n D = "
  93.                      (rtos sdarea 2 2)
  94.                      " sq.m"
  95.                      "\n K = "
  96.                      (rtos skarea 2 2)
  97.                      " sq.m"
  98.              )
  99.       )
  100.     )
  101.     (princ "\n-> No valid polyline selected...")
  102.   )
  103.   (princ)
  104. )
  105.  
  106.  


Thanks
Title: Re: help with a lisp
Post by: pedroantonio on March 27, 2014, 12:07:27 PM
i think i fix it
Title: Re: help with a lisp
Post by: Kerry on March 27, 2014, 12:30:03 PM

I can't make time to look closely at the moment but option 2 seems incorrect.

I'll have a look when I finish up what I'm doing.
Title: Re: help with a lisp
Post by: pedroantonio on March 27, 2014, 12:42:22 PM
Kerry if you can fix option 3. I fix option 2 but in option 3 i have calculation problems

Code - Auto/Visual Lisp: [Select]
  1.   (defun _option3 ()
  2.  
  3.       (cond ((= area 4000)
  4.            (setq sdarea (= 200)
  5.                  skarea (* area 0.10)
  6.            )
  7.           )
  8.       (( 4000 < area =<8000) ; I don't know how to write it
  9.            (setq sdarea (+ 200 ( * 0.02 (- area 4000))) ; please check it  200 + (Area - 4000)*0.02
  10.                  skarea (* area 0.1)
  11.            )
  12.           )
  13.           ((area > 8000)
  14.            (setq sdarea (+ 280 ( * 0.01 (- area 8000))) ; please check it  280 + (Area - 8000)*0.01
  15.                  skarea (* area 0.1)
  16.            )
  17.           )
  18.      (( 750 =< Area < 1200); I don't know how to write it
  19.            (setq sdarea (+ 280 ( /  (- area 750) 9)) ; please check it   D = 100 + ((Area - 750) / 9)
  20.                  skarea (* area 0.1)
  21.            )
  22.           )
  23.         (( 1200 =< Area =< 2000); I don't know how to write it
  24.            (setq sdarea (+ 150 ( / (- area 1200) 16)) ; please check it    D = 150 + ((Area - 1200) / 16)
  25.                  skarea (* area 0.1)
  26.            )
  27.           )
  28.     )
  29.   )
  30.  

thanks
Title: Re: help with a lisp
Post by: pedroantonio on March 27, 2014, 01:46:15 PM
Kerry , I change the option 3 code but i have this problem

for    1200 < Area < = 2000      D = 150 + ((Area - 1200) / 16)    and K = Area * 0.10

but

for    2000 < Area < 40000      D = 0   and  K =0


I dont know how to write it

Please check all the functions

if Area = 4000 sqm then D = 200 sqm    and K = Area * 0.10
if 4000 sqm < Area =<8000 sqm then D = 200 + (Area - 4000)*0.02    and K = Area * 0.10
if Area > 8000 sqm then D = 280 + (Area - 8000)*0.01    and K = Area * 0.10
if 750 sqm =< Area <1200 sqm then D = 100 + ((Area - 750) / 9)    and K = Area * 0.10
if 1200 sqm =< Area =<2000 sqm then D = 150 + ((Area - 1200) / 16)    and K = Area * 0.10



Code - Auto/Visual Lisp: [Select]
  1. (defun _option3 ()
  2.       (cond ((= area 4000)
  3.            (setq sdarea 200
  4.                  skarea (* area 0.1)
  5.            )
  6.           )
  7.           ((> area 4000)
  8.            (setq sdarea (+ 200 ( * 0.02 (- area 4000)))
  9.                  skarea (* area 0.1)
  10.            )
  11.           )
  12.           ((<= area 8000)
  13.            (setq sdarea (+ 200 ( * 0.02 (- area 4000)))
  14.                  skarea (* area 0.1)
  15.            )
  16.           )
  17.           ((> area 8000)
  18.            (setq sdarea (+ 280 ( * 0.01 (- area 8000)))
  19.                  skarea (* area 0.1)
  20.            )
  21.           )
  22.           ((>= area 750)
  23.            (setq sdarea (+ 100 ( / (- area 750) 9))
  24.                  skarea (* area 0.1)
  25.            )
  26.           )
  27.           ((<= area 1200)
  28.            (setq sdarea (+ 100 ( / (- area 750) 9))
  29.                  skarea (* area 0.1)
  30.            )
  31.           )
  32.            ((> area 1200)
  33.            (setq sdarea (+ 150 ( / (- area 1200) 16))
  34.                  skarea (* area 0.1)
  35.            )
  36.           )
  37.            ((<= area 2000)
  38.            (setq sdarea (+ 150 ( / (- area 1200) 16))
  39.                  skarea (* area 0.1)
  40.            )
  41.           )
  42.            ((> area 2000)
  43.            (setq sdarea 0
  44.                  skarea 0
  45.            )
  46.           )
  47.            ((< area 4000)
  48.            (setq sdarea 0
  49.                  skarea 0
  50.            )
  51.           )
  52.     )
  53.   )
  54.  
  55.  

thanks
Title: Re: help with a lisp
Post by: Kerry on March 27, 2014, 03:09:57 PM
Have a play with this for testing ... best not to change ( kdub:assert-expect <.> <.> )
Build your own tests.

Code - Auto/Visual Lisp: [Select]
  1.  
  2.  
  3. ;;;------------------------------------------------------------------
  4. ;;;------------------------------------------------------------------
  5. ;;;
  6. ;;; (kdub:assert-expect <teststatement> <expected>)
  7. ;;; kwb 20020715
  8. ;;; <teststatement> argument must be quoted
  9. ;|
  10. ( kdub:assert-expect '(+ 2 2) 4)
  11. ( kdub:assert-expect '(+ 2 2) (+ 1 3))
  12. |;
  13. (defun kdub:assert-expect (teststatement expected / catchit tmp)
  14.         (setq catchit (vl-catch-all-apply
  15.                         '=
  16.                         (list expected (setq tmp (eval teststatement)))
  17.                       )
  18.         )
  19.       )
  20.     ;; else
  21.     (if (not catchit)
  22.       (progn (mapcar 'princ
  23.                      (list "\n **** Assertion Failure : "
  24.                            (vl-prin1-to-string teststatement)
  25.                            "\n expected : "
  26.                            (vl-prin1-to-string expected)
  27.                            " returned : "
  28.                            (vl-prin1-to-string tmp)
  29.                      )
  30.              )
  31.              ;; decide what to do here later ?
  32.              (if *assert-debug_on*
  33.                (princ "  ")
  34.                (vl-exit-with-error (strcat "We bombed! "))
  35.              )
  36.       )
  37.       (mapcar 'princ
  38.               (list "\nAssertion-expect : "
  39.                     (vl-prin1-to-string teststatement)
  40.                     " returned : "
  41.                     (vl-prin1-to-string tmp)
  42.               )
  43.       )
  44.     )
  45.   )
  46.   (princ)
  47. )
  48. ;;;------------------------------------------------------------------
  49. ;;;------------------------------------------------------------------
  50. ;;;
  51.  


These are the tests I used for _option1()
You will need to load _option1() into memory ...
Code - Auto/Visual Lisp: [Select]
  1. (setq area 1)
  2. (_option1)
  3. ( kdub:assert-expect 'sdarea 1)
  4. ( kdub:assert-expect 'skarea 1)  ; a failing test
  5.  
  6. (setq area 199)
  7. (_option1)
  8. ( kdub:assert-expect 'sdarea area)
  9. ( kdub:assert-expect 'skarea (* area 0.7))
  10.  
  11. (setq area 600)
  12. (_option1)
  13. ( kdub:assert-expect 'sdarea 240)
  14. ( kdub:assert-expect 'skarea (* area 0.6))
  15.  
  16. (setq area 701)
  17. (_option1)
  18. ( kdub:assert-expect 'sdarea 400)
  19. ( kdub:assert-expect 'skarea (* area 0.6))
  20.  
  21.  

Just comment out the tests when you're happy.
You can uncomment them when you make changes to your code under test in the future ....

Added:
Testing like this is one reason to keep your functions compact.
Title: Re: help with a lisp
Post by: Kerry on March 27, 2014, 03:17:01 PM
Topographer,

Lets try a little self help.

Can you write tests for _option3()
Then we can look at the ones that fail.

Regards,


added:

See if something like these conditionals brings you joy
Code - Auto/Visual Lisp: [Select]
  1.  
  2. (= area 4000)
  3. (and (> area 4000) (<= area 8000))
  4. (> area 8000)
  5. (and (>= area 750) (< area 1200))
  6. (and (>= area 1200) (<= area 2000))
  7.  
  8.  

These are the conditionals you specified.
There seems to be some gaps in the range that will not be evaluated.
Title: Re: help with a lisp
Post by: pedroantonio on March 27, 2014, 03:50:03 PM
I write this

Code - Auto/Visual Lisp: [Select]
  1. (defun _option3 ()
  2.       (cond  (and (>= area 750) (<= area 1200)
  3.            (setq sdarea (+ 100 ( / (- area 750) 9))
  4.                  skarea (* area 0.1)
  5.            )
  6.           )
  7.                    
  8.            (and (> area 1200) (<= area 2000)
  9.            (setq sdarea (+ 150 ( / (- area 1200) 16))
  10.                  skarea (* area 0.1)
  11.            )
  12.           )
  13.            (and (> area 2000) (< area 4000)
  14.            (setq sdarea 0
  15.                  skarea 0
  16.                     )
  17.           )
  18.  
  19.            ((= area 4000)
  20.            (setq sdarea 200
  21.                  skarea (* area 0.1)
  22.            )
  23.           )
  24.           (and (> area 4000) (<= area 8000)
  25.            (setq sdarea (+ 200 ( * 0.02 (- area 4000)))
  26.                  skarea (* area 0.1)
  27.            )
  28.           )
  29.          
  30.           ((> area 8000)
  31.            (setq sdarea (+ 280 ( * 0.01 (- area 8000)))
  32.                  skarea (* area 0.1)
  33.            )
  34.           )        
  35.     )
  36.   )
  37.  
  38.  

but i have problem  with this

for    2000 < Area < 40000    --->  D = 0   and  K =0

example

for area 3950 sqm  --- >  D= 455.56 and K= 395 , understand the fuction as   Area >=750 .

I don't know what to do
Title: Re: help with a lisp
Post by: Kerry on March 27, 2014, 03:57:52 PM

There are a few number ranges that are not evaluated.

Draw yourself a numberLine and mark off the ranges you ARE testing.
http://en.wikipedia.org/wiki/Number_line

You may need to add conditionals and assignments for those ranges ...
Title: Re: help with a lisp
Post by: Kerry on March 27, 2014, 04:01:16 PM
It looks like you are missing some parenthesis in your conditional statement

(cond
    <HERE> (and (>= area 750) (<= area 1200) <and HERE>

        .. do stuff
     )
    .. more conditionals
)
Title: Re: help with a lisp
Post by: pedroantonio on March 27, 2014, 04:16:14 PM
I add the parenthesis
The lisp run and when i select 3 option  gives me  this error !!!
; error: bad argument type: numberp: nil

Code - Auto/Visual Lisp: [Select]
  1.  (defun c:test4
  2.        (/ _option1 _option2 _option3 _option4 area dxf ent sdarea skarea)
  3.   (defun _option1 ()
  4.     (cond ((<= area 200)
  5.            (setq sdarea area
  6.                  skarea (* area 0.7)
  7.            )
  8.           )
  9.           ((< area 700)
  10.            (setq sdarea 240
  11.                  skarea (* area 0.6)
  12.            )
  13.           )
  14.           ((>= area 700)
  15.            (setq sdarea 400
  16.                  skarea (* area 0.6)
  17.            )
  18.           )
  19.     )
  20.   )
  21.   (defun _option2 ()
  22.   (cond ((<= sdarea 400)  ; I don't know if this is correct maxD = 400
  23.            (setq sdarea (* area 0.8)
  24.                  skarea (* area 0.6)
  25.            )
  26.           )          
  27.     )
  28.   )
  29.   (defun _option3 ()
  30.  
  31.       (cond ((and (>= area 750) (<= area 1200)
  32.            (setq sdarea (+ 100 ( / (- area 750) 9))
  33.                  skarea (* area 0.1)
  34.            )
  35.           )
  36.                    
  37.            ((and (> area 1200) (<= area 2000)
  38.            (setq sdarea (+ 150 ( / (- area 1200) 16))
  39.                  skarea (* area 0.1)
  40.            )
  41.           )
  42.            ((and (> area 2000) (< area 4000)
  43.            (setq sdarea 0
  44.                  skarea 0
  45.                     )
  46.           )
  47.  
  48.            ((= area 4000)
  49.            (setq sdarea 200
  50.                  skarea (* area 0.1)
  51.            )
  52.           )
  53.           ((and (> area 4000) (<= area 8000)
  54.            (setq sdarea (+ 200 ( * 0.02 (- area 4000)))
  55.                  skarea (* area 0.1)
  56.            )
  57.           )
  58.          
  59.           ((> area 8000)
  60.            (setq sdarea (+ 280 ( * 0.01 (- area 8000)))
  61.                  skarea (* area 0.1)
  62.              )
  63.            )
  64.          )
  65.        )
  66.      )
  67.     )
  68.   )
  69. )
  70.  
  71.   (defun _option4 ()
  72.     (initget 7)
  73.     (setq sdarea (* area (getreal "\n Give sd (example 1.2) : ")))
  74.     (initget 7)
  75.     (setq skarea (* area (getreal "\n Give sk in % (example 0.70) : ")))
  76.   )
  77.   ;; Main -----
  78.   (if (and (setq ent (car (entsel "\n-> Select a closed polyline : ")))
  79.            (wcmatch (cdr (assoc 0 (setq dxf (entget ent)))) "*POLYLINE")
  80.            (member (cdr (assoc 70 dxf)) '(1 129))
  81.       )
  82.     (progn
  83.       (initget 7)
  84.   (PROMPT
  85.     "\n choose option :
  86.  
  87.   1. Choose 1 for this ...
  88.   2. Choose 2 for this ...
  89.   3. Choose 3 for this ...
  90.   4. Choose 4 for this ...
  91.  
  92. " )
  93.       (setq area   (vlax-curve-getarea ent)
  94.             option (getint "Select Option 1 to 4 : ")
  95.       )
  96.       (cond ((= option 1) (_Option1))
  97.             ((= option 2) (_Option2))
  98.             ((= option 3) (_Option3))
  99.             ((= option 4) (_Option4))
  100.             (t (alert "Read the prompt, Idiot\nUsing Option 4. ") (_Option4))
  101.       )
  102.       (princ (strcat "\n Selected Area = "
  103.                      (rtos area 2 2)
  104.                      "\n D = "
  105.                      (rtos sdarea 2 2)
  106.                      " sq.m"
  107.                      "\n K = "
  108.                      (rtos skarea 2 2)
  109.                      " sq.m"
  110.              )
  111.       )
  112.     )
  113.     (princ "\n-> No valid polyline selected...")
  114.   )
  115.   (princ)
  116. )
  117.  
  118.  
  119.  
Title: Re: help with a lisp
Post by: Kerry on March 27, 2014, 04:22:06 PM
I add the parenthesis and now gives me

< .. >

Have another look ... your conditional test is mixed with the assignment code.
Title: Re: help with a lisp
Post by: pedroantonio on March 27, 2014, 04:30:53 PM
I update the code but i still have the same problom with the option 3
; error: bad argument type: numberp: nil

Code - Auto/Visual Lisp: [Select]
  1.  (defun c:test4
  2.        (/ _option1 _option2 _option3 _option4 area dxf ent sdarea skarea)
  3.   (defun _option1 ()
  4.     (cond ((<= area 200)
  5.            (setq sdarea area
  6.                  skarea (* area 0.7)
  7.            )
  8.           )
  9.           ((< area 700)
  10.            (setq sdarea 240
  11.                  skarea (* area 0.6)
  12.            )
  13.           )
  14.           ((>= area 700)
  15.            (setq sdarea 400
  16.                  skarea (* area 0.6)
  17.            )
  18.           )
  19.     )
  20.   )
  21.   (defun _option2 ()
  22.     (cond ((<= area 2000)
  23.             (setq sdarea  (* area 0.8)
  24.              skarea (* area 0.6)
  25.            )
  26.           )    
  27.          ((> area 2000)
  28.            (setq sdarea (+ 400 ( * 0.05 (- area 2000)))
  29.                  skarea (* area 0.1)
  30.            )
  31.           )    
  32.     )
  33.   )
  34.   (defun _option3 ()
  35.  
  36.       (cond ((and (>= area 750) (<= area 1200)
  37.            (setq sdarea (+ 100 ( / (- area 750) 9))
  38.                  skarea (* area 0.1)
  39.            )
  40.           )
  41.  
  42.            ((and (> area 1200) (<= area 2000)
  43.            (setq sdarea (+ 150 ( / (- area 1200) 16))
  44.                  skarea (* area 0.1)
  45.            )
  46.           )
  47.            ((and (> area 2000) (< area 4000)
  48.            (setq sdarea 0
  49.                  skarea 0
  50.                     )
  51.           )
  52.  
  53.            ((= area 4000)
  54.            (setq sdarea 200
  55.                  skarea (* area 0.1)
  56.            )
  57.           )
  58.           ((and (> area 4000) (<= area 8000)
  59.            (setq sdarea (+ 200 ( * 0.02 (- area 4000)))
  60.                  skarea (* area 0.1)
  61.            )
  62.           )
  63.  
  64.           ((> area 8000)
  65.            (setq sdarea (+ 280 ( * 0.01 (- area 8000)))
  66.                  skarea (* area 0.1)
  67.              )
  68.            )
  69.          )
  70.        )
  71.      )
  72.     )
  73.   )
  74. )
  75.  
  76.   (defun _option4 ()
  77.     (initget 7)
  78.     (setq sdarea (* area (getreal "\n Give sd (example 1.2) : ")))
  79.     (initget 7)
  80.     (setq skarea (* area (getreal "\n Give sk in % (example 0.70) : ")))
  81.   )
  82.   ;; Main -----
  83.   (if (and (setq ent (car (entsel "\n-> Select a closed polyline : ")))
  84.            (wcmatch (cdr (assoc 0 (setq dxf (entget ent)))) "*POLYLINE")
  85.            (member (cdr (assoc 70 dxf)) '(1 129))
  86.       )
  87.     (progn
  88.       (initget 7)
  89.   (PROMPT
  90.     "\n choose option :
  91.  
  92.   1. Choose 1 for this ...
  93.   2. Choose 2 for this ...
  94.   3. Choose 3 for this ...
  95.   4. Choose 4 for this ...
  96.  
  97. " )
  98.       (setq area   (vlax-curve-getarea ent)
  99.             option (getint "Select Option 1 to 4 : ")
  100.       )
  101.       (cond ((= option 1) (_Option1))
  102.             ((= option 2) (_Option2))
  103.             ((= option 3) (_Option3))
  104.             ((= option 4) (_Option4))
  105.             (t (alert "Read the prompt, Idiot\nUsing Option 4. ") (_Option4))
  106.       )
  107.       (princ (strcat "\n Selected Area = "
  108.                      (rtos area 2 2)
  109.                      "\n D = "
  110.                      (rtos sdarea 2 2)
  111.                      " sq.m"
  112.                      "\n K = "
  113.                      (rtos skarea 2 2)
  114.                      " sq.m"
  115.              )
  116.       )
  117.     )
  118.     (princ "\n-> No valid polyline selected...")
  119.   )
  120.   (princ)
  121. )
  122.  
  123.  
  124.  
Title: Re: help with a lisp
Post by: Kerry on March 27, 2014, 04:33:40 PM

Try something like this for _option2
Code - Auto/Visual Lisp: [Select]
  1. (defun _option2 ()
  2.   (cond (area
  3.          (setq sdarea (min 400.0 (* area 0.8))
  4.                skarea (* area 0.6)
  5.          )
  6.         )
  7.   )
  8. )
Title: Re: help with a lisp
Post by: Kerry on March 27, 2014, 04:35:56 PM

Try this formatting for option3
I haven't looked at the logic

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun _option3 ()
  3.      (cond ((and (>= area 750) (<= area 1200))
  4.             (setq sdarea (+ 100 (/ (- area 750) 9))
  5.                   skarea (* area 0.1)
  6.             )
  7.            )
  8.            ((and (> area 1200) (<= area 2000))
  9.             (setq sdarea (+ 150 (/ (- area 1200) 16))
  10.                   skarea (* area 0.1)
  11.             )
  12.            )
  13.            ((and (> area 2000) (< area 4000))
  14.             (setq sdarea 0
  15.                   skarea 0
  16.             )
  17.            )
  18.            ((= area 4000)
  19.             (setq sdarea 200
  20.                   skarea (* area 0.1)
  21.             )
  22.            )
  23.            ((and (> area 4000) (<= area 8000))
  24.             (setq sdarea (+ 200 (* 0.02 (- area 4000)))
  25.                   skarea (* area 0.1)
  26.             )
  27.            )
  28.            ((> area 8000)
  29.             (setq sdarea (+ 280 (* 0.01 (- area 8000)))
  30.                   skarea (* area 0.1)
  31.             )
  32.            )
  33.      )
  34.    )
  35.  
  36.  
Title: Re: help with a lisp
Post by: pedroantonio on March 27, 2014, 04:44:59 PM
Thank you Kerry .Now the lisp works fine. Can you explain me were was the mistake. I had exactly the same function before and not working properly !!!

Title: Re: help with a lisp
Post by: Kerry on March 27, 2014, 04:50:30 PM
Thank you Kerry .Now the lisp works fine. Can you explain me were was the mistake. I had exactly the same function before and not working properly !!!
The error was in the parenthesis.
Have a look at this Post reply
It looks like you are missing some parenthesis in your conditional statement

(cond
    <HERE> (and (>= area 750) (<= area 1200) <and HERE>

        .. do stuff
     )
    .. more conditionals
)


Did you build tests for each conditional ?
If you fix the edge cases and the missing ranges you may not need to look at the code again after testing.

Title: Re: help with a lisp
Post by: pedroantonio on March 27, 2014, 05:16:08 PM
Kerry , The only problem i have is with this

Code - Auto/Visual Lisp: [Select]
  1. ((and (>= area 750) (<= area 1200))
  2.             (setq sdarea (+ 100 (/ (- area 750) 9))
  3.                   skarea (* area 0.1)
  4.             )
  5.            )
  6.  

For area = 750 and i change the code to this

Code - Auto/Visual Lisp: [Select]
  1. ((and (<= 750 area) (<= area 1200))
  2.             (setq sdarea (+ 100 (/ (- area 750) 9))
  3.                   skarea (* area 0.1)
  4.             )
  5.            )
  6.  

I test it and work. What is your opinion ?

Thanks
Title: Re: help with a lisp
Post by: Kerry on March 27, 2014, 05:19:47 PM
< .. >
I test it and work. What is your opinion ?

Thanks

The logic is similar I believe ... just different test values.
Title: Re: help with a lisp
Post by: pedroantonio on March 27, 2014, 05:31:58 PM
Kerry, Option 3 crass again for area = 750  i dont know why

; error: bad argument type: numberp: nil


Code - Auto/Visual Lisp: [Select]
  1.  (defun c:test4
  2.        (/ _option1 _option2 _option3 _option4 area dxf ent sdarea skarea)
  3.   (defun _option1 ()
  4.     (cond ((<= area 200)
  5.            (setq sdarea area
  6.                  skarea (* area 0.7)
  7.            )
  8.           )
  9.           ((< area 700)
  10.            (setq sdarea 240
  11.                  skarea (* area 0.6)
  12.            )
  13.           )
  14.           ((>= area 700)
  15.            (setq sdarea 400
  16.                  skarea (* area 0.6)
  17.            )
  18.           )
  19.     )
  20.   )
  21.   (defun _option2 ()
  22.     (cond ((<= area 2000)
  23.             (setq sdarea  (* area 0.8)
  24.              skarea (* area 0.6)
  25.            )
  26.           )    
  27.          ((> area 2000)
  28.            (setq sdarea (+ 400 ( * 0.05 (- area 2000)))
  29.                  skarea (* area 0.1)
  30.            )
  31.           )    
  32.     )
  33.   )
  34.  
  35. (defun _option3 ()
  36.      (cond ((and (>= area 750) (<= area 1200))
  37.             (setq sdarea (+ 100 (/ (- area 750) 9))
  38.                   skarea (* area 0.1)
  39.             )
  40.            )
  41.            ((and (> area 1200) (<= area 2000))
  42.             (setq sdarea (+ 150 (/ (- area 1200) 16))
  43.                   skarea (* area 0.1)
  44.             )
  45.            )
  46.            ((and (> area 2000) (< area 4000))
  47.             (setq sdarea 0
  48.                   skarea 0
  49.             )
  50.            )
  51.            ((= area 4000)
  52.             (setq sdarea 200
  53.                   skarea (* area 0.1)
  54.             )
  55.            )
  56.            ((and (> area 4000) (<= area 8000))
  57.             (setq sdarea (+ 200 (* 0.02 (- area 4000)))
  58.                   skarea (* area 0.1)
  59.             )
  60.            )
  61.            ((> area 8000)
  62.             (setq sdarea (+ 280 (* 0.01 (- area 8000)))
  63.                   skarea (* area 0.1)
  64.             )
  65.            )
  66.      )
  67.    )
  68.  
  69.   (defun _option4 ()
  70.     (initget 7)
  71.     (setq sdarea (* area (getreal "\n Give sd (example 1.2) : ")))
  72.     (initget 7)
  73.     (setq skarea (* area (getreal "\n Give sk in % (example 0.70) : ")))
  74.   )
  75.   ;; Main -----
  76.   (if (and (setq ent (car (entsel "\n-> Select a closed polyline : ")))
  77.            (wcmatch (cdr (assoc 0 (setq dxf (entget ent)))) "*POLYLINE")
  78.            (member (cdr (assoc 70 dxf)) '(1 129))
  79.       )
  80.     (progn
  81.       (initget 7)
  82.   (PROMPT
  83.     "\n choose option :
  84.  
  85.   1. Choose 1 for this ...
  86.   2. Choose 2 for this ...
  87.   3. Choose 3 for this ...
  88.   4. Choose 4 for this ...
  89.  
  90. " )
  91.       (setq area   (vlax-curve-getarea ent)
  92.             option (getint "Select Option 1 to 4 : ")
  93.       )
  94.       (cond ((= option 1) (_Option1))
  95.             ((= option 2) (_Option2))
  96.             ((= option 3) (_Option3))
  97.             ((= option 4) (_Option4))
  98.             (t (alert "Read the prompt, Idiot\nUsing Option 4. ") (_Option4))
  99.       )
  100.       (princ (strcat "\n Selected Area = "
  101.                      (rtos area 2 2)
  102.                      "\n D = "
  103.                      (rtos sdarea 2 2)
  104.                      " sq.m"
  105.                      "\n K = "
  106.                      (rtos skarea 2 2)
  107.                      " sq.m"
  108.              )
  109.       )
  110.     )
  111.     (princ "\n-> No valid polyline selected...")
  112.   )
  113.   (princ)
  114. )
  115.  
  116.  
Title: Re: help with a lisp
Post by: Kerry on March 27, 2014, 05:42:41 PM

is area an integer
area = 750

or a real at 749.9999999999998

I'd close AutoCAD and reload the code.

Have you written tests yet ?

Where does the code crash .. on which line
I assume you're testing in VLIDE with Break on Error toggled ON and using Last Break Source Ctrl-F9 after the crash.
Title: Re: help with a lisp
Post by: pedroantonio on March 27, 2014, 06:03:59 PM
I change the code with this and work fine

Code - Auto/Visual Lisp: [Select]
  1.  (defun _option3 ()
  2.            (cond ((= area 750)
  3.             (setq sdarea 100
  4.                   skarea (* area 0.1)
  5.             )
  6.            )
  7.             ((and (> area 750) (<= area 1200))
  8.             (setq sdarea (+ 100 (/ (- area 750) 9))
  9.                   skarea (* area 0.1)
  10.             )
  11.            )
  12.                       ((and (> area 1200) (<= area 2000))
  13.             (setq sdarea (+ 150 (/ (- area 1200) 16))
  14.                   skarea (* area 0.1)
  15.             )
  16.            )
  17.            ((and (> area 2000) (< area 4000))
  18.             (setq sdarea 0
  19.                   skarea 0
  20.             )
  21.            )
  22.            ((= area 4000)
  23.             (setq sdarea 200
  24.                   skarea (* area 0.1)
  25.             )
  26.            )
  27.            ((and (> area 4000) (<= area 8000))
  28.             (setq sdarea (+ 200 (* 0.02 (- area 4000)))
  29.                   skarea (* area 0.1)
  30.             )
  31.            )
  32.            ((> area 8000)
  33.             (setq sdarea (+ 280 (* 0.01 (- area 8000)))
  34.                   skarea (* area 0.1)
  35.             )
  36.            )
  37.      )
  38.    )
  39.  
  40.  

Thank you Kerry
Title: Re: help with a lisp
Post by: Kerry on March 28, 2014, 04:39:20 AM
I change the code with this and work fine

< .. >

Thank you Kerry


Great. Glad I could help.

Just an observation :
I notice that the code you posted is not well formatted.
I'd suggest that use the VLIDE to format your code. A lot of the problems you have will be resolved by just accepting the formatting provided. Sometimes unbalanced statements are a little more obvious.

This is your code back ... just reformatted. You can see the flow a little easier because the 'paragraphs' line up a little better. This makes it easier to find faults in the logic.

In some regards VLIDE is a crap editor and it's disappointing that AutoDesk have not improved it in the last 15 years but it is a resource we should make the most of.

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun _option3 ()
  3.   (cond ((= area 750)
  4.          (setq sdarea 100
  5.                skarea (* area 0.1)
  6.          )
  7.         )
  8.         ((and (> area 750) (<= area 1200))
  9.          (setq sdarea (+ 100 (/ (- area 750) 9))
  10.                skarea (* area 0.1)
  11.          )
  12.         )
  13.         ((and (> area 1200) (<= area 2000))
  14.          (setq sdarea (+ 150 (/ (- area 1200) 16))
  15.                skarea (* area 0.1)
  16.          )
  17.         )
  18.         ((and (> area 2000) (< area 4000))
  19.          (setq sdarea 0
  20.                skarea 0
  21.          )
  22.         )
  23.         ((= area 4000)
  24.          (setq sdarea 200
  25.                skarea (* area 0.1)
  26.          )
  27.         )
  28.         ((and (> area 4000) (<= area 8000))
  29.          (setq sdarea (+ 200 (* 0.02 (- area 4000)))
  30.                skarea (* area 0.1)
  31.          )
  32.         )
  33.         ((> area 8000)
  34.          (setq sdarea (+ 280 (* 0.01 (- area 8000)))
  35.                skarea (* area 0.1)
  36.          )
  37.         )
  38.   )
  39. )
  40.  
  41.  ;|«Visual LISP© Format Options»
  42. (80 2 45 2 nil "end of " 80 45 1 0 nil nil nil nil T)
  43. ;*** DO NOT add text below the comment! ***|;
  44.  

Regards,
Title: Re: help with a lisp
Post by: CAB on March 28, 2014, 06:07:37 AM
Here is an observation; on options 1 & 2 you addresses the condition where the area was below a minimum value but in condition 3 you did not.
See my changes where option 3 has an error trap for values below 750.
Note also that condition statements will stop evaluating the conditions when one is true.
Therefore you do not need to bracket the value like
Code: [Select]
(and (> area 2000) (< area 4000))when you have already dealt with values below 2000 because the processing will never get this far for values <= 2000.
See my changes there too.
Lastly the last condition can simply be True and not
Code: [Select]
(> area 8000) as all other conditions have been addressed.

I also changed you user input for options 1 - 4 to use getKword instead of getinit.
This is a personal preference.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test4 (/ _option1 _option2 _option3 _option4 area dxf ent sdarea skarea)
  2.   (defun _option1 ()
  3.     (cond ((<= area 200)
  4.            (setq sdarea area
  5.                  skarea (* area 0.7)
  6.            )
  7.           )
  8.           ((< area 700)
  9.            (setq sdarea 240
  10.                  skarea (* area 0.6)
  11.            )
  12.           )
  13.           (
  14.            (setq sdarea 400
  15.                  skarea (* area 0.6)
  16.            )
  17.           )
  18.     )
  19.   )
  20.   (defun _option2 ()
  21.     (cond ((<= area 2000)
  22.            (setq sdarea (* area 0.8)
  23.                  skarea (* area 0.6)
  24.            )
  25.           )
  26.           (t
  27.            (setq sdarea (+ 400 (* 0.05 (- area 2000)))
  28.                  skarea (* area 0.1)
  29.            )
  30.           )
  31.     )
  32.   )
  33.  
  34.   (defun _option3 ()
  35.     (cond ((< area 750)
  36.            (princ "\nERROR: Area is too small")
  37.           )
  38.           ((= area 750)
  39.            (setq sdarea 100
  40.                  skarea (* area 0.1)
  41.            )
  42.           )
  43.           ((<= area 1200)
  44.            (setq sdarea (+ 100 (/ (- area 750) 9))
  45.                  skarea (* area 0.1)
  46.            )
  47.           )
  48.           ((<= area 2000)
  49.            (setq sdarea (+ 150 (/ (- area 1200) 16))
  50.                  skarea (* area 0.1)
  51.            )
  52.           )
  53.           ((< area 4000)
  54.            (setq sdarea 0
  55.                  skarea 0
  56.            )
  57.           )
  58.           ((= area 4000)
  59.            (setq sdarea 200
  60.                  skarea (* area 0.1)
  61.            )
  62.           )
  63.           ((<= area 8000)
  64.            (setq sdarea (+ 200 (* 0.02 (- area 4000)))
  65.                  skarea (* area 0.1)
  66.            )
  67.           )
  68.           (t
  69.            (setq sdarea (+ 280 (* 0.01 (- area 8000)))
  70.                  skarea (* area 0.1)
  71.            )
  72.           )
  73.     )
  74.   )
  75.  
  76.   (defun _option4 ()
  77.     (initget 7)
  78.     (setq sdarea (* area (getreal "\n Give sd (example 1.2) : ")))
  79.     (initget 7)
  80.     (setq skarea (* area (getreal "\n Give sk in % (example 0.70) : ")))
  81.   )
  82.  
  83.  
  84.  
  85.   ;; Main -----
  86.   (if (and (setq ent (car (entsel "\n-> Select a closed polyline : ")))
  87.            (wcmatch (cdr (assoc 0 (setq dxf (entget ent)))) "*POLYLINE")
  88.            (member (cdr (assoc 70 dxf)) '(1 129))
  89.       )
  90.     (progn
  91.       (textpage)
  92.       (prompt
  93.         (strcat "\n choose option :" "\n " "\n  1. Choose 1 for this ..." "\n  2. Choose 2 for this ..."
  94.                 "\n  3. Choose 3 for this ..." "\n  4. Choose 4 for this ..." "\n"
  95.                )
  96.       )
  97.       (setq area (vlax-curve-getarea ent))
  98.       (initget 1 "1 2 3 4")
  99.       (setq option (getkword "Select Option 1 to 4 : ")
  100.       )
  101.       (cond ((= option "1") (_option1))
  102.             ((= option "2") (_option2))
  103.             ((= option "3") (_option3))
  104.             ((= option "4") (_option4))
  105.       )
  106.       (if area
  107.         (princ (strcat "\n Selected Area = "
  108.                        (rtos area 2 2)
  109.                        "\n D = "
  110.                        (rtos sdarea 2 2)
  111.                        " sq.m"
  112.                        "\n K = "
  113.                        (rtos skarea 2 2)
  114.                        " sq.m"
  115.                )
  116.         )
  117.       )
  118.     )
  119.     (princ "\n-> No valid polyline selected...")
  120.   )
  121.   (princ)
  122. )
  123.  
  124.  ;|«Visual LISP© Format Options»
  125. (120 2 2 2 nil "end of " 100 9 1 1 1 nil T nil T)
  126. ;*** DO NOT add text below the comment! ***|;
Title: Re: help with a lisp
Post by: pedroantonio on March 31, 2014, 03:34:22 AM
Kerry i have another question

1) I change all the code with this ,but i have some erros
2) i want to add two different comments at the end

a) if   (oldare - anox) =< area <=(oldare + anox)  then print comment 1
b) if    area > (oldare + anox)  or   area < (oldare - anox)  then print comment 2

Code - Auto/Visual Lisp: [Select]
  1.    C:test(/ _OPTION1 _OPTION2 OLDARE AREA DXF ENT ANOX)
  2.   (DEFUN
  3.      _OPTION1 ()
  4.     (SETQ ANOX (* OLDARE 0.05))
  5.     DEFUN
  6.     _OPTION2
  7.     ()
  8.     (SETQ ANOX (* OLDARE 0.10))
  9.     ;; Main -----
  10.     (IF (AND
  11.           (SETQ ENT (CAR (ENTSEL "\nSelect a close polyline: ")))
  12.           (SETQ OLDARE (GETREAL "\ngive old area : "))
  13.           (WCMATCH
  14.             (CDR (ASSOC 0 (SETQ DXF (ENTGET ENT))))
  15.             "*POLYLINE"
  16.           )
  17.           (MEMBER (CDR (ASSOC 70 DXF)) '(1 129))
  18.         )
  19.       (PROGN
  20.         (INITGET 7)
  21.         (TEXTPAGE)
  22.         (PROMPT "\n text1  :
  23.  
  24.   1. option 1
  25.   2. option 2")
  26.         (SETQ
  27.           AREA   (VLAX-CURVE-GETAREA ENT)
  28.           OPTION (GETINT "choose 1 -->2: ")
  29.         )
  30.         (COND
  31.           ((= OPTION 1) (_OPTION1))
  32.           ((= OPTION 2) (_OPTION2))
  33.           (T (ALERT "Select > 2 --> Auto select 2. ") (_OPTION2))
  34.         )
  35.         (PRINC
  36.           (STRCAT
  37.             "\n Area = "
  38.             (RTOS AREA 2 2)
  39.             " sqm"
  40.             "\n Anotation Area = "
  41.             (RTOS ANOX 2 2)
  42.             " sqm"
  43.             "\n comments: "
  44.             "\n comment1....... "
  45.             "\n comment2....... "
  46.             "com "
  47.           )
  48.         )
  49.       )
  50.       (PRINC "\nError selection of polyline ...")
  51.     )
  52.     (PRINC)
  53.   )
  54.   (PRINC)
  55. )
  56.  

thanks
Title: Re: help with a lisp
Post by: Kerry on March 31, 2014, 04:34:15 AM

I'm certain if you apply yourself you can do this without too much trouble.

Regards,


Title: Re: help with a lisp
Post by: pedroantonio on March 31, 2014, 06:47:47 AM
Kerry i can't find the error   :embarrassed:

Code - Auto/Visual Lisp: [Select]
  1.    C:TEST (/ _OPTION1 _OPTION2 OLDARE AREA DXF ENT ANOX)
  2.   (DEFUN _OPTION1 () (SETQ ANOX (* OLDARE 0.05)))
  3.   (DEFUN _OPTION2 () (SETQ ANOX (* OLDARE 0.10)))
  4.   ;; Main -----
  5.   (IF (AND
  6.         (SETQ ENT (CAR (ENTSEL "\nSelect a close polyline: ")))
  7.         (SETQ OLDARE (GETREAL "\ngive old area : "))
  8.         (WCMATCH
  9.           (CDR (ASSOC 0 (SETQ DXF (ENTGET ENT))))
  10.           "*POLYLINE"
  11.         )
  12.         (MEMBER (CDR (ASSOC 70 DXF)) '(1 129))
  13.       )
  14.     (PROGN
  15.       (INITGET 7)
  16.       (TEXTPAGE)
  17.       (PROMPT
  18.         "\n text1  :
  19.  
  20.   1. option 1
  21.   2. option 2
  22.        "
  23.       )
  24.       (SETQ
  25.         AREA   (VLAX-CURVE-GETAREA ENT)
  26.         OPTION (GETINT "choose 1 -->2: ")
  27.       )
  28.       (COND
  29.         ((= OPTION 1) (_OPTION1))
  30.         ((= OPTION 2) (_OPTION2))
  31.         (T (ALERT "Select > 2 --> Auto select 2. ") (_OPTION2))
  32.       )
  33.       (PRINC
  34.         (STRCAT
  35.           "\n Area = "
  36.           (RTOS AREA 2 2)
  37.           " sqm"
  38.           "\n Anotation Area = "
  39.           (RTOS ANOX 2 2)
  40.           " sqm"
  41.           "\n comments: "
  42.           "\n "
  43.           (COND
  44.             ((AND
  45.                (>= AREA (- OLDARE ANOX))
  46.                (<= AREA (+ OLDARE ANOX))
  47.                (PRINC "\n comment1")
  48.                ((AND
  49.                   (> AREA (+ OLDARE ANOX))
  50.                   (< AREA (- OLDARE ANOX))
  51.                   (PRINC "\n comment2")
  52.                 )
  53.                )
  54.              )
  55.              (PRINC "\nError selection of polyline ...")
  56.             )
  57.             (PRINC)
  58.           )
  59.           (PRINC)
  60.         )
  61.       )
  62.     )
  63.   )
  64. )
  65.  ;|«Visual LISP© Format Options»
  66. (72 2 40 2 nil "end of " 60 2 2 2 1 nil nil nil T)
  67. ;*** DO NOT add text below the comment! ***|;
  68.  
  69.  
Title: Re: help with a lisp
Post by: snownut2 on March 31, 2014, 06:59:39 AM
Take a look at you parenthesis around the "and" functions, and it appears you have variables (ie; comment1 & comment2) being used as text in the princ line.  Look at using the strcat function

example;
Code: [Select]
(and
    (foo1)
    (foo2)
)

You've seen enough examples here from others that you can figure this out.  (time to cowboy up)
Title: Re: help with a lisp
Post by: Kerry on March 31, 2014, 07:19:34 AM
Additionally ;

Your conditional statement is unbalanced.

Study this
Each branch consists of a self contained Test and a statement set  to execute if the test is true.

Code - Auto/Visual Lisp: [Select]
  1. (cond ((and (true-or-false-test-01)
  2.             (true-or-false-test-02)
  3.        )
  4.        (setq xxx 0102)
  5.       )
  6.       ((and (true-or-false-test-03)
  7.             (true-or-false-test-04)
  8.        )
  9.        (setq xxx 0304)
  10.       )
  11.       ((and (true-or-false-test-01)
  12.             (true-or-false-test-03)
  13.        )
  14.        (setq xxx 0103)
  15.       )
  16.       ((and (true-or-false-test-02)
  17.             (true-or-false-test-03)
  18.        )
  19.        (setq xxx 0203)
  20.       )
  21. )
  22.  
Title: Re: help with a lisp
Post by: pedroantonio on April 01, 2014, 10:25:53 AM
Kerry i can not understand it. Can you help me.

Thanks
Title: Re: help with a lisp
Post by: Kerry on April 01, 2014, 10:48:23 AM
Untested

Code - Auto/Visual Lisp: [Select]
  1.  
  2.    C:TEST (/ _OPTION1 _OPTION2 OLDARE AREA DXF ENT ANOX)
  3.   (defun _OPTION1 () (setq ANOX (* OLDARE 0.05)))
  4.   (defun _OPTION2 () (setq ANOX (* OLDARE 0.10)))
  5.   ;; Main -----
  6.   (if (and
  7.         (setq
  8.           ENT
  9.            (car (entsel "\nSelect a close polyline: "))
  10.         )
  11.         (setq OLDARE (getreal "\ngive old area : "))
  12.         (wcmatch
  13.           (cdr (assoc 0 (setq DXF (entget ENT))))
  14.           "*POLYLINE"
  15.         )
  16.         (member (cdr (assoc 70 DXF)) '(1 129))
  17.       )
  18.     (progn
  19.       (initget 7)
  20.       (textpage)
  21.       (prompt
  22.         "\n text1  :
  23.  
  24.   1. option 1
  25.   2. option 2
  26.        "
  27.       )
  28.       (setq
  29.         AREA   (vlax-curve-getarea ENT)
  30.         OPTION (getint "choose 1 -->2: ")
  31.       )
  32.       (cond
  33.         ((= OPTION 1) (_OPTION1))
  34.         ((= OPTION 2) (_OPTION2))
  35.         (t
  36.          (alert "Select > 2 --> Auto select 2. ")
  37.          (_OPTION2)
  38.         )
  39.       )
  40.       (princ
  41.         (strcat
  42.           "\n Area = "
  43.           (rtos AREA 2 2)
  44.           " sqm"
  45.           "\n Anotation Area = "
  46.           (rtos ANOX 2 2)
  47.           " sqm"
  48.           "\n comments: "
  49.           "\n "
  50.           (cond
  51.             ((and
  52.                (>= AREA (- OLDARE ANOX))
  53.                (<= AREA (+ OLDARE ANOX))
  54.              )
  55.              (princ "\n comment1")
  56.             )
  57.             ((and
  58.                (> AREA (+ OLDARE ANOX))
  59.                (< AREA (- OLDARE ANOX))
  60.              )
  61.              (princ "\n comment2")
  62.             )
  63.           )
  64.         )
  65.       )
  66.     )
  67.     (princ "\nError selection of polyline ...")
  68.   )
  69.   (princ)
  70. )
  71.  
  72.  
  73.  
  74.  
  75.  
Title: Re: help with a lisp
Post by: pedroantonio on April 01, 2014, 10:54:15 AM
Thank you Kerry
Title: Re: help with a lisp
Post by: pedroantonio on April 01, 2014, 11:38:16 AM
Kerry I have problem with print comment 2
I change litle bit the code . But i still have print problem .Can you check it.

Code - Auto/Visual Lisp: [Select]
  1.    C:TEST (/ _OPTION1 _OPTION2 OLDARE AREA DXF ENT ANOX T1 T2)
  2.   (DEFUN _OPTION1 () (SETQ ANOX (* OLDARE 0.05)))
  3.   (DEFUN _OPTION2 () (SETQ ANOX (* OLDARE 0.10)))
  4.   ;; Main -----
  5.   (IF (AND
  6.         (SETQ ENT (CAR (ENTSEL "\nSelect a close polyline: ")))
  7.         (SETQ OLDARE (GETREAL "\ngive old area : "))
  8.         (WCMATCH
  9.           (CDR (ASSOC 0 (SETQ DXF (ENTGET ENT))))
  10.           "*POLYLINE"
  11.         )
  12.         (MEMBER (CDR (ASSOC 70 DXF)) '(1 129))
  13.       )
  14.     (PROGN
  15.       (INITGET 7)
  16.       (TEXTPAGE)
  17.       (PROMPT
  18.         "\n text1  :
  19.  
  20.   1. option 1
  21.   2. option 2
  22.        "
  23.       )
  24.       (SETQ
  25.         AREA   (VLAX-CURVE-GETAREA ENT)
  26.         OPTION (GETINT "choose 1 -->2: ")
  27.       )
  28.       (COND
  29.         ((= OPTION 1) (_OPTION1))
  30.         ((= OPTION 2) (_OPTION2))
  31.         (T (ALERT "Select > 2 --> Auto select 2. ") (_OPTION2))
  32.       )
  33.       (SETQ T1 (- OLDARE ANOX))
  34.       (SETQ T2 (+ OLDARE ANOX))
  35.       (PRINC
  36.         (STRCAT
  37.           "\n Area = "
  38.           (RTOS AREA 2 2)
  39.           " sqm"
  40.           "\n Anotation Area = ± "
  41.           (RTOS ANOX 2 2)
  42.           " sqm"
  43.           "\n "
  44.           "\n comments: "
  45.           "\n "
  46.           (COND
  47.             ((AND (>= AREA T1) (<= AREA T2))
  48.              (PRINC
  49.                "\n "
  50.                (RTOS T1 2 2)
  51.                " sqm <="
  52.                (RTOS AREA 2 2)
  53.                " <= "
  54.                (RTOS T2 2 2)
  55.                " sqm"
  56.                "\n comment1"
  57.              )
  58.             )
  59.             ((AND (> AREA T2) (< AREA T1))
  60.              (PRINC
  61.                (PRINC
  62.                  "\n "
  63.                  (RTOS T1 2 2)
  64.                  " sqm > "
  65.                  (RTOS AREA 2 2)
  66.                  " > "
  67.                  (RTOS T2 2 2)
  68.                  "sqm"
  69.                  "\n comment2"
  70.                )
  71.              )
  72.             )
  73.           )
  74.         )
  75.       )
  76.       (PRINC "\nError selection of polyline ...")
  77.     )
  78.     (PRINC)
  79.   )
  80.   ;|«Visual LISP© Format Options»
  81. (72 2 40 2 nil "end of " 60 2 2 2 1 nil nil nil T)
  82. ;*** DO NOT add text below the comment! ***|;
  83. )
  84.  

Thank you
Title: Re: help with a lisp
Post by: Kerry on April 01, 2014, 11:45:53 AM
Explain EXACTLY what is wrong.
What are your pre-condition values ?
What do you expect What ?
and what you get what ?

For the cause of the problem, look first at the things you changed.

Added:
Looking at your code, you need to fix the last several lines of code.
Compare my post with yours.
I'll look at your comment code when you respond satisfactorily to my information request.
Title: Re: help with a lisp
Post by: pedroantonio on April 01, 2014, 12:58:39 PM
Sorry Kerry.I will explain you now..

I want
a) when  T1< = Area <= T2 to print T1< = Area <= T2 and comment 1
b) when  T1>Area >T2 to print T1> Area > T2 and comment 2

Your code works only for comment 1 , for comment 2 gives error. I add in the code ths lines

Code - Auto/Visual Lisp: [Select]
  1.  
  2.  
  3. (SETQ T1 (- OLDARE ANOX))
  4. (SETQ T2 (+ OLDARE ANOX))
  5. --------------------
  6. -----------------
  7.  
  8.             ((AND (>= AREA T1) (<= AREA T2))
  9.              (PRINC
  10.                "\n "
  11.                (RTOS T1 2 2)
  12.                " sqm <="
  13.                (RTOS AREA 2 2)
  14.                " <= "
  15.                (RTOS T2 2 2)
  16.                " sqm"
  17.                "\n comment1"
  18.              )
  19.             )
  20.             ((AND (> AREA T2) (< AREA T1))
  21.              (PRINC
  22.                (PRINC
  23.                  "\n "
  24.                  (RTOS T1 2 2)
  25.                  " sqm > "
  26.                  (RTOS AREA 2 2)
  27.                  " > "
  28.                  (RTOS T2 2 2)
  29.                  "sqm"
  30.                  "\n comment2"
  31.                )
  32.  

but i still have problem with the results . I test the code in autocad vlisp editor  but i can not find were the problem is. if you can help.

Thanks
Title: Re: help with a lisp
Post by: Kerry on April 01, 2014, 01:05:11 PM
You're going to have to learn to listen bud !
I didn't ask for freaking code, I asked for data.

Give me values for comment 1
Area :
OLDARE :
ANOX :

Give me values for comment 2
Area :
OLDARE :
ANOX :

... as many combinations as you like.

Without knowing the data and the expected results I may as well just walk away.


added:
and please confirm the rules because this isn't what you've coded.
Quote
I want
a) when  T1<= Area <= T2     to print T1<= Area <= T2 and comment 1
b) when  T1 >  Area     >T2    to print    T1> Area >T2 and comment 2
Title: Re: help with a lisp
Post by: pedroantonio on April 01, 2014, 01:28:52 PM
Karry here is the example


for option 1 (comment 1)
OLD AREA 8000sqm
Area 8062sqm
Anox 8000 * 0.05 = 400 sqm
T1 =  8000 - 400 = 7600 sqm
T2 =  8000 + 400 = 8400 sqm

7600< 8062 <8400  so
comment 1

for option 1 (comment 2)

OLD AREA 8000sqm
Area 9500sqm
Anox 8000 * 0.05 = 400 sqm
T1 =  8000 - 400 = 7600 sqm
T2 =  8000 + 400 = 8400 sqm

7600>9500 >8400  so
comment 2
 -----------------------------------------------

for option 2 (comment 1)
OLD AREA 8000sqm
Area 7500sqm
Anox 8000 * 0.10 = 800 sqm
T1 =  8000 - 800 = 7200 sqm
T2 =  8000 + 800 = 8800 sqm

7200< 7500 <8800  so
comment 1

for option 2 (comment 2)

OLD AREA 8000sqm
Area 7100sqm
Anox 8000 * 0.10 = 800 sqm
T1 =  8000 - 800 = 7200 sqm
T2 =  8000 + 800 = 8800 sqm 

Here we have a change in the code

7200>7100  so
comment 2

if we have

for option 2 (comment 2)

OLD AREA 8000sqm
Area 8950sqm
Anox 8000 * 0.10 = 800 sqm
T1 =  8000 - 800 = 7200 sqm
T2 =  8000 + 800 = 8800 sqm 

Here we have a change in the code

8950 > 8800  so
comment 2

The comment 2 i thing need 3 options
T1>Area>T2
T1>Area
T2< Area

Title: Re: help with a lisp
Post by: Kerry on April 01, 2014, 02:02:35 PM
for option 1 (comment 2)

OLD AREA 8000sqm
Area 9500sqm
Anox 8000 * 0.05 = 400 sqm
T1 =  8000 - 400 = 7600 sqm
T2 =  8000 + 400 = 8400 sqm

7600>9500 >8400  so
comment 2
 -----------------------------------------------

7600>9500 >8400 This is crap.
Title: Re: help with a lisp
Post by: pedroantonio on April 01, 2014, 02:09:57 PM
I know thats why i write

Quote
The comment 2 i thing need 3 options
T1>Area>T2
T1>Area
T2< Area
Title: Re: help with a lisp
Post by: ymg on April 01, 2014, 02:22:03 PM
Kerry,

Here somethig I use quite often as a test condition:

Quote
1$ (< 2 5 7)
T
_1$ (< 2 1 7)
nil
Title: Re: help with a lisp
Post by: Kerry on April 01, 2014, 02:31:14 PM
Please Test this in isolation :

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun _PrintComments ()
  3.   (setq T1 (- OLDARE ANOX))
  4.   (setq T2 (+ OLDARE ANOX))
  5.   (princ (strcat "\n ----------------"
  6.                  (strcat "\n Area = " (rtos AREA 2 2) " sqm")
  7.                  (strcat "\n Old Area = " (rtos oldare 2 2) " sqm")
  8.                  (strcat "\n Anotation Area = ± " (rtos ANOX 2 2) " sqm")
  9.                  "\n comments: "
  10.          )
  11.   )
  12.   (cond
  13.     ((<= T1 AREA T2)
  14.      (princ (strcat "\n ----------------\n "
  15.                     (strcat (rtos T1 2 2)
  16.                             " sqm <= "
  17.                             (rtos AREA 2 2)
  18.                             " <= "
  19.                             (rtos T2 2 2)
  20.                             " sqm"
  21.                     )
  22.                     "\n comment1:"
  23.             )
  24.      )
  25.     )
  26.     ((> T1 AREA T2)
  27.      (princ (strcat "\n ----------------\n "
  28.                     (strcat (rtos T1 2 2)
  29.                             " sqm > "
  30.                             (rtos AREA 2 2)
  31.                             " > "
  32.                             (rtos T2 2 2)
  33.                             " sqm"
  34.                     )
  35.                     "\n comment2:"
  36.             )
  37.      )
  38.     )
  39.     ((> T1 AREA)
  40.      (princ
  41.        (strcat "\n ----------------\n "
  42.                (strcat (rtos T1 2 2) " sqm > " (rtos AREA 2 2) " sqm")
  43.                "\n comment2:"
  44.        )
  45.      )
  46.     )
  47.     ((< T2 AREA)
  48.      (princ
  49.        (strcat "\n ----------------\n "
  50.                (strcat (rtos T2 2 2) " sqm < " (rtos AREA 2 2) " sqm")
  51.                "\n comment2:"
  52.        )
  53.      )
  54.     )
  55.     (t (princ "\n ----------------\n No suitable data."))
  56.   )
  57.   (princ "\n =======================\n")
  58.   (princ)
  59. )
  60.  

With these tests
.... and I'd suggest you write some tests of your own as well.
Code - Auto/Visual Lisp: [Select]
  1.  
  2. ;; TESTING CODE for (_PrintComments)
  3.  
  4. ;; for option 1 (comment 1)
  5. (setq area   8062
  6.       oldare 8000
  7.       anox   (* OLDARE 0.05)
  8.       var    (_PrintComments)
  9. )
  10. ;; for option 1 (comment 2)
  11. (setq area   9500
  12.       oldare 8000
  13.       anox   (* OLDARE 0.05)
  14.       var    (_PrintComments)
  15. )
  16.  
  17.  
  18.  
  19. ;; for option 2 (comment 1)
  20. (setq area   7500
  21.       oldare 8000
  22.       anox   (* OLDARE 0.10)
  23.       var    (_PrintComments)
  24. )
  25. ;; for option 2 (comment 2)
  26. (setq area   7100
  27.       oldare 8000
  28.       anox   (* OLDARE 0.10)
  29.       var    (_PrintComments)
  30. )
  31.  
  32. ;; for option 2 (comment 2)
  33. (setq area   8950
  34.       oldare 8000
  35.       anox   (* OLDARE 0.10)
  36.       var    (_PrintComments)
  37. )
  38.  
  39.  
  40.  


My Results :

Quote
----------------
 Area = 8062.00 sqm
 Old Area = 8000.00 sqm
 Anotation Area = ± 400.00 sqm
 comments:
 ----------------
 7600.00 sqm <= 8062.00 <= 8400.00 sqm
 comment1:
 =======================

 
 ----------------
 Area = 9500.00 sqm
 Old Area = 8000.00 sqm
 Anotation Area = ± 400.00 sqm
 comments:
 ----------------
 8400.00 sqm < 9500.00 sqm
 comment2:
 =======================

 
 ----------------
 Area = 7500.00 sqm
 Old Area = 8000.00 sqm
 Anotation Area = ± 800.00 sqm
 comments:
 ----------------
 7200.00 sqm <= 7500.00 <= 8800.00 sqm
 comment1:
 =======================

 
 ----------------
 Area = 7100.00 sqm
 Old Area = 8000.00 sqm
 Anotation Area = ± 800.00 sqm
 comments:
 ----------------
 7200.00 sqm > 7100.00 sqm
 comment2:
 =======================

 
 ----------------
 Area = 8950.00 sqm
 Old Area = 8000.00 sqm
 Anotation Area = ± 800.00 sqm
 comments:
 ----------------
 8800.00 sqm < 8950.00 sqm
 comment2:
 =======================










Then if you're happy try the combined code on real entitys.

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun C:TEST (/         _PrintComments      _Option1  _Option2
  3.                OLDARE    AREA      DXF       ENT       ANOX
  4.                T1        T2
  5.               )
  6.   (defun _Option1 () (setq ANOX (* OLDARE 0.05)))
  7.   (defun _Option2 () (setq ANOX (* OLDARE 0.10)))
  8.   (defun _PrintComments ()
  9.     (setq T1 (- OLDARE ANOX))
  10.     (setq T2 (+ OLDARE ANOX))
  11.     (princ
  12.       (strcat "\n ----------------"
  13.               (strcat "\n Area = " (rtos AREA 2 2) " sqm")
  14.               (strcat "\n Old Area = " (rtos oldare 2 2) " sqm")
  15.               (strcat "\n Anotation Area = ± " (rtos ANOX 2 2) " sqm")
  16.               "\n comments: "
  17.       )
  18.     )
  19.     (cond
  20.       ((<= T1 AREA T2)
  21.        (princ (strcat "\n ----------------\n "
  22.                       (strcat (rtos T1 2 2)
  23.                               " sqm <= "
  24.                               (rtos AREA 2 2)
  25.                               " <= "
  26.                               (rtos T2 2 2)
  27.                               " sqm"
  28.                       )
  29.                       "\n comment1:"
  30.               )
  31.        )
  32.       )
  33.       ((> T1 AREA T2)
  34.        (princ (strcat "\n ----------------\n "
  35.                       (strcat (rtos T1 2 2)
  36.                               " sqm > "
  37.                               (rtos AREA 2 2)
  38.                               " > "
  39.                               (rtos T2 2 2)
  40.                               " sqm"
  41.                       )
  42.                       "\n comment2:"
  43.               )
  44.        )
  45.       )
  46.       ((> T1 AREA)
  47.        (princ
  48.          (strcat "\n ----------------\n "
  49.                  (strcat (rtos T1 2 2) " sqm > " (rtos AREA 2 2) " sqm")
  50.                  "\n comment2:"
  51.          )
  52.        )
  53.       )
  54.       ((< T2 AREA)
  55.        (princ
  56.          (strcat "\n ----------------\n "
  57.                  (strcat (rtos T2 2 2) " sqm < " (rtos AREA 2 2) " sqm")
  58.                  "\n comment2:"
  59.          )
  60.        )
  61.       )
  62.       (t (princ "\n ----------------\n No suitable data."))
  63.     )
  64.     (princ "\n =======================\n")
  65.     (princ)
  66.   )
  67.   ;; Main -----
  68.   (if
  69.     (and (setq ENT (car (entsel "\nSelect a close polyline: ")))
  70.          (wcmatch (cdr (assoc 0 (setq DXF (entget ENT)))) "*POLYLINE")
  71.          (member (cdr (assoc 70 DXF)) '(1 129))
  72.          (setq OLDARE (getreal "\ngive old area : "))
  73.     )
  74.      (progn
  75.        (initget 7)
  76.        (textpage)
  77.        (prompt "\n text1  :
  78.  
  79.   1. option 1
  80.   2. option 2
  81.        "
  82.        )
  83.        (setq AREA   (vlax-curve-getarea ENT)
  84.              OPTION (getint "choose 1 -->2: ")
  85.        )
  86.        (cond ((= OPTION 1) (_Option1))
  87.              ((= OPTION 2) (_Option2))
  88.              (t (alert "Select > 2 --> Auto select 2. ") (_Option2))
  89.        )
  90.        (_PrintComments)
  91.      )
  92.      (princ "\nError selection of polyline ...")
  93.   )
  94.   (princ)
  95. )
  96.  
Title: Re: help with a lisp
Post by: pedroantonio on April 01, 2014, 02:52:01 PM
thank you kerry i will test it..
Title: Re: help with a lisp
Post by: pedroantonio on April 04, 2014, 03:48:29 AM
Hello Kerry ..
I tried to add some comments on the results to the first code of this topic. The above method for showing me is difficult to use it  because the Oprtion  2 and Option 3  have the same area  2000, but different comments. So I decided to  add  the comments in the code of each option. But something is written wrong but  i  don't know what.I don't know how to use     (_PRINTCOMMENTS) .Could you help me with the code.
Thanks

Code - Auto/Visual Lisp: [Select]
  1.    C:DOMKAL (/ _PRINTCOMMENTS _OPTION1 _OPTION2 _OPTION3 _OPTION4 AREA
  2.              DXF ENT SDAREA SKAREA
  3.             )
  4.   (DEFUN
  5.      _OPTION1 ()
  6.     (COND
  7.       ((< AREA 200)
  8.        (SETQ
  9.          SDAREA AREA
  10.          SKAREA
  11.           (* AREA 0.7)
  12.        )
  13.        (PRINC
  14.          (STRCAT
  15.            "\n ---------------------\n "
  16.            "\n bla bla bla bla."
  17.            "\n bla bla bla bla."
  18.            "\n bla bla bla bla."
  19.            "\n bla bla bla bla."
  20.           )
  21.        )
  22.       )
  23.       ((< AREA 700)
  24.        (SETQ
  25.          SDAREA 240
  26.          SKAREA
  27.           (* AREA 0.6)
  28.          (PRINC
  29.            (STRCAT
  30.              "\n ---------------------\n "
  31.              "\n bla bla bla bla."
  32.              "\n bla bla bla bla."
  33.              "\n bla bla bla bla."
  34.              "\n bla bla bla bla."
  35.             )
  36.          )
  37.        )
  38.        ((>= AREA 700)
  39.          (SETQ
  40.            SDAREA 400
  41.            SKAREA
  42.             (* AREA 0.6)
  43.            (PRINC
  44.              (STRCAT
  45.                "\n ---------------------\n "
  46.                "\n bla bla bla bla."
  47.                "\n bla bla bla bla."
  48.                "\n bla bla bla bla."
  49.                "\n bla bla bla bla."
  50.               )
  51.            )
  52.          )
  53.        )
  54.       )
  55.       (DEFUN
  56.        _OPTION2
  57.        ()
  58.        (COND
  59.          ((<= AREA 2000)
  60.           (SETQ
  61.             SDAREA
  62.              (* AREA 0.8)
  63.             SKAREA
  64.              (* AREA 0.6)
  65.             (PRINC
  66.               (STRCAT
  67.                 "\n ---------------------\n "
  68.                 "\n bla bla bla bla."
  69.                 "\n bla bla bla bla."
  70.                 "\n bla bla bla bla."
  71.                 "\n bla bla bla bla."
  72.                )
  73.             )
  74.           )
  75.           ((> AREA 2000)
  76.             (SETQ
  77.               SDAREA
  78.                (+ 400 (* 0.05 (- AREA 2000)))
  79.               SKAREA
  80.                (* AREA 0.1)
  81.               (PRINC
  82.                 (STRCAT
  83.                   "\n ---------------------\n "
  84.                   "\n bla bla bla bla."
  85.                   "\n bla bla bla bla."
  86.                   "\n bla bla bla bla."
  87.                   "\n bla bla bla bla."
  88.                  )
  89.               )
  90.             )
  91.           )
  92.          )
  93.          (DEFUN
  94.           _OPTION3
  95.           ()
  96.           (COND
  97.             ((= AREA 750)
  98.              (SETQ
  99.                SDAREA 100
  100.                SKAREA
  101.                 (* AREA 0.1)
  102.                (PRINC
  103.                  (STRCAT
  104.                    "\n ---------------------\n "
  105.                    "\n bla bla bla bla."
  106.                    "\n bla bla bla bla."
  107.                    "\n bla bla bla bla."
  108.                    "\n bla bla bla bla."
  109.                   )
  110.                )
  111.              )
  112.             )
  113.             ((AND (> AREA 750) (<= AREA 1200))
  114.              (SETQ
  115.                SDAREA
  116.                 (+ 100 (/ (- AREA 750) 9))
  117.                SKAREA
  118.                 (* AREA 0.1)
  119.                (PRINC
  120.                  (STRCAT
  121.                    "\n ---------------------\n "
  122.                    "\n bla bla bla bla."
  123.                    "\n bla bla bla bla."
  124.                    "\n bla bla bla bla."
  125.                    "\n bla bla bla bla."
  126.                   )
  127.                )
  128.              )
  129.             )
  130.             ((AND (> AREA 1200) (<= AREA 2000))
  131.              (SETQ
  132.                SDAREA
  133.                 (+ 150 (/ (- AREA 1200) 16))
  134.                SKAREA
  135.                 (* AREA 0.1)
  136.                (PRINC
  137.                  (STRCAT
  138.                    "\n ---------------------\n "
  139.                    "\n bla bla bla bla."
  140.                    "\n bla bla bla bla."
  141.                    "\n bla bla bla bla."
  142.                    "\n bla bla bla bla."
  143.                   )
  144.                )
  145.              )
  146.             )
  147.             ((AND (> AREA 2000) (< AREA 4000))
  148.              (SETQ
  149.                SDAREA 0
  150.                SKAREA 0
  151.                (PRINC
  152.                  (STRCAT
  153.                    "\n ---------------------\n "
  154.                "\n bla bla bla bla."
  155.                 "\n bla bla bla bla."
  156.                "\n bla bla bla bla."
  157.                 "\n bla bla bla bla."
  158.              )
  159.             )
  160.           )
  161.          )
  162.          ((= AREA 4000)
  163.           (SETQ
  164.             SDAREA 200
  165.             SKAREA
  166.              (* AREA 0.1)
  167.             (PRINC
  168.               (STRCAT
  169.                 "\n ---------------------\n "
  170.                 "\n bla bla bla bla."
  171.                 "\n bla bla bla bla."
  172.                 "\n bla bla bla bla."
  173.                 "\n bla bla bla bla."
  174.                )
  175.             )
  176.           )
  177.          )
  178.          ((AND (> AREA 4000) (<= AREA 8000))
  179.           (SETQ
  180.             SDAREA
  181.              (+ 200 (* 0.02 (- AREA 4000)))
  182.             SKAREA
  183.              (* AREA 0.1)
  184.             (PRINC
  185.               (STRCAT
  186.                 "\n ---------------------\n "
  187.                 "\n bla bla bla bla."
  188.                 "\n bla bla bla bla."
  189.                 "\n bla bla bla bla."
  190.                 "\n bla bla bla bla."
  191.                )
  192.             )
  193.           )
  194.          )
  195.          ((> AREA 8000)
  196.           (SETQ
  197.             SDAREA
  198.              (+ 280 (* 0.01 (- AREA 8000)))
  199.             SKAREA
  200.              (* AREA 0.1)
  201.             (PRINC
  202.               (STRCAT
  203.                 "\n ---------------------\n "
  204.                 "\n bla bla bla bla."
  205.                 "\n bla bla bla bla."
  206.                 "\n bla bla bla bla."
  207.                 "\n bla bla bla bla."
  208.                )
  209.             )
  210.           )
  211.          )
  212.        )
  213.        (DEFUN
  214.           _OPTION4 ()
  215.          (INITGET 7)
  216.          (SETQ SDAREA (* AREA (GETREAL "\n Give sd (example 1.2) : ")))
  217.          (INITGET 7)
  218.          (SETQ SKAREA (* AREA (GETREAL "\nGive sk (example 0.70) : ")))
  219.        )
  220.        (PRINC
  221.          (STRCAT
  222.            "\n Print Results"
  223.            "\n -----------------------"
  224.            (STRCAT "\n Selected Area = " (RTOS AREA 2 2) " sq.m")
  225.            (STRCAT "\n D = " (RTOS SDAREA 2 2) " sq.m")
  226.            (STRCAT "\n K = " (RTOS SKAREA 2 2) " sq.m")
  227.            "\n"
  228.            "\n comments: "
  229.          )
  230.          (PRINC
  231.               (STRCAT
  232.                 "\n ---------------------\n "
  233.                 "\n bla bla bla bla."
  234.                 "\n bla bla bla bla."
  235.                 "\n bla bla bla bla."
  236.                 "\n bla bla bla bla."
  237.                )
  238.             )
  239.       )
  240.     )
  241.     (T
  242.       (PRINC
  243.         "\n ---------------------\nNo valid polyline selected..."
  244.       )
  245.     )
  246.   )
  247.   (PRINC
  248.     "\n ========================================================================\n"
  249.   )
  250.   (PRINC)
  251. )
  252. ;; Main -----
  253.       (SETQ ENT (CAR (ENTSEL "\nSelect a close polyline: ")))
  254.       (WCMATCH
  255.         (CDR (ASSOC 0 (SETQ DXF (ENTGET ENT))))
  256.         "*POLYLINE"
  257.       )
  258.       (MEMBER (CDR (ASSOC 70 DXF)) '(1 129))
  259.     )
  260.   (PROGN
  261.     (INITGET 7)
  262.     (TEXTPAGE)
  263.     (PROMPT
  264.       "\nChoose an option:
  265.  
  266.   1. Oprion 1
  267.   2. Option 2
  268.   3. Option 3
  269.   4. Option 4
  270.  
  271. "   )
  272.     (SETQ
  273.       AREA   (VLAX-CURVE-GETAREA ENT)
  274.       OPTION (GETINT "choose 1 -->4:  ")
  275.     )
  276.     (COND
  277.       ((= OPTION 1) (_OPTION1))
  278.       ((= OPTION 2) (_OPTION2))
  279.       ((= OPTION 3) (_OPTION3))
  280.       ((= OPTION 4) (_OPTION4))
  281.       (T (ALERT "Select > 4 --> Auto select 4. ") (_OPTION4))
  282.     )
  283.     (_PRINTCOMMENTS)
  284.   )
  285.   (PRINC "\nError selection of polyline ...")
  286. )
  287. )
  288. ;|«Visual LISP© Format Options»
  289. (72 2 40 2 nil "end of " 60 2 2 2 1 nil nil nil T)
  290. ;*** DO NOT add text below the comment! ***|;
  291.  
  292.  
Title: Re: help with a lisp
Post by: Kerry on April 04, 2014, 04:06:18 AM

I don't have time to play.

Break the problem down  to about half a page of code so you understand what is happening.
Title: Re: help with a lisp
Post by: Kerry on April 04, 2014, 04:47:02 AM

This is probably the best advice I can offer.

(http://i62.tinypic.com/2mww7ww.png)
Title: Re: help with a lisp
Post by: pedroantonio on April 04, 2014, 09:31:42 AM
show me one example from Option 1 and i will try the others
Title: Re: help with a lisp
Post by: snownut2 on April 04, 2014, 05:30:35 PM
show me one example from Option 1 and i will try the others

Really Pedro, did you not understand Kerry's GRAPH.
Title: Re: help with a lisp
Post by: Kerry on April 04, 2014, 07:41:42 PM
It seems to me that because of your the changed logic, the (_PRINTCOMMENTS) is no longer required. .. or perhaps you do .. I no longer understand what you want.

Perhaps something like this structure would suit better

Code - Auto/Visual Lisp: [Select]
  1.  
  2.  
  3. (defun c:MyRoutine ( / Routine_Functions Routine_variables)
  4.  
  5.   (defun *error* () (princ))
  6.   (defun _SelectBoundary () (princ))
  7.   (defun _PromptForOption () (princ))
  8.   (defun _PromptForOldArea () (princ))
  9.   (defun _OptionController () (princ))
  10.   (defun _ProcessOption1 () (princ))
  11.   (defun _ProcessOption2 () (princ))
  12.   (defun _ProcessOption3 () (princ))
  13.   (defun _ProcessOption4 () (princ))
  14.   (defun _CalculateAndPrintArea () (princ))
  15.   ;;
  16.   ;;-- Main
  17.   (if
  18.     (not (and (_SelectBoundary)
  19.               (_PromptForOption)
  20.               (_PromptForOldArea)))
  21.      (exit)
  22.   )
  23.   (_OptionController)
  24.   (princ)
  25. )
  26.  
  27.  

Just for giggles: If you renamed these variables to something that had obvious meaning, what would the new names be ?

ANOX
T1
T2
AREA    <-- is not a good name because it duplicates an AutoCAD command name.
OLDARE
SDAREA
SKAREA

How does the user know which option to choose.
Title: Re: help with a lisp
Post by: Kerry on April 04, 2014, 08:10:48 PM
Then fill out the logic flow functionality.

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun c:MyRoutine ()
  3.   (defun *error* () (princ))
  4.   (defun _SelectBoundary () (princ))
  5.   (defun _PromptForOption () (princ))
  6.   (defun _PromptForOldArea () (princ))
  7.   (defun _OptionController ()
  8.     ;; Calculate BoundaryArea
  9.     (cond ((= OPTION 1) (_ProcessOption1))
  10.           ((= OPTION 2) (_ProcessOption2))
  11.           ((= OPTION 3) (_ProcessOption3))
  12.           ((= OPTION 4) (_ProcessOption4))
  13.           (t (alert "Select > 4 --> Auto select 4. ") (_ProcessOption4))
  14.     )
  15.     (princ)
  16.   )
  17.   (defun _ProcessOption1 ()
  18.     (cond ((< AREA 200)
  19.            ;; Calculate area related values
  20.            ;; Print option comments
  21.           )
  22.           ((< AREA 700)
  23.            ;; Calculate area related values
  24.            ;; Print option comments
  25.           )
  26.           ((>= AREA 700)
  27.            ;; Calculate area related values
  28.            ;; Print option comments
  29.           )
  30.     )
  31.     (princ)
  32.   )
  33.   (defun _ProcessOption2 ()
  34.     (cond ((<= AREA 2000)
  35.            ;; Calculate area related values
  36.            ;; Print option comments
  37.           )
  38.           ((> AREA 2000)
  39.            ;; Calculate area related values
  40.            ;; Print option comments
  41.           )
  42.     )
  43.     (princ)
  44.   )
  45.   (defun _ProcessOption3 ()
  46.     (cond ((and (> AREA 750) (<= AREA 1200))
  47.            ;; Calculate area related values
  48.            ;; Print option comments
  49.           )
  50.           ((and (> AREA 1200) (<= AREA 2000))
  51.            ;; Calculate area related values
  52.            ;; Print option comments
  53.           )
  54.           ((and (> AREA 2000) (< AREA 4000))
  55.            ;; Calculate area related values
  56.            ;; Print option comments
  57.           )
  58.           ((= AREA 4000)
  59.            ;; Calculate area related values
  60.            ;; Print option comments
  61.           )
  62.           ((and (> AREA 4000) (<= AREA 8000))
  63.            ;; Calculate area related values
  64.            ;; Print option comments
  65.           )
  66.           ((> AREA 8000)
  67.            ;; Calculate area related values
  68.            ;; Print option comments
  69.           )
  70.     )
  71.     (princ)
  72.   )
  73.   (defun _ProcessOption4 ()
  74.     ;; Prompt for criteria
  75.     ;; Calculate area related values
  76.     ;; Print option comments
  77.     (princ)
  78.   )
  79.   (defun _CalculateAndPrintComments ()
  80.     ;; Similar to old  (_PrintComments)
  81.     (princ)
  82.   )
  83.   ;;
  84.   ;;-- Main
  85.   ;;
  86.   (if
  87.     (not (and (_SelectBoundary) (_PromptForOption) (_PromptForOldArea)))
  88.      (exit)
  89.   )
  90.   (_OptionController)
  91.   (_CalculateAndPrintComments)
  92.   (princ)
  93. )
  94.  

 
Print this because it is your roadmap.
If you change the logic, change this first.

Save and rename this then continue filling in functionality.

Title: Re: help with a lisp
Post by: pedroantonio on April 05, 2014, 12:28:24 PM
i fix it thanks