prodromosm 发表于 2022-7-6 00:02:42

计算打印问题!!

你好,我的朋友,我需要一点帮助。
我有下面的lisp,可以进行相同的计算
(vl-load-com)
(defun c:cal(/ A E I L S K)
(if
   (and (setq
          s (ssget '((0 . "ARC,CIRCLE,ELLIPSE,LINE,*POLYLINE,SPLINE")
                     (-4 . "<AND")
                     (0 . "LWPOLYLINE")
                     (70 . 1)
                     (-4 . "AND>")
                  )
            )
      )
      (progn
          (initget "A B")
          (setq
            k (cond
                ((getkword "\n For calculation select < A > :"))
                ("A")
            )
          )
      )
   )
    (progn
      (setq l 0.0
            a 0.0
            i 0
      )
      (while (< i (sslength s))
      (progn
          (setq e (ssname s i)
                l (+ l
                     (vlax-curve-getdistatparam e (vlax-curve-getendparam e))
                  )
                a (+ a (vlax-curve-getarea e))
          )
      )
      (setq i (1+ i))
      )
      (textscr)
      (princ "\n")
      (princ "\n      Calculations Results ")
      (princ "\n")
      (if (eq k "A")
      (progn
          (princ "\n Type 1: ")
          (princ
            (strcat
            (rtos (/ (* (- (expt (+ (sqrt a) 1) 2) a) l 0.25) (sqrt a))
                  2
                  2
            )
            "sq.m"
            )
          )
      )
      (progn
          (princ "\nType 2: ")
          (princ
            (strcat
            (rtos (/ (* (- (expt (+ (sqrt a) 4) 2) a) l 0.25) (sqrt a))
                  2
                  2
            )
            " sq.m"
            )
          )
      )
      )
      (princ "\n Type 3: ")
      (princ (strcat (rtos (* a 0.1) 2 2) " sq.m"))
    )
)
(princ)
)
 
如果我选择类型1(例如)print toy me
类型1=。。。。平方米
类型3=。。。。平方米
 
以同样的方式
如果我选择类型2(例如),请打印toy me
类型2=。。。。平方米
类型3=。。。。平方米
 
我只需要打印这个
 
对于
 
如果类型1>类型3,则仅打印类型3
如果类型1
 
如果我选择
 
如果类型2>类型3,则仅打印类型3
如果类型2
 
有人能帮我吗?

MSasu 发表于 2022-7-6 00:08:37

您应该将计算从PRINC调用中移出,并将其存储在专用变量(即t1、t2和t3)下;使用IF比较结果并相应打印。可能还想检查STRCAT功能,以优化代码的人机工程学。

prodromosm 发表于 2022-7-6 00:15:00

这对我来说有点复杂。你能修好吗?

prodromosm 发表于 2022-7-6 00:19:41

谢谢,我会试试的,如果我有其他问题,我会告诉你。。。。。。。。。。。。。。

MSasu 发表于 2022-7-6 00:23:30

对不起,我不会这么做;相反,我会给你一个开始的例子:
 
(setq t1 (/ (* (- (expt (+ (sqrt a) 1) 2) a) l 0.25) (sqrt a))
...
(if (eq k "A")
(if (> t1 t3)
(princ (strcat "\n Type 3: " (rtos t3 2 2) " sq.m"))
(princ (strcat "\n Type 1: " (rtos t1 2 2) " sq.m"))
)
...

prodromosm 发表于 2022-7-6 00:24:28

(vl-load-com)
(defun c:cal(/ A E I L S K)
(if
   (and (setq
          s (ssget '((0 . "ARC,CIRCLE,ELLIPSE,LINE,*POLYLINE,SPLINE")
                     (-4 . "<AND")
                     (0 . "LWPOLYLINE")
                     (70 . 1)
                     (-4 . "AND>")
                  )
            )
      )
      (progn
          (initget "A B")
          (setq
            k (cond
                ((getkword "\n For calculation select < A > :"))
                ("A")
            )
          )
      )
   )
    (progn
      (setq l 0.0
            a 0.0
            i 0
      )
      (while (< i (sslength s))
      (progn
          (setq e (ssname s i)
                l (+ l
                     (vlax-curve-getdistatparam e (vlax-curve-getendparam e))
                  )
                a (+ a (vlax-curve-getarea e))
          )
      )
      (setq i (1+ i))
      )
      (textscr)

(setq t1 (/ (* (- (expt (+ (sqrt a) 1) 2) a) l 0.25) (sqrt a))
(setq t2 (/ (* (- (expt (+ (sqrt a) 4) 2) a) l 0.25) (sqrt a))
(setq t3 (* a 0.1) (sqrt a))

(if (eq k "A")
(if (> t1 t3)
(princ (strcat "\n Type 3: " (rtos t3 2 2) " sq.m"))
(princ (strcat "\n Type 1: " (rtos t1 2 2) " sq.m"))
)
(if (eq k "B")
(if (> t2 t3)
(princ (strcat "\n Type 3: " (rtos t3 2 2) " sq.m"))
(princ (strcat "\n Type 1: " (rtos t1 2 2) " sq.m"))
)
(princ)
)
 
现在根本不起作用

MSasu 发表于 2022-7-6 00:32:30

你需要检查括号的平衡,有很多括号没有闭合对。

prodromosm 发表于 2022-7-6 00:32:55

我什么都不想做。

MSasu 发表于 2022-7-6 00:38:56

请检查这篇关于括号匹配的文章。

prodromosm 发表于 2022-7-6 00:41:25

我做不到。这很难
页: [1] 2
查看完整版本: 计算打印问题!!