Author Topic: What's the problem ?  (Read 2344 times)

0 Members and 1 Guest are viewing this topic.

andy_lee

  • Newt
  • Posts: 147
What's the problem ?
« on: August 27, 2014, 05:41:09 AM »
Code - Auto/Visual Lisp: [Select]
  1. ;;;line,spline to circle(arc) Atsai 2014.8.24
  2. (defun c:tt (/ ss s1 ss2)
  3.   (setvar "cmdecho" 0)
  4.   (setq os (getvar "osmode"))
  5.   (setvar "osmode" 0)
  6.   (setq ps (getvar "peditaccept"))
  7.   (setvar "peditaccept" 1)
  8.   (setq ss (ssget '((0 . "LINE,SPLINE"))))
  9.  
  10. ;;;change line&spline to circle&arc ==start==
  11.   (defun draw (ss / s1 ss2 en2)
  12.     ;;from ZZQQXX
  13.     (setq s1 (entlast))
  14.     (setq ss2 (ssadd))
  15.     (command "pedit" "m" ss "" "j" 0.05 "")
  16.     (while (setq s1 (entnext s1))
  17.       (ssadd s1 ss2)
  18.     )
  19.  
  20.     (setq l (sslength ss2))
  21.     (setq i 0)
  22.     (repeat l
  23.       (setq ssn (ssname ss2 i))
  24.       (if (> (rem (cdr (assoc 70 (entget ssn))) 2) 0)
  25.         (progn
  26.           (command "_region" ssn "")
  27.           (setq en2 (entlast))
  28.           (setq obj2 (vlax-ename->vla-object en2))
  29.           (setq area (vla-get-Area obj2))
  30.           (setq        ptc (vlax-safearray->list
  31.                       (vlax-variant-value (vla-get-centroid obj2))
  32.                     )
  33.           )
  34.           (setq radius (sqrt (/ area pi)))
  35.           (command "_circle" ptc radius)
  36.           (entdel en2)
  37.         )
  38.         (progn
  39.           (setq obj1 (vlax-ename->vla-object ssn))
  40.           (setq pts (trans (vlax-curve-getstartpoint obj1) 0 (cdr (assoc 210 (entget ssn)))))
  41.           (setq pte (vlax-curve-getendpoint obj1))
  42.           (setq dis (vlax-curve-getdistAtPoint obj1 pte))
  43.           (setq pte (trans (vlax-curve-getendpoint obj1) 0 (cdr (assoc 210 (entget ssn)))))
  44.           (setq ptm (trans (vlax-curve-getpointatdist obj1 (* dis 0.5)) 0 (cdr (assoc 210 (entget ssn)))))
  45.           (command "_arc" pts ptm pte)
  46.           (entdel ssn)
  47.         )
  48.       )
  49.       (setq i (1+ i))
  50.     )
  51.   )
  52. ;;;change line&spline to circle&arc ==end==
  53.  
  54.  
  55.   (setq l (sslength ss))
  56.   (setq i 0)
  57.   (setq ss_l (ssadd))
  58.   (setq ss_sp (ssadd))
  59.   (repeat l
  60.     (setq ssn (ssname ss i))
  61.     (setq ssdata (entget ssn))
  62.     (setq sstype (cdr (assoc 0 ssdata)))
  63.     (cond
  64.       ((= sstype "LINE")
  65.        (setq ss_l (ssadd ssn ss_l))
  66.       )
  67.       ((= sstype "SPLINE")
  68.        (setq ss_sp (ssadd ssn ss_sp))
  69.       )
  70.     )
  71.     (setq i (1+ i))
  72.   )
  73.  
  74.   (if (> (sslength ss_l) 0)
  75.     (draw ss_l)
  76.   )
  77.   (if (> (sslength ss_sp) 0)
  78.     (progn
  79.       (setq j 0)
  80.       (repeat (sslength ss_sp)
  81.         (setq ssn (ssname ss_sp j))
  82.         (command "splinedit" ssn "p" 10)
  83.         (command "_.explode" (entlast))
  84.         (setq ss_tmp1 (ssget "_p"))
  85.         (if (= j 0)
  86.           (setq ss_tmp2 ss_tmp1)
  87.           (progn
  88.             (setq k 0)
  89.             (setq ll (sslength ss_tmp1))
  90.             (repeat (sslength ss_tmp1)
  91.               (setq ss_tmp2 (ssadd (ssname ss_tmp1 k) ss_tmp2))
  92.               (setq k (1+ k))
  93.             )
  94.           )
  95.         )
  96.         (setq j (1+ j))
  97.       )
  98.       (draw ss_tmp2)
  99.     )
  100.   )
  101.  
  102.   (setvar "peditaccept" ps)
  103.   (setvar "osmode" os)
  104.   (princ)
  105. )

I use in autocad2010 ,but error !!
Code: [Select]
Command: TT
Select objects: Specify opposite corner: 3 found
Select objects:
*Invalid selection*
Expects a point or
Window/Last/Crossing/BOX/ALL/Fence/WPolygon/CPolygon/Group/Add/Remove/Multiple/P
revious/Undo/AUto/SIngle
; error: Function cancelled

DWG for test
« Last Edit: August 27, 2014, 09:05:37 AM by Kerry »
andy.
Best regards.

ronjonp

  • Needs a day job
  • Posts: 7524
Re: What's the problem ?
« Reply #1 on: August 27, 2014, 08:21:26 AM »
Works in 2015.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

andy_lee

  • Newt
  • Posts: 147
Re: What's the problem ?
« Reply #2 on: August 27, 2014, 09:02:16 AM »
 
Works in 2015.

I test use acad2007(The same computer ) , is the same too.  error....
andy.
Best regards.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: What's the problem ?
« Reply #3 on: August 27, 2014, 09:10:27 AM »
Which line is it breaking on ??

See this to help discover the line ..


http://www.theswamp.org/index.php?topic=47623.msg526380#msg526380
Quote
Can you load it from the VLIDE ( as lisp code) with Debug->BreakOnError toggled on.
Then select Last Break Source when you get an error
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

andy_lee

  • Newt
  • Posts: 147
Re: What's the problem ?
« Reply #4 on: August 27, 2014, 09:56:29 AM »
Which line is it breaking on ??

See this to help discover the line ..


http://www.theswamp.org/index.php?topic=47623.msg526380#msg526380
Quote
Can you load it from the VLIDE ( as lisp code) with Debug->BreakOnError toggled on.
Then select Last Break Source when you get an error

Thanks kerry. I change another computer. Acad2010 , test OK!
andy.
Best regards.

ronjonp

  • Needs a day job
  • Posts: 7524
Re: What's the problem ?
« Reply #5 on: August 27, 2014, 10:06:45 AM »
You should probably localize your variables. That could be giving you fits.
Quote
; === Top statistic:
; Global variables: (AREA DIS I J K L LL OBJ1 OBJ2 OS PS PTC PTE PTM PTS RADIUS SSDATA SSN SSTYPE SS_L SS_SP SS_TMP1 SS_TMP2)
; Function definition (with number of arguments): ((DRAW . 1) (C:TT . 0))
; Check done.
« Last Edit: August 27, 2014, 10:10:24 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

andy_lee

  • Newt
  • Posts: 147
Re: What's the problem ?
« Reply #6 on: August 27, 2014, 09:29:43 PM »
Debug.

break at:
(command "_.explode" (entlast))

The reason has been found : "qaflags " need set to "0"
« Last Edit: August 27, 2014, 10:24:48 PM by emk2012 »
andy.
Best regards.

ChrisCarlson

  • Guest
Re: What's the problem ?
« Reply #7 on: August 28, 2014, 07:54:24 AM »
shouldn't it be?

(vl-cmdf "_.explode" (entlast))