Hi guys !
Can run it on cad2010 and CAD2014.
Why this function can't run on CAD2015 ?
Before ,I uploaded the full routine , Was downloaded 14 times. But no one replies. I think maybe this routine is big.
Need takes a long time to read .
Troubleshoot one day. I find one function can't run on CAD2015 ,Why?
ON Cad2015
_$ (setq ss (ssget))
<Selection set: bf>
_$ (setq ent (car(entsel)))
<Entity name: 7ff7eba04d80>
_$ (break-byent ss ent)
; error: Function Err: <Entity name: 7ff7eba04da0>
ON Cad2010
_$ (setq ss (ssget))
<Selection set: 4>
_$ (setq ent (car(entsel)))
<Entity name: 7ee39410>
_$ (break-byent ss ent)
<Selection set: 4>
(defun break-byent
(
ss
ent
/
brkobjlst
brk_obj
en
iplist
lastent
maxparam
minparam
obj
obj2break
obj_erase
p1param
p2
p2param
pt
ssobjs
ssobjsall
onlockedlayer
ssget->vla-list
list->3pair
)
(vl-load-com)
(defun onlockedlayer (ename / entlst)
(setq entlst (tblsearch "LAYER" (cdr (assoc 8 (entget ename)))))
(= 4 (logand 4 (cdr (assoc 70 entlst))))
)
(defun ssget->vla-list (ss ent / i ename lst)
(setq i -1)
(while
(setq ename (ssname ss (setq i (1+ i))))
(if (equal ename ent)
(setq ss (ssdel ent ss))
)
;; check for locked layer, do not use if on locked layer
(if
(and
(not (onlockedlayer ename))
(not (equal ename ent))
) ; exclude break object
(setq lst (cons (vlax-ename->vla-object ename) lst))
)
)
lst
)
(defun list->3pair (old / new)
(while
(setq new (cons (list (car old) (cadr old) (caddr old)) new)
old (cdddr old)
)
)
(reverse new)
)
(if (and ss ent (setq ssobjs (ssget->vla-list ss ent)))
(progn
(setq ssobjsAll ss)
(setq brk_obj (vlax-ename->vla-object ent))
(mapcar
'(lambda (obj2Break / iplist brkobjlst lastent)
; loop through list of objects to be broken
; get list of intersect points
(setq iplist (vl-catch-all-apply 'vlax-safearray->list (list (vlax-variant-value (vla-intersectwith brk_obj obj2Break acextendnone)))))
(setq brkobjlst (cons obj2Break brkobjlst))
; collect the original object to be broken
(if (not (vl-catch-all-error-p iplist))
; error if no intersection
(mapcar ; loop through intersect points
'(lambda (pt / cen elst maxparam minparam p1 p2 p1param p2param)
;; get last entity created via break in case multiple breaks
(if
(and
lastent
(not (equal lastent (vlax-vla-object->ename brk_obj)))
) ; ignore the break object
(progn ; new object created via break, put in list
(setq brkobjlst (cons (vlax-ename->vla-object (entlast)) brkobjlst))
(setq ssobjsAll (ssadd (entlast) ssobjsAll))
;; if pt not on object x, switch objects
(if (not (vlax-curve-getdistatpoint obj2Break pt))
(foreach obj brkobjlst
; find the one that pt is on
(if (vlax-curve-getdistatpoint obj pt)
(setq obj2Break obj) ; switch objects
)
)
)
)
)
;; Handle any objects that can not be use with the Break Command
;; using one point
(cond
(
(and (= "AcDbSpline" (vla-get-objectname obj2Break))
; only closed splines
(vlax-curve-isClosed obj2Break)
)
(setq p1param (vlax-curve-getparamatpoint obj2Break pt)
p2param (+ p1param 0.000001)
p2 (vlax-curve-getPointAtParam obj2Break p2param)
)
(command "._break"
(vlax-vla-object->ename obj2Break)
"non"
(trans pt 0 1)
"non"
(trans p2 0 1)
)
)
(
(= "AcDbCircle" (vla-get-objectname obj2Break))
; break the circle
(setq p1param (vlax-curve-getparamatpoint obj2Break pt)
p2param (+ p1param 0.000001)
p2 (vlax-curve-getPointAtParam obj2Break p2param)
)
(command "._break"
(vlax-vla-object->ename obj2Break)
"non"
(trans pt 0 1)
"non"
(trans p2 0 1)
)
(setq en (entlast))
(setq ssobjsAll (ssadd en ssobjsAll))
)
(
(and
(= "AcDbEllipse" (vla-get-objectname obj2Break))
; only closed ellipse
(vlax-curve-isClosed obj2Break)
)
;; Break the ellipse, code borrowed from Joe Burke 6/6/2005
(setq p1param (vlax-curve-getparamatpoint obj2Break pt)
p2param (+ p1param 0.000001)
;(vlax-curve-getparamatpoint obj p2)
minparam (min p1param p2param)
maxparam (max p1param p2param)
)
(vlax-put obj2Break 'startparameter maxparam)
(vlax-put obj2Break 'endparameter (+ minparam (* pi 2)))
)
;;==================================
;; Objects that can be broken
;;==================================
(t
(command "._break"
(vlax-vla-object->ename obj2Break)
"non"
(trans pt 0 1)
"non"
(trans pt 0 1)
)
;; could not get vl-cmdf "._break" to behave
(setq lastent (entlast))
(setq ssobjsAll (ssadd lastent ssobjsAll))
)
)
)
(list->3pair iplist)
)
)
)
ssobjs
)
;; remove the break line, if current layer is not locked
(if obj_erase
(vl-catch-all-apply 'vla-delete (list brk_obj))
)
);;end_progn
);;end_if
ssobjsAll
);;end_defun