乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
楼主: temo

[编程交流] LISP计算长度和w

[复制链接]

1

主题

14

帖子

13

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 15:59:34 | 显示全部楼层
这很好,但对于非直矩形的形状,难道不能编写lisp来从最大x值中减去最小x值,通过用y代替x来获得长度和宽度吗?
回复

使用道具 举报

1

主题

14

帖子

13

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 16:02:06 | 显示全部楼层
顺便说一句,你在哪里学会写这些?
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 16:07:30 | 显示全部楼层
哈哈,你回复的时候写的
  1. (defun c:lenwid    (/ ent pt nlist xlist ylist xmax xmin ymax ymin xlen ylen len)
  2.    (defun makelay (x)
  3.    (if (not (tblsearch "Layer" x))
  4.        (progn
  5.        (setvar "cmdecho" 0)
  6.        (command "-layer" "m" x "")
  7.        (setvar "cmdecho" 1)
  8.        ) ;_  end progn
  9.    ) ;_  end if
  10.    ) ;_  end defun
  11.    (makelay "TEXT")
  12.    (defun Make_Text (txt_pt txt_val)
  13.    (entmake
  14.        (list '(0 . "TEXT")
  15.          '(8 . "TEXT")
  16.          (cons 10 txt_pt)
  17.          (cons 40 (max 2.5 (getvar "TEXTSIZE")))
  18.          (cons 1 txt_val)
  19.          '(50 . 0.0)
  20.          '(7 . "STANDARD")
  21.          '(71 . 0)
  22.          '(72 . 1)
  23.          '(73 . 2)
  24.          (cons 11 txt_pt)
  25.        ) ; end list
  26.    ) ; end entmake
  27.    ) ;_  end defun
  28.    (if    (and
  29.        (setq ent (car (entsel "\nSelect Object > ")))
  30.        (= "LWPOLYLINE" (cdr (assoc 0 (entget ent))))
  31.        (setq pt (getpoint "\nSelect Point for Text > "))
  32.    ) ;_  end and
  33.    (progn
  34.        (foreach x (entget ent)
  35.        (if (eq 10 (car x))
  36.            (setq nlist (cons (cdr x) nlist))
  37.        ) ;_  end if
  38.        ) ;_  end foreach
  39.        (setq nlist (reverse nlist))
  40.        (foreach n nlist
  41.        (setq xlist (cons (car n) xlist)
  42.              ylist (cons (cadr n) ylist)
  43.        ) ;_  end setq
  44.        ) ;_  end foreach
  45.        (setq xmax (apply 'max xlist)
  46.          xmin (apply 'min xlist)
  47.          ymax (apply 'max ylist)
  48.          ymin (apply 'min ylist)
  49.          xlen (- xmax xmin)
  50.          ylen (- ymax ymin)
  51.        ) ;_  end setq
  52.        (if    (> xlen ylen)
  53.        (setq len (strcat "Length of Room = "
  54.                  (rtos xlen 2 2)
  55.                  ",  Width of Room = "
  56.                  (rtos ylen 2 2)
  57.              ) ;_  end strcat
  58.        ) ;_  end setq
  59.        (setq len (strcat "Length of Room = "
  60.                  (rtos ylen 2 2)
  61.                  ",  Width of Room = "
  62.                  (rtos xlen 2 2)
  63.              ) ;_  end strcat
  64.        ) ;_  end setq
  65.        ) ;_  end if
  66.        (Make_Text pt len)
  67.    ) ;_  end progn
  68.    (princ "\n<!> No Object Selected or Object is not Polyline! <!>")
  69.    ) ;_  end if
  70.    (princ)
  71. ) ;_  end defun
回复

使用道具 举报

1

主题

14

帖子

13

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 16:10:02 | 显示全部楼层
含糖的谢谢结果很好
回复

使用道具 举报

1

主题

14

帖子

13

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 16:12:11 | 显示全部楼层
等等,单位是英寸。我怎么把它换成脚?
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 16:16:04 | 显示全部楼层
 
上大学前的一个空档年,在一家公司工作时,有人给我看了一个Lisp程序以及它能做什么,我很感兴趣,所以我查看了Lisp程序并试图找出它(很多尝试和错误!)。。。然后我偶然发现了这个论坛,从这里的人那里学到了我现在知道的一切。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 16:18:20 | 显示全部楼层
 
这样地?
 
  1. (defun c:lenwid    (/ ent pt nlist xlist ylist xmax xmin ymax ymin xlen ylen len)
  2.    (defun makelay (x)
  3.    (if (not (tblsearch "Layer" x))
  4.        (progn
  5.        (setvar "cmdecho" 0)
  6.        (command "-layer" "m" x "")
  7.        (setvar "cmdecho" 1)
  8.        ) ;_  end progn
  9.    ) ;_  end if
  10.    ) ;_  end defun
  11.    (makelay "TEXT")
  12.    (defun Make_Text (txt_pt txt_val)
  13.    (entmake
  14.        (list '(0 . "TEXT")
  15.          '(8 . "TEXT")
  16.          (cons 10 txt_pt)
  17.          (cons 40 (max 2.5 (getvar "TEXTSIZE")))
  18.          (cons 1 txt_val)
  19.          '(50 . 0.0)
  20.          '(7 . "STANDARD")
  21.          '(71 . 0)
  22.          '(72 . 1)
  23.          '(73 . 2)
  24.          (cons 11 txt_pt)
  25.        ) ; end list
  26.    ) ; end entmake
  27.    ) ;_  end defun
  28.    (if    (and
  29.        (setq ent (car (entsel "\nSelect Object > ")))
  30.        (= "LWPOLYLINE" (cdr (assoc 0 (entget ent))))
  31.        (setq pt (getpoint "\nSelect Point for Text > "))
  32.    ) ;_  end and
  33.    (progn
  34.        (foreach x (entget ent)
  35.        (if (eq 10 (car x))
  36.            (setq nlist (cons (cdr x) nlist))
  37.        ) ;_  end if
  38.        ) ;_  end foreach
  39.        (setq nlist (reverse nlist))
  40.        (foreach n nlist
  41.        (setq xlist (cons (car n) xlist)
  42.              ylist (cons (cadr n) ylist)
  43.        ) ;_  end setq
  44.        ) ;_  end foreach
  45.        (setq xmax (apply 'max xlist)
  46.          xmin (apply 'min xlist)
  47.          ymax (apply 'max ylist)
  48.          ymin (apply 'min ylist)
  49.          xlen (- xmax xmin)
  50.          ylen (- ymax ymin)
  51.        ) ;_  end setq
  52.        (if    (> xlen ylen)
  53.        (setq len (strcat "Length of Room = "
  54.                  (rtos (/ xlen 12.0) 2 2)
  55.                  ",  Width of Room = "
  56.                  (rtos (/ ylen 12.0) 2 2)
  57.              ) ;_  end strcat
  58.        ) ;_  end setq
  59.        (setq len (strcat "Length of Room = "
  60.                  (rtos (/ ylen 12.0) 2 2)
  61.                  ",  Width of Room = "
  62.                  (rtos (/ xlen 12.0) 2 2)
  63.              ) ;_  end strcat
  64.        ) ;_  end setq
  65.        ) ;_  end if
  66.        (Make_Text pt len)
  67.    ) ;_  end progn
  68.    (princ "\n<!> No Object Selected or Object is not Polyline! <!>")
  69.    ) ;_  end if
  70.    (princ)
  71. ) ;_  end defun
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 16:23:02 | 显示全部楼层
可能也需要(英尺):
 
  1. (defun c:lenwid    (/ ent pt nlist xlist ylist xmax xmin ymax ymin xlen ylen len)
  2.    (defun makelay (x)
  3.    (if (not (tblsearch "Layer" x))
  4.        (progn
  5.        (setvar "cmdecho" 0)
  6.        (command "-layer" "m" x "")
  7.        (setvar "cmdecho" 1)
  8.        ) ;_  end progn
  9.    ) ;_  end if
  10.    ) ;_  end defun
  11.    (makelay "TEXT")
  12.    (defun Make_Text (txt_pt txt_val)
  13.    (entmake
  14.        (list '(0 . "TEXT")
  15.          '(8 . "TEXT")
  16.          (cons 10 txt_pt)
  17.          (cons 40 (max 2.5 (getvar "TEXTSIZE")))
  18.          (cons 1 txt_val)
  19.          '(50 . 0.0)
  20.          '(7 . "STANDARD")
  21.          '(71 . 0)
  22.          '(72 . 1)
  23.          '(73 . 2)
  24.          (cons 11 txt_pt)
  25.        ) ; end list
  26.    ) ; end entmake
  27.    ) ;_  end defun
  28.    (if    (and
  29.        (setq ent (car (entsel "\nSelect Object > ")))
  30.        (= "LWPOLYLINE" (cdr (assoc 0 (entget ent))))
  31.        (setq pt (getpoint "\nSelect Point for Text > "))
  32.    ) ;_  end and
  33.    (progn
  34.        (foreach x (entget ent)
  35.        (if (eq 10 (car x))
  36.            (setq nlist (cons (cdr x) nlist))
  37.        ) ;_  end if
  38.        ) ;_  end foreach
  39.        (setq nlist (reverse nlist))
  40.        (foreach n nlist
  41.        (setq xlist (cons (car n) xlist)
  42.              ylist (cons (cadr n) ylist)
  43.        ) ;_  end setq
  44.        ) ;_  end foreach
  45.        (setq xmax (apply 'max xlist)
  46.          xmin (apply 'min xlist)
  47.          ymax (apply 'max ylist)
  48.          ymin (apply 'min ylist)
  49.          xlen (- xmax xmin)
  50.          ylen (- ymax ymin)
  51.        ) ;_  end setq
  52.        (if    (> xlen ylen)
  53.        (setq len (strcat "Length of Room = "
  54.                  (rtos (/ xlen 12.0) 2 2)
  55.                  "ft,  Width of Room = "
  56.                  (rtos (/ ylen 12.0) 2 2)
  57.                  "ft"
  58.              ) ;_  end strcat
  59.        ) ;_  end setq
  60.        (setq len (strcat "Length of Room = "
  61.                  (rtos (/ ylen 12.0) 2 2)
  62.                  "ft,  Width of Room = "
  63.                  (rtos (/ xlen 12.0) 2 2)
  64.                  "ft"
  65.              ) ;_  end strcat
  66.        ) ;_  end setq
  67.        ) ;_  end if
  68.        (Make_Text pt len)
  69.    ) ;_  end progn
  70.    (princ "\n<!> No Object Selected or Object is not Polyline! <!>")
  71.    ) ;_  end if
  72.    (princ)
  73. ) ;_  end defun
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-4 18:33 , Processed in 0.388692 second(s), 66 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表