Here is a routine from NG Autodesk, for closed LWPOLYLINE, you can use it. If it is not closed, close it first.
The error message, here is "Automation Error. Invalid input", might be different in Chinese version. You got to modify it.
;;f:pline_intersects returns T if given a self-intersecting lwpolyline
;;
(defun f:pline_intersects (en / sa rg)
(setq sa (vlax-make-safearray vlax-vbObject '(0 . 0))
sa (vlax-make-variant
(vlax-safearray-fill sa (list (f:enx en))))
) ;setq
(if (vl-catch-all-error-p
(setq rg (vl-catch-all-apply
'vla-addregion
(list (fx:active_space) sa))))
(if (wcmatch (vl-catch-all-error-message rg) "Automation Error. Invalid input")
;"*UNGÜLTIGE*")
T)
(vla-Delete
(car (vlax-safearray->list (vlax-variant-value rg))))
)
)
(defun fx:active_space ()
(if (zerop (getvar "TILEMODE"))
(vla-get-PaperSpace (fx:doc))
(vla-get-ModelSpace (fx:doc))
)
)
(defun f:enx (en)
(if (= (type en) 'ENAME)
(vlax-ename->vla-object en)
en
)
)
(defun fx:doc()
(vla-get-activedocument (vlax-get-acad-object))) |