明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 193|回复: 4

[函数] (GetTwoPt)带关键字拾取两点

[复制链接]
发表于 16 小时前 | 显示全部楼层 |阅读模式
本帖最后由 fangmin723 于 2025-4-25 09:52 编辑

如果是拾取距离的话,使用getdist就可以了,

我这边不只需要距离,

后面还需要用到拾取的点,所以就用到了这个函数

  1. ;;说明:带关键字拾取两点
  2. ;;参数:keywords:关键字和描述信息的点表;'(("E" . "拾取曲线") ("P" . "拾取距离"))
  3. ;;返回:成功拾取两点:返回两点列表;触发关键字:返回关键字;否则:返回nil
  4. (defun GetTwoPt(keywords / join-symbol keywordstr model promptstr pt1 pt2)
  5.   (defun join-symbol(lst symbol)
  6.     (if (and lst (apply 'and (mapcar '(lambda(x) (equal (type x) 'STR)) lst)))
  7.       (apply 'strcat (cons (strcase (car lst)) (mapcar '(lambda (x) (strcat symbol (strcase x) )) (cdr lst))))
  8.       nil
  9.     )
  10.   )
  11.   (setq
  12.     keywordstr (join-symbol (mapcar 'car keywords) " ")
  13.     promptstr (join-symbol (mapc
  14. ar '(lambda(x) (strcat (cdr x) "(" (car x) ")")) keywords) "/")
  15.   )
  16.   (initget keywordstr)
  17.   (if (setq pt1 (getpoint (strcat "\n拾取第一点[" promptstr "]")))
  18.     (if (equal (type pt1) 'STR)
  19.       (setq model (strcase pt1))
  20.       (progn
  21.         (initget keywordstr)
  22.         (if (setq pt2 (getpoint pt1 (strcat "\n拾取第二点[" promptstr "]")))
  23.           (if (equal (type pt2) 'STR)
  24.             (setq model (strcase pt2))
  25.             (list pt1 pt2)
  26.           )
  27.           nil
  28.         )
  29.       )
  30.     )
  31.     nil
  32.   )
  33. )



GetTwoPt函数的简单应用
  1. (if (setq model "P" pts (GetTwoPt '(("E" . "拾取曲线"))))
  2.   (progn
  3.     (while (equal (type pts) 'STR)
  4.       (setq pts (strcase pts) model pts)
  5.       (cond
  6.         ((equal pts "P")
  7.           (setq pts (GetTwoPt '(("E" . "拾取曲线"))))
  8.         )
  9.         ((equal pts "E")
  10.           (initget "P")
  11.           (setq pts (entsel "\n拾取直线,多段线,圆(弧),椭圆(弧)[拾取距离(P)]:"))
  12.         )
  13.       )
  14.     )
  15.     (if pts
  16.       (cond
  17.         ((equal model "P")
  18.           .
  19.           .
  20.           .
  21.         )
  22.         ((equal model "E")
  23.           .
  24.           .
  25.           .
  26.         )
  27.       )
  28.     )
  29.   )
  30. )

评分

参与人数 1明经币 +1 收起 理由
zhoupeng220 + 1 很给力!

查看全部评分

"觉得好,就打赏"
还没有人打赏,支持一下
回复

使用道具 举报

发表于 15 小时前 | 显示全部楼层
感谢大佬共享代码 !  简单应用中的cond函数  括弧是不是有点问题?
回复 支持 反对

使用道具 举报

 楼主| 发表于 15 小时前 | 显示全部楼层
guosheyang 发表于 2025-4-25 08:33
感谢大佬共享代码 !  简单应用中的cond函数  括弧是不是有点问题?

有啥问题???
回复 支持 反对

使用道具 举报

发表于 14 小时前 | 显示全部楼层

最后一个cond   
(if pts
      (cond
        ((equal model "P")
          (princ "1")
        )
      )
      ((equal model "E")
        (princ "2")
      )
    )
回复 支持 反对

使用道具 举报

 楼主| 发表于 14 小时前 | 显示全部楼层
本帖最后由 fangmin723 于 2025-4-25 09:55 编辑
guosheyang 发表于 2025-4-25 09:15
最后一个cond   
(if pts
      (cond

好的,谢谢,可能是在删除里面代码时没注意,已经改好了
回复 支持 反对

使用道具 举报

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

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-4-25 23:56 , Processed in 0.235951 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表