乐筑天下

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

[编程交流] 改进的Break-LISP例程

[复制链接]

95

主题

477

帖子

383

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
475
发表于 2022-7-5 18:42:32 | 显示全部楼层
在运行当前代码时,我仍然会遇到一些错误,说我有很多参数,但我不知道为什么。我的新代码是:
  1. (defun c:breakfirst2 (/ *error* whilestop ent entlist pt)
  2. (defun *error* (msg)
  3.    (if (not
  4.          (member msg '("Function cancelled" "quit / exit abort"))
  5.        )
  6.      (princ (strcat "\nError: " msg))
  7.    )
  8.    (princ)
  9. )
  10. (setq whilestop t)
  11. (setvar 'errno 0)
  12. (while whilestop
  13.    (if (setq ent (car (entsel "\nSelect object to break: ")))
  14.      (progn
  15.        (setq entlist (entget ent))
  16.        (cond
  17.          ((/= (or (cdr (assoc 0 entlist) "LINE")
  18.                   (cdr (assoc 0 entlist) "ARC")
  19.                   (cdr (assoc 0 entlist) "CIRCLE")
  20.                   (cdr (assoc 0 entlist) "POLYLINE")
  21.                   (cdr (assoc 0 entlist) "AECC_FEATURE_LINE")
  22.               )
  23.           )
  24.           (princ "\nNot a valid object, try again.")
  25.          )
  26.          ((= (cdr (assoc 0 entlist) "AECC_FEATURE_LINE"))
  27.           (if (setq pt (getpoint "\nSelect break point: "))
  28.             (progn
  29.               (command "._AeccBreakFeatures" ent "_f" pt)
  30.               (setq whilestop nil)
  31.             )
  32.           )
  33.          )
  34.          (t
  35.           (if (setq pt (getpoint "\nSelect break point: "))
  36.             (progn
  37.               (command "._Break" ent "_f" pt)
  38.               (setq whilestop nil)
  39.             )
  40.           )
  41.          )
  42.        )
  43.      )
  44.    )
  45.    (if (/= (getvar 'errno) 52)
  46.      (princ "\nYou missed. Try again.")
  47.      (setq whilestop nil)
  48.    )
  49. )
  50. )
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 18:49:37 | 显示全部楼层
乍一看:
  1. (cdr (assoc 0 entlist) "LINE")
可能应该是:
  1. [highlight](=[/highlight] (cdr (assoc 0 entlist)[highlight])[/highlight] "LINE")

其他表达式也是如此。
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-5 18:51:10 | 显示全部楼层
下面是对代码的快速修改,以帮助您继续:
  1. (defun c:breakfirst2 ( / *error* ent pnt stop typ )
  2.    (defun *error* ( msg )
  3.        (if (not (member msg '("Function cancelled" "quit / exit abort")))
  4.            (princ (strcat "\nError: " msg))
  5.        )
  6.        (princ)
  7.    )
  8.    (while (not stop)
  9.        (setvar 'errno 0)
  10.        (setq ent (entsel "\nSelect object to break: "))
  11.        (cond
  12.            (   (= 52 (getvar 'errno))
  13.                (setq stop t)
  14.            )
  15.            (   (null ent)
  16.                (princ "\nYou missed. Try again.")
  17.            )
  18.            (   (not (wcmatch (setq typ (cdr (assoc 0 (entget (car ent))))) "LINE,ARC,CIRCLE,POLYLINE,AECC_FEATURE_LINE"))
  19.                (princ "\nNot a valid object, try again.")
  20.            )
  21.            (   (not (setq pnt (getpoint "\nSelect break point: ")))
  22.                (setq stop t)
  23.            )
  24.            (   (= typ "AECC_FEATURE_LINE")
  25.                (command "_.aeccbreakfeatures" ent "_f" "_non" pnt "_non" pnt)
  26.                (setq stop t)
  27.            )
  28.            (   t
  29.                (command "_.break" ent "_f" "_non" pnt "_non" pnt)
  30.                (setq stop t)
  31.            )
  32.        )
  33.    )
  34.    (princ)
  35. )
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 18:56:27 | 显示全部楼层
太棒了,李!我稍微调整了一下(为了我的喜好)
  1. (defun c:breakfirst2 ( / *error* ent pnt stop typ )
  2.    (defun *error* ( msg )
  3.        (if (not (member msg '("Function cancelled" "quit / exit abort")))
  4.            (princ (strcat "\nError: " msg))
  5.        )
  6.        (princ)
  7.    )
  8.    (while (not stop)
  9.        (setvar 'errno 0)
  10.        (setq ent (entsel "\nSelect object to break: "))
  11.        (cond
  12.            (   (= 52 (getvar 'errno))
  13.                (setq stop t)
  14.            )
  15.            (   (null ent)
  16.                (princ "\nYou missed. Try again.")
  17.            )
  18.            (   (not (wcmatch (setq typ (cdr (assoc 0 (entget (car ent))))) "LINE,XLINE,RAY,LWPOLYLINE,ARC,CIRCLE,POLYLINE,AECC_FEATURE_LINE"))
  19.                (princ "\nNot a valid object, try again.")
  20.            )
  21.            (   (not (setq pnt (getpoint "\nSelect break point: ")))
  22.                (setq stop t)
  23.            )
  24.            (   (= typ "AECC_FEATURE_LINE")
  25.                (command "_.aeccbreakfeatures" ent "_f" "_non" pnt "_non" pnt)
  26.                (setq stop t)
  27.            )
  28.            (   t
  29.                (while (command "_.break" ent "_f" "_non" pnt "_non" pnt)
  30.                (setq stop t))
  31.            )
  32.        )
  33.    )
  34.    (princ)
  35. )
回复

使用道具 举报

95

主题

477

帖子

383

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
475
发表于 2022-7-5 18:59:23 | 显示全部楼层
谢谢李和Grr,我真的很感谢你们的帮助!我最后只是稍微重写了一下,以获得更多的代码练习。我的代码是
奇怪的是,你的代码和我的代码都不适用于特征线。aeccbreakfeatures命令似乎有一些小问题。我写的一段代码是
有没有一种简单的方法来合并在while循环中工作的代码?我不希望用户必须两次命中一个点,因为那里有not getpoint语句。此外,如果用户正在打断要素行,并使用插入到breakfirst2代码中的我的breakfeaturesfirst代码点击escape,则会导致代码中断。有什么建议吗?
回复

使用道具 举报

95

主题

477

帖子

383

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
475
发表于 2022-7-5 19:03:08 | 显示全部楼层
下面是新的和改进的代码,它可以完美地工作。我想我以后会把它发给任何想要它的人。再次感谢李和Grrr的帮助!
  1. 11
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-13 00:11 , Processed in 1.762558 second(s), 62 queries .

© 2020-2025 乐筑天下

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