broncos15 发表于 2022-7-5 18:42:32

在运行当前代码时,我仍然会遇到一些错误,说我有很多参数,但我不知道为什么。我的新代码是:(defun c:breakfirst2 (/ *error* whilestop ent entlist pt)
(defun *error* (msg)
   (if (not
         (member msg '("Function cancelled" "quit / exit abort"))
       )
   (princ (strcat "\nError: " msg))
   )
   (princ)
)
(setq whilestop t)
(setvar 'errno 0)
(while whilestop
   (if (setq ent (car (entsel "\nSelect object to break: ")))
   (progn
       (setq entlist (entget ent))
       (cond
         ((/= (or (cdr (assoc 0 entlist) "LINE")
                  (cdr (assoc 0 entlist) "ARC")
                  (cdr (assoc 0 entlist) "CIRCLE")
                  (cdr (assoc 0 entlist) "POLYLINE")
                  (cdr (assoc 0 entlist) "AECC_FEATURE_LINE")
            )
          )
          (princ "\nNot a valid object, try again.")
         )
         ((= (cdr (assoc 0 entlist) "AECC_FEATURE_LINE"))
          (if (setq pt (getpoint "\nSelect break point: "))
            (progn
            (command "._AeccBreakFeatures" ent "_f" pt)
            (setq whilestop nil)
            )
          )
         )
         (t
          (if (setq pt (getpoint "\nSelect break point: "))
            (progn
            (command "._Break" ent "_f" pt)
            (setq whilestop nil)
            )
          )
         )
       )
   )
   )
   (if (/= (getvar 'errno) 52)
   (princ "\nYou missed. Try again.")
   (setq whilestop nil)
   )
)
)

Lee Mac 发表于 2022-7-5 18:49:37

乍一看:
(cdr (assoc 0 entlist) "LINE")可能应该是:
(= (cdr (assoc 0 entlist)) "LINE")
其他表达式也是如此。

Lee Mac 发表于 2022-7-5 18:51:10

下面是对代码的快速修改,以帮助您继续:
(defun c:breakfirst2 ( / *error* ent pnt stop typ )

   (defun *error* ( msg )
       (if (not (member msg '("Function cancelled" "quit / exit abort")))
         (princ (strcat "\nError: " msg))
       )
       (princ)
   )

   (while (not stop)
       (setvar 'errno 0)
       (setq ent (entsel "\nSelect object to break: "))
       (cond
         (   (= 52 (getvar 'errno))
               (setq stop t)
         )
         (   (null ent)
               (princ "\nYou missed. Try again.")
         )
         (   (not (wcmatch (setq typ (cdr (assoc 0 (entget (car ent))))) "LINE,ARC,CIRCLE,POLYLINE,AECC_FEATURE_LINE"))
               (princ "\nNot a valid object, try again.")
         )
         (   (not (setq pnt (getpoint "\nSelect break point: ")))
               (setq stop t)
         )
         (   (= typ "AECC_FEATURE_LINE")
               (command "_.aeccbreakfeatures" ent "_f" "_non" pnt "_non" pnt)
               (setq stop t)
         )
         (   t
               (command "_.break" ent "_f" "_non" pnt "_non" pnt)
               (setq stop t)
         )
       )
   )
   (princ)
)

Grrr 发表于 2022-7-5 18:56:27

太棒了,李!我稍微调整了一下(为了我的喜好)
(defun c:breakfirst2 ( / *error* ent pnt stop typ )

   (defun *error* ( msg )
       (if (not (member msg '("Function cancelled" "quit / exit abort")))
         (princ (strcat "\nError: " msg))
       )
       (princ)
   )

   (while (not stop)
       (setvar 'errno 0)
       (setq ent (entsel "\nSelect object to break: "))
       (cond
         (   (= 52 (getvar 'errno))
               (setq stop t)
         )
         (   (null ent)
               (princ "\nYou missed. Try again.")
         )
         (   (not (wcmatch (setq typ (cdr (assoc 0 (entget (car ent))))) "LINE,XLINE,RAY,LWPOLYLINE,ARC,CIRCLE,POLYLINE,AECC_FEATURE_LINE"))
               (princ "\nNot a valid object, try again.")
         )
         (   (not (setq pnt (getpoint "\nSelect break point: ")))
               (setq stop t)
         )
         (   (= typ "AECC_FEATURE_LINE")
               (command "_.aeccbreakfeatures" ent "_f" "_non" pnt "_non" pnt)
               (setq stop t)
         )
         (   t
               (while (command "_.break" ent "_f" "_non" pnt "_non" pnt)
               (setq stop t))
         )
       )
   )
   (princ)
)

broncos15 发表于 2022-7-5 18:59:23

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

broncos15 发表于 2022-7-5 19:03:08

下面是新的和改进的代码,它可以完美地工作。我想我以后会把它发给任何想要它的人。再次感谢李和Grrr的帮助!
11
页: 1 [2]
查看完整版本: 改进的Break-LISP例程