Qonfire 发表于 2022-7-6 09:10:05

(defun c:我需要的LISP)

敬礼
 
在这个线程中,希望会有一个我想要和需要的最后lisp
 
首先,我需要一些测量面积的方法,比如说矩形。
 
(defun c:xxx (/ pt1 pt2 pt3 pt4 ltbay1 bay num_br)
(setq pt1 (getpoint "/nTop:"))
(setq pt2 (getcorner "/nBottom" pt1))
(setq pt3 (list (nth 0 pt2)(nth 1 pt1)))
(setq pt4 (list (nth 0 pt1)(nth 1 pt2)))
(command "_rectang" pt1 pt2);;;; i can live without actually drawing it but at this stage of lisp i want it there


(setq ltbay1 (rtos (- (nth 0 pt3) (nth 0 pt1)) 4 1)) ;; i want to measure distance of one side of rectangle
(setq num_br (1+ (fix (/ ltbay1 (rtos 15 4 1)))))

(print num_br)
 
 
我的错误是通过将一个点的x坐标从另一个点上减去来测量“距离”,我不知道还有其他方法可以获得该距离,当我看到这个问题没有帮助时,我添加了rtos
我还谈到了在xy轴的不同象限中指定矩形的问题
但现在我用最简单的方法
 
我希望有意见和建议

ketxu 发表于 2022-7-6 09:18:16

您在第1行中将ltbay1设置为字符串,并且字符串不能在数学/第2行中使用

BlackBox 发表于 2022-7-6 09:24:39

我不太明白为什么要沿一侧(X轴?)分割线性距离然而,在15之前,有一种方法可以获得绘制的矩形的面积:
 

(defun c:XXX ( / pt1 pt2 recArea)
(princ "\rRECTANGLE + AREA ")
(vl-load-com)
(if (and (setq pt1 (getpoint "\nSpecify start point: "))
   (not (initget 32))
   (setq pt2 (getpoint pt1 "\nSpecify end point: ")))
   (progn
   (entlast)
   (command "._rectang" pt1 pt2)
   (if (setq recArea (vla-get-area (vlax-ename->vla-object (entlast))))
       (prompt (strcat "\nArea = " (rtos recArea 4 1)))))
   (cond (pt1 (prompt "\n** Invalid input: Must specify end point ** "))
       ((prompt "\n** Invalid input: Must specify start point ** "))))
(princ))

 
备注-未经测试,写在我的MacBook上

BlackBox 发表于 2022-7-6 09:42:52

 
别担心。。。如果你可以发布其余的代码,或者澄清你需要什么额外的计算,也许我(或者更聪明的人)能够帮助建议一种更有效的方法来做你需要的事情?

LISP2LEARN 发表于 2022-7-6 09:44:48

新手代码。希望有帮助
 
(defun c:test ( / pt1 pt2 x y area)

(if
(and
   (setq pt1 (getpoint "\nPick top corner:"))
(setq pt2 (getcorner "\nPick bottom corner:" pt1))
(command "_.rectang" pt1 pt2)
)

(setq x (abs (- (car pt2) (car pt1))))
(setq y (abs (- (cadr pt2) (cadr pt1))))      
(setq area (/ (* x y) 12))

(princ (strcat "\nLenght of x is: " (rtos x)))
(princ (strcat "\nLenght of y is: " (rtos y)))
(princ (strcat "\nArea of rec is: " (rtos area)))
(princ)
)
)

BlackBox 发表于 2022-7-6 09:56:21

下面是另一种方法,通过一些注释来帮助解释代码的作用:
 

;; This is a keyboard shortcut
(defun c:RECA () (c:RectangleArea))

;; This is the main function
(defun c:RectangleArea ( / *error* oldCmdecho pt1 pt2 x y)

;; This loads the visual lisp library, and makes ActiveX available
(vl-load-com)

;; This displays the command name at the command line.
(princ "\rRECTANGLE+AREA ")

;; This is an error handler which is only in use during this function.
(defun *error*(msg)

    ;; In the event of an error, this will restore the original
    ;; system variable setting, *IF* that variable is defined.
   (and oldCmdecho (setvar 'cmdecho oldCmdecho))
   (cond ((not msg))                                                 ; Normal exit
         ((member msg '("Function cancelled" "quit / exit abort")))   ; <esc> or (quit)
         ((princ (strcat "\n** Error: " msg " ** "))))                 ; Fatal error, display it
   (princ))

;; This stores the current system variable value, and sets it
;; to not echo the command prompts that would normally be shown.
(and (setq oldCmdecho (getvar 'cmdecho)) (setvar 'cmdecho 0))

(if (and (setq pt1 (getpoint "\nPick top corner:"))

         ;; This dashes the selection line from pt1
          (not (initget 32))
          (setq pt2 (getcorner pt1 "\nPick bottom corner:"))

         ;; vl-cmdf returns T, whereas command returns NIL.
         ;; Using command would prevent your code from completing the
         ;; "AND" statement.
          (vl-cmdf "_.rectang" pt1 pt2))

    ;; Here I've combined several steps into one for simplicity.
   (princ
   (strcat
       "\nLength of x is: "
       (rtos (setq x (abs (- (car pt2) (car pt1)))))
       "\nLenght of y is: "
       (rtos (setq y (abs (- (cadr pt2) (cadr pt1)))))
       "\nArea of rec is: "
       (rtos (/ (* x y) 12)))))

;; If the code performs normally, and no errors (or Esc),
;; this will restore the original system variable setting.
(setvar 'cmdecho oldCmdecho)
(princ))

 
希望这有帮助!

Qonfire 发表于 2022-7-6 09:57:44

这是lisp的主要思想
 
我看到了一个简单的例子

LISP2LEARN 发表于 2022-7-6 10:04:25

为什么不使用DIVIDE或MEASURE命令。

BIGAL 发表于 2022-7-6 10:12:00

“分割和测量”不考虑可能需要的边缘偏移。这是一篇针对同一主题的新帖子,已经得到了广泛的评论。
页: [1]
查看完整版本: (defun c:我需要的LISP)