(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)
)
)
) 乍一看:
(cdr (assoc 0 entlist) "LINE")可能应该是:
(= (cdr (assoc 0 entlist)) "LINE")
其他表达式也是如此。 下面是对代码的快速修改,以帮助您继续:
(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)
) 太棒了,李!我稍微调整了一下(为了我的喜好)
(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)
) 谢谢李和Grr,我真的很感谢你们的帮助!我最后只是稍微重写了一下,以获得更多的代码练习。我的代码是
奇怪的是,你的代码和我的代码都不适用于特征线。aeccbreakfeatures命令似乎有一些小问题。我写的一段代码是
有没有一种简单的方法来合并在while循环中工作的代码?我不希望用户必须两次命中一个点,因为那里有not getpoint语句。此外,如果用户正在打断要素行,并使用插入到breakfirst2代码中的我的breakfeaturesfirst代码点击escape,则会导致代码中断。有什么建议吗? 下面是新的和改进的代码,它可以完美地工作。我想我以后会把它发给任何想要它的人。再次感谢李和Grrr的帮助!
11
页:
1
[2]