Jump to content

Help with calculation Dcl , Lisp file


mhy3sx

Recommended Posts

Dont need a get_tile just check is len nil if so (setq len 0) but (set_tile "len" (rtos len 2 02)) you need to set the value of len outside the dcl.

 

In a dcl all the edits are strings no numbers.

 

I would do as a list and use for each rather than multiple If's.

Link to comment
Share on other sites

I try this but is not working

 

       (if (= "len" nil) (setq "len" 0))
       (if (= "wid" nil) (setq "wid" 0))
       (if (= "len1" nil) (setq "len1" 0))
       (if (= "len2") nil) (setq "len2" 0))
       (if (= "wid1" nil) (setq "wid1" 0))
       (if (= "wid2" nil) (setq "wid2" 0))
       (if (= "ar1" nil) (setq "ar1" 0))
       (if (= "ar2" nil) (setq "ar2" 0)) 

 

Perhaps I understand something wrong 😵‍💫

Link to comment
Share on other sites

I think I am getting somewhere

 

       
       (IF (= xa nil)    (set_tile "lena" "0")) 
       (IF (= ya nil)    (set_tile "wida" "0"))
       (IF (= lxd1 nil)  (set_tile "lend1" "0"))
       (IF (= lyd1 nil)  (set_tile "lend2" "0"))
       (IF (= arif1 nil) (set_tile "widd1" "0"))
       (IF (= lxd2 nil)  (set_tile "widd2" "0"))
       (IF (= lyd2 nil)  (set_tile "arif1" "0"))
       (IF (= arif2 nil) (set_tile "arif2" "0"))

 

(setq xa (atof (get_tile "lena")))
(setq ya (atof (get_tile "wida")))
(setq lxd1 (atof (get_tile "lend1")))
.............

 

Edited by BIGAL
Link to comment
Share on other sites

I change all this but nothing

 

  (defun Footest ( len wid len1 wid1 ar1 len2 wid2 ar2 / x y x1 y1 x2 y2 a b c d a1 a2 b1 b2) ;;Calculations
    (set_tile "res1" "")
    (set_tile "res2" "")
    (set_tile "res3" "")
    (set_tile "res4" "")

    (cond
	  (IF (= x nil)   (set_tile "len" "0"))
       (IF (= y nil)   (set_tile "wid" "0"))
       (IF (= x1 nil)  (set_tile "len1" "0"))
       (IF (= y1 nil)  (set_tile "wid1" "0"))
       (IF (= a1 nil)  (set_tile "ar1" "0"))
       (IF (= x2 nil)  (set_tile "len2" "0"))
       (IF (= y2 nil)  (set_tile "wid2" "0"))
       (IF (= a2 nil)  (set_tile "ar2" "0"))
    ; dimensions
      ( (or (not len) (= "" len))
        (alert "Please enter a length value.")
        (mode_tile "len" 2)
      )
      ( (or (not wid) (= "" wid))
        (alert "Please enter a width value.")
        (mode_tile "wid" 2)
      )
      ( (not (setq x (atof len)))
        (alert "The length must be numerical.")
        (mode_tile "len" 2)
      )
      ( (not (setq y (atof wid)))
        (alert "The width must be numerical.")
        (mode_tile "wid" 2)
      )


        ; dimension 1 
      ( (or (not len1) (= "" len1))
        (alert "Please enter a length value.")
        (mode_tile "len1" 2)
      )
      ( (or (not wid1) (= "" wid1))
        (alert "Please enter a width value.")
        (mode_tile "wid1" 2)
      )
      ( (or (not ar1) (= "" ar1))
        (alert "Please enter a ar1 value.")
        (mode_tile "ar1" 2)
      )
      ( (not (setq x1 (atof len1)))
        (alert "The length must be numerical.")
        (mode_tile "len1" 2)
      )
      ( (not (setq y1 (atof wid1)))
        (alert "The width must be numerical.")
        (mode_tile "wid1" 2)
      )
      ( (not (setq a1 (atof ar1)))
        (alert "The ar1 must be numerical.")
        (mode_tile "ar1" 2)
      )


        ; dimension 2
      ( (or (not len2) (= "" len2))
        (alert "Please enter a length value.")
        (mode_tile "len2" 2)
      )
      ( (or (not wid2) (= "" wid2))
        (alert "Please enter a width value.")
        (mode_tile "wid2" 2)
      )
      ( (or (not ar2) (= "" ar2))
        (alert "Please enter a ar2 value.")
        (mode_tile "ar2" 2)                            ;;SP TYPO: Added '2'
      )
      ( (not (setq x2 (atof len1)))
        (alert "The length must be numerical.")
        (mode_tile "len2" 2)
      )
      ( (not (setq y2 (atof wid2)))
        (alert "The width must be numerical.")
        (mode_tile "wid2" 2)
      )
      ( (not (setq a2 (atof ar2)))
        (alert "The ar2 must be numerical.")
        (mode_tile "ar1" 2)
      )
	  

	   
       (setq x (atof (get_tile "len")))
       (setq y (atof (get_tile "wid")))
       (setq x1 (atof (get_tile "len1")))
       (setq y1 (atof (get_tile "wid1")))
       (setq a1 (atof (get_tile "ar1")))
       (setq x2 (atof (get_tile "len2")))
       (setq y2 (atof (get_tile "wid2")))
       (setq a2 (atof (get_tile "ar2")))

      ( t                                                         ;;SP ADDED t
        (setq a (* x y))                                         ;;SP REMOVED (rtos
        (setq b1 (* x1 y1 a1))
        (setq b2 (* x2 y2 a2))
        (setq b (+ b1 b2))
        (setq c (- a b))                                         ;;TYPO (-a to be (- a
        (setq d (/ b a))

        (set_tile "res1" (rtos a 2 2))
        (set_tile "res2" (rtos b 2 2))
        (set_tile "res3" (rtos c 2 2))
        (set_tile "res4" (rtos d 2 2))
      ) ; end t
    ) ; end cond 2


(princ (list len wid len1 wid1 ar1 len2 wid2 ar2))

  ) ; end defun

 

Link to comment
Share on other sites

I dont think you understand how a cond works once a condition is met that is it exit cond, so I removed the cond, I am not sure if this works but try it. 

 

 (defun Footest ( len wid len1 wid1 ar1 len2 wid2 ar2 / x y x1 y1 x2 y2 a b c d a1 a2 b1 b2) ;;Calculations
    (set_tile "res1" "")
    (set_tile "res2" "")
    (set_tile "res3" "")
    (set_tile "res4" "")

    
	   (IF (= x nil)   (set_tile "len" "0"))
       (IF (= y nil)   (set_tile "wid" "0"))
       (IF (= x1 nil)  (set_tile "len1" "0"))
       (IF (= y1 nil)  (set_tile "wid1" "0"))
       (IF (= a1 nil)  (set_tile "ar1" "0"))
       (IF (= x2 nil)  (set_tile "len2" "0"))
       (IF (= y2 nil)  (set_tile "wid2" "0"))
       (IF (= a2 nil)  (set_tile "ar2" "0"))
    ; dimensions

      (If (or (not len) (= "" len))
        (alert "Please enter a length value.")
        (mode_tile "len" 2)
      )
      (IF  (or (not wid) (= "" wid))
        (alert "Please enter a width value.")
        (mode_tile "wid" 2)
      )
      (IF (not (setq x (atof len)))
        (alert "The length must be numerical.")
        (mode_tile "len" 2)
      )
      (If (not (setq y (atof wid)))
        (alert "The width must be numerical.")
        (mode_tile "wid" 2)
      )
        ; dimension 1 
      (IF (or (not len1) (= "" len1))
        (alert "Please enter a length value.")
        (mode_tile "len1" 2)
      )
      (IF (or (not wid1) (= "" wid1))
        (alert "Please enter a width value.")
        (mode_tile "wid1" 2)
      )
      (If (or (not ar1) (= "" ar1))
        (alert "Please enter a ar1 value.")
        (mode_tile "ar1" 2)
      )
      (If (not (setq x1 (atof len1)))
        (alert "The length must be numerical.")
        (mode_tile "len1" 2)
      )
      (IF (not (setq y1 (atof wid1)))
        (alert "The width must be numerical.")
        (mode_tile "wid1" 2)
      )
      ( (not (setq a1 (atof ar1)))
        (alert "The ar1 must be numerical.")
        (mode_tile "ar1" 2)
      )
        ; dimension 2
      (IF (or (not len2) (= "" len2))
        (alert "Please enter a length value.")
        (mode_tile "len2" 2)
      )
      (If (or (not wid2) (= "" wid2))
        (alert "Please enter a width value.")
        (mode_tile "wid2" 2)
      )
      (If (or (not ar2) (= "" ar2))
        (alert "Please enter a ar2 value.")
        (mode_tile "ar2" 2)                            ;;SP TYPO: Added '2'
      )
      (IF (not (setq x2 (atof len1)))
        (alert "The length must be numerical.")
        (mode_tile "len2" 2)
      )
      (IF (not (setq y2 (atof wid2)))
        (alert "The width must be numerical.")
        (mode_tile "wid2" 2)
      )
      (IF (not (setq a2 (atof ar2)))
        (alert "The ar2 must be numerical.")
        (mode_tile "ar1" 2)
      )
	  )
	   
       (setq x (atof (get_tile "len")))
       (setq y (atof (get_tile "wid")))
       (setq x1 (atof (get_tile "len1")))
       (setq y1 (atof (get_tile "wid1")))
       (setq a1 (atof (get_tile "ar1")))
       (setq x2 (atof (get_tile "len2")))
       (setq y2 (atof (get_tile "wid2")))
       (setq a2 (atof (get_tile "ar2")))

                                                     ;;SP ADDED t
        (setq a (* x y))                                         ;;SP REMOVED (rtos
        (setq b1 (* x1 y1 a1))
        (setq b2 (* x2 y2 a2))
        (setq b (+ b1 b2))
        (setq c (- a b))                                         ;;TYPO (-a to be (- a
        (setq d (/ b a))

        (set_tile "res1" (rtos a 2 2))
        (set_tile "res2" (rtos b 2 2))
        (set_tile "res3" (rtos c 2 2))
        (set_tile "res4" (rtos d 2 2))

(princ (list len wid len1 wid1 ar1 len2 wid2 ar2))

  ) ; end defun

 

 

Link to comment
Share on other sites

So in your LISP, this

 

       (IF (= x nil)   (set_tile "len" "0"))
       (IF (= y nil)   (set_tile "wid" "0"))
       (IF (= x1 nil)  (set_tile "len1" "0"))
       (IF (= y1 nil)  (set_tile "wid1" "0"))
       (IF (= a1 nil)  (set_tile "ar1" "0"))
       (IF (= x2 nil)  (set_tile "len2" "0"))
       (IF (= y2 nil)  (set_tile "wid2" "0"))
       (IF (= a2 nil)  (set_tile "ar2" "0"))

 

comes at the start of FooTest and then afterwards you calculate what x, Y and so on. However with this at the beginning of FooTest x will always be nil, len will always be set to 0.

 

So what is happening is you run the main routine, Foo which brings up the calculation dialogue. Press calc and behind the scenes FooTest runs and each time you press calc it runs as a new instance, each time x has not been set, is nil, so every press of calc sets "len" to "0"

 

What you might want to consider is doing these checks after your code to set x, y, and so on

 

The second part I notice is that this part:

 

       (setq x (atof (get_tile "len")))
       (setq y (atof (get_tile "wid")))
       (setq x1 (atof (get_tile "len1")))
       (setq y1 (atof (get_tile "wid1")))
       (setq a1 (atof (get_tile "ar1")))
       (setq x2 (atof (get_tile "len2")))
       (setq y2 (atof (get_tile "wid2")))
       (setq a2 (atof (get_tile "ar2")))

 

sits in the middle of the conds, just before (t ...... ) - it might be better after all of them or if needed to be put as a condition on their own

 

 

 

I've added a note here to show what conds are starting and ending t make it clearer, and move the problem parts of code to the end, commented out:

 

  (defun Footest ( len wid len1 wid1 ar1 len2 wid2 ar2 / x y x1 y1 x2 y2 a b c d a1 a2 b1 b2) ;;Calculations
    (set_tile "res1" "")
    (set_tile "res2" "")
    (set_tile "res3" "")
    (set_tile "res4" "")

    (cond
    ; dimensions
      ( (or (not len) (= "" len))
        (alert "Please enter a length value.")
        (mode_tile "len" 2)
      )                             ; end condition: not len
      ( (or (not wid) (= "" wid))
        (alert "Please enter a width value.")
        (mode_tile "wid" 2)
      )                             ; end condition: not wid
      ( (not (setq x (atof len)))
        (alert "The length must be numerical.")
        (mode_tile "len" 2)
      )                             ; end condition: not atof len
      ( (not (setq y (atof wid)))
        (alert "The width must be numerical.")
        (mode_tile "wid" 2)
      )                             ; end condition: not atof wid

        ; dimension 1 
      ( (or (not len1) (= "" len1))
        (alert "Please enter a length value.")
        (mode_tile "len1" 2)
      )                             ; end condition: not len1
      ( (or (not wid1) (= "" wid1))
        (alert "Please enter a width value.")
        (mode_tile "wid1" 2)
      )                             ; end condition: not wid1
      ( (or (not ar1) (= "" ar1))
        (alert "Please enter a ar1 value.")
        (mode_tile "ar1" 2)
      )                             ; end condition: not ar1
      ( (not (setq x1 (atof len1)))
        (alert "The length must be numerical.")
        (mode_tile "len1" 2)
      )                             ; end condition: not atof len1
      ( (not (setq y1 (atof wid1)))
        (alert "The width must be numerical.")
        (mode_tile "wid1" 2)
      )                             ; end condition: not atof wid1
      ( (not (setq a1 (atof ar1)))
        (alert "The ar1 must be numerical.")
        (mode_tile "ar1" 2)
      )                             ; end condition: not atof ar1

        ; dimension 2
      ( (or (not len2) (= "" len2))
        (alert "Please enter a length value.")
        (mode_tile "len2" 2)
      )                             ; end condition: not len2
      ( (or (not wid2) (= "" wid2))
        (alert "Please enter a width value.")
        (mode_tile "wid2" 2)
      )                             ; end condition: not wid2
      ( (or (not ar2) (= "" ar2))
        (alert "Please enter a ar2 value.")
        (mode_tile "ar2" 2)
      )                             ; end condition: not ar2
      ( (not (setq x2 (atof len1)))
        (alert "The length must be numerical.")
        (mode_tile "len2" 2)
      )                             ; end condition: not atof len1
      ( (not (setq y2 (atof wid2)))
        (alert "The width must be numerical.")
        (mode_tile "wid2" 2)
      )                             ; end condition: not atof wid2
      ( (not (setq a2 (atof ar2)))
        (alert "The ar2 must be numerical.")
        (mode_tile "ar1" 2)
      )                             ; end condition: not atof ar2

      ( t                                                        ;;SP ADDED t
        (setq a (* x y))                                         ;;SP REMOVED (rtos
        (setq b1 (* x1 y1 a1))
        (setq b2 (* x2 y2 a2))
        (setq b (+ b1 b2))
        (setq c (- a b))                                         ;;TYPO (-a to be (- a
        (setq d (/ b a))

        (set_tile "res1" (rtos a 2 2))
        (set_tile "res2" (rtos b 2 2))
        (set_tile "res3" (rtos c 2 2))
        (set_tile "res4" (rtos d 2 2))
      )                              ; end condition: t
    ) ; end conds 2


;       (setq x (atof (get_tile "len")))
;       (setq y (atof (get_tile "wid")))
;       (setq x1 (atof (get_tile "len1")))
;       (setq y1 (atof (get_tile "wid1")))
;       (setq a1 (atof (get_tile "ar1")))
;       (setq x2 (atof (get_tile "len2")))
;       (setq y2 (atof (get_tile "wid2")))
;       (setq a2 (atof (get_tile "ar2")))

;       (IF (= x nil)   (set_tile "len" "0"))
;       (IF (= y nil)   (set_tile "wid" "0"))
;       (IF (= x1 nil)  (set_tile "len1" "0"))
;       (IF (= y1 nil)  (set_tile "wid1" "0"))
;       (IF (= a1 nil)  (set_tile "ar1" "0"))
;       (IF (= x2 nil)  (set_tile "len2" "0"))
;       (IF (= y2 nil)  (set_tile "wid2" "0"))
;       (IF (= a2 nil)  (set_tile "ar2" "0"))


(princ (list len wid len1 wid1 ar1 len2 wid2 ar2))

  )

 

Edited by Steven P
Link to comment
Share on other sites

In your calc, the way I see it working just now is that all the values have to be entered, if there is nothing entered it won't get any further until all are entered.

 

Is it that you want one or more value to be changed to 0 if there is no value entered - and which ones need to have values, which can be 0?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...