Author Topic: Why this function can't run on CAD2015  (Read 1895 times)

0 Members and 1 Guest are viewing this topic.

Rosamund

  • Guest
Why this function can't run on CAD2015
« on: November 16, 2016, 04:29:34 AM »
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
Code: [Select]
_$ (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
Code: [Select]
_$ (setq ss (ssget))
<Selection set: 4>
_$ (setq ent (car(entsel)))
<Entity name: 7ee39410>
_$ (break-byent ss ent)
<Selection set: 4>


Code: [Select]
(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
« Last Edit: November 17, 2016, 01:47:14 AM by Rosamund »

Rosamund

  • Guest
Re: Why this function can't run on CAD2015
« Reply #1 on: November 17, 2016, 01:52:43 AM »
I tried replacing

Code: [Select]
commandto
Code: [Select]
command-s

Did not solve the problem

Rosamund

  • Guest
Re: Why this function can't run on CAD2015
« Reply #2 on: November 17, 2016, 04:16:48 AM »
Hi guys!

Code: [Select]
(defun fy-err (msg)       
(if
(and
(listp $lt-error$)
(= "*LTErr*" (last $lt-error$))
)
(progn
(mapcar 'eval (cdr (reverse (cdr $lt-error$))))
(setq $lt-error$ (list (car $lt-error$) (last $lt-error$)))
)
)
(cond
((= (type $lt-errormsg$) 'list) (eval $lt-errormsg$))
((= (type $lt-errormsg$) 'str) (setq msg $lt-errormsg$))
((not $lt-errormsg$) (setq msg nil))
)
(if msg (princ msg))
(while (not (= (getvar "cmdnames") "")) (command))
(if
(and
(or (= (car $lt-error$) 1) (= (car $lt-error$) T))
$lt-undoctl$
)
(progn
(var-set '("cmdecho" 0))
(while (not (wcmatch (getvar "cmdnames") "*UNDO*"))
(command "_.undo")
)
(command "_end")
(command "_.undo" "1")
(while (not (= (getvar "cmdnames") "")) (command))
)
)
(setq $lt-alive$ 1)
(var-res)
(setq $lt-alive$ 0)
(undo-res)
(if $lt-olderror$
(setq *error* $lt-olderror$ $lt-olderror$ nil)
)
(princ)
);;end_defun


in error function can't use "command" function , Must use "command-s" function.

Quote
Known Considerations
When using the command-s function, you must take the following into consideration:
Token streams fed in a single command-s expression must represent a full command and its input. Any commands in progress when command tokens are all processed will be cancelled. The following is not valid with the command-s function:
(command-s "._line")
(command-s "2,2" "12.25,9" "")


If change it like this,  is wrong,  is not valid...  So , How modify it ?
Code: [Select]
(while (not (wcmatch (getvar "cmdnames") "*UNDO*"))
(command-s "_.undo")
)
(command-s "_end")
« Last Edit: November 18, 2016, 09:06:30 PM by Rosamund »

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Why this function can't run on CAD2015
« Reply #3 on: November 17, 2016, 07:49:28 AM »
What expression does this procedure highlight?

Rosamund

  • Guest
Re: Why this function can't run on CAD2015
« Reply #4 on: November 18, 2016, 03:14:41 AM »
Hi Lee, Thank you for  your reply.

I have debugged. 

Last break at : (ssget "CP" (fy-GetDivPt ent times) filter)

I find something strange
Code: [Select]
(defun fy-GetDivPt (ent times / end i lineobj plst start)
(vl-load-com)
(setq lineObj (vlax-ename->vla-object ent)
start (vlax-curve-getstartparam lineObj)
end (vlax-curve-getendparam lineObj)
i 0
)
(while (< i times)
(setq plst (append plst(list (vlax-curve-getpointatparam lineObj (* i (/ (- end start) times))))) i (1+ i))
)
plst
)

Code: [Select]
(setq ent (car(entsel)))
(fy-GetDivPt ent 100)

The object is "revcloud" ,  why the list have some "nil" ?

Code: [Select]
_$  (fy-GetDivPt ent 100)
((1708.63 1079.09 0.0) (1708.86 1080.87 0.0) (1709.99 1082.26 0.0) (1711.69 1082.84 0.0) nil nil nil (1712.54 1082.96 0.0) (1713.35 1084.44 0.0) (1714.82 1085.28 0.0) (1716.51 1085.21 0.0) nil nil nil (1717.14 1085.32 0.0) (1718.11 1086.74 0.0) (1719.69 1087.43 0.0) (1721.39 1087.18 0.0) nil nil nil (1721.84 1087.52 0.0) (1722.68 1089.02 0.0) (1724.19 1089.85 0.0) (1725.91 1089.76 0.0) nil nil nil (1726.73 1090.09 0.0) (1728.42 1090.48 0.0) (1730.07 1089.91 0.0) (1731.16 1088.55 0.0) nil nil nil (1732.24 1088.47 0.0) (1734.08 1087.58 0.0) (1735.17 1085.86 0.0) nil nil nil nil (1736.29 1083.44 0.0) (1737.47 1081.94 0.0) (1737.69 1080.04 0.0) nil nil nil nil (1738.09 1077.57 0.0) (1738.69 1075.69 0.0) (1738.2 1073.77 0.0) nil nil nil nil (1737.59 1071.32 0.0) (1737.15 1069.66 0.0) (1735.91 1068.49 0.0) nil nil nil nil (1734.04 1066.56 0.0) (1732.37 1065.54 0.0) (1730.42 1065.56 0.0) nil nil nil (1729.46 1065.92 0.0) (1727.98 1064.7 0.0) (1726.08 1064.44 0.0) (1724.33 1065.23 0.0) nil nil nil (1723.61 1065.6 0.0) (1722.0 1064.56 0.0) (1720.08 1064.52 0.0) (1718.43 1065.51 0.0) nil nil nil (1717.71 1065.75 0.0) (1716.05 1065.33 0.0) (1714.41 1065.85 0.0) (1713.31 1067.16 0.0) nil nil nil (1712.57 1067.36 0.0) (1710.82 1067.64 0.0) (1709.49 1068.81 0.0) (1708.97 1070.5 0.0) nil nil nil (1707.99 1071.5 0.0) (1706.71 1074.02 0.0) (1706.94 1076.83 0.0))

_$  (fy-GetDivPt ent 100)
((1755.85 1085.77 0.0) (1755.83 1087.56 0.0) (1756.82 1089.05 0.0) (1758.48 1089.74 0.0) nil nil nil (1759.01 1090.73 0.0) (1759.99 1092.23 0.0) (1761.65 1092.91 0.0) nil nil nil (1762.93 1092.95 0.0) (1764.1 1094.35 0.0) (1765.86 1094.85 0.0) (1767.6 1094.29 0.0) nil nil nil (1768.6 1095.06 0.0) (1770.36 1095.72 0.0) (1772.19 1095.27 0.0) nil nil nil (1773.27 1094.82 0.0) (1774.88 1095.63 0.0) (1776.67 1095.39 0.0) (1778.02 1094.19 0.0) nil nil nil (1779.44 1094.12 0.0) (1781.03 1093.17 0.0) (1781.82 1091.49 0.0) nil nil nil (1782.33 1090.38 0.0) (1783.65 1089.09 0.0) (1784.02 1087.28 0.0) nil nil nil nil (1784.5 1084.58 0.0) (1784.94 1082.79 0.0) (1784.31 1081.06 0.0) nil nil nil (1784.02 1079.85 0.0) (1783.79 1078.01 0.0) (1782.58 1076.62 0.0) nil nil nil nil (1780.26 1073.94 0.0) (1778.23 1072.44 0.0) (1775.71 1072.34 0.0) nil nil nil (1774.49 1071.88 0.0) (1772.9 1071.01 0.0) (1771.09 1071.18 0.0) nil nil nil (1769.95 1071.92 0.0) (1768.51 1070.84 0.0) (1766.72 1070.75 0.0) (1765.18 1071.69 0.0) nil nil nil (1764.14 1071.14 0.0) (1762.25 1070.52 0.0) (1760.34 1071.07 0.0) nil nil nil (1759.18 1071.9 0.0) (1757.36 1072.0 0.0) (1755.91 1073.09 0.0) (1755.33 1074.82 0.0) nil nil nil (1754.18 1075.57 0.0) (1753.12 1077.11 0.0) (1753.09 1078.98 0.0) nil nil nil (1753.29 1080.36 0.0) (1752.95 1082.59 0.0) (1753.91 1084.63 0.0))

« Last Edit: November 18, 2016, 04:14:17 AM by Rosamund »

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: Why this function can't run on CAD2015
« Reply #5 on: November 18, 2016, 07:17:36 AM »
Not 100% sure, but try this mod...

Code: [Select]
(defun fy-GetDivPt ( ent times / end i plst start )
        (vl-load-com)
        (setq start (vlax-curve-getstartparam ent)
                 end (vlax-curve-getendparam ent)
                 i 0
        )
        (while (< i times)
                (setq plst (append plst (list (vlax-curve-getpointatparam ent (+ start (* i (/ (- end start) times)))))))
                (setq i (1+ i))
        )
        plst
)

HTH. M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Why this function can't run on CAD2015
« Reply #6 on: November 18, 2016, 02:03:58 PM »
Try replacing that function with this:
Code - Auto/Visual Lisp: [Select]
  1. (defun fy-getdivpt ( ent num / dis inc lst pnt )
  2.           dis 0.0
  3.     )
  4.     (repeat (1+ num)
  5.         (if (setq pnt (vlax-curve-getpointatdist ent dis))
  6.             (setq lst (cons pnt lst))
  7.         )
  8.         (setq dis (+ dis inc))
  9.     )
  10.     (reverse lst)
  11. )

Rosamund

  • Guest
Re: Why this function can't run on CAD2015
« Reply #7 on: November 18, 2016, 07:56:29 PM »
The same DWG file , Test at another computer . No problems were found.

But at this current computer.  Reboot computer ,Reboot AutoCAD , The problem always exists.

Hi
@ ribarm ,Thank you for help . use your function ,the problem still exists.
@ Lee Mac , Thank you , use your function , problem solved!!!  great!!!

@Lee , I have another problem , at #2
« Last Edit: November 18, 2016, 09:09:52 PM by Rosamund »