Author Topic: code is very slow problem  (Read 1151 times)

0 Members and 1 Guest are viewing this topic.

dussla

  • Bull Frog
  • Posts: 297
code is very slow problem
« on: April 05, 2018, 09:28:27 AM »
i made  this code  as referenced other code
that code is very slow
my com is down  often
what problem
can you test my attched file ?~

Code - Auto/Visual Lisp: [Select]
  1. (defun c:txtb (/ ss i sn pts n s in psn)
  2.   ;
  3.   (if (setq ss (ssget '((0 . "*POLYLINE"))))
  4.     (repeat (setq i (sslength ss))
  5.             (setq sn (ssname ss (setq i (1- i))))
  6.             (if  (vlax-curve-isclosed sn)
  7.               (progn
  8.                 (setq x (entget sn))
  9.                 (setq pts (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) x)))
  10.                 (if (setq s (  ssget "_WP" pts '((0 . "text"))  )   )
  11.                   (progn
  12.                     (setq en (ssname s 0))
  13.                     (setq elist (entget en))
  14.                     (setq txt (cdr (assoc 1 elist)))
  15.                     (setq sum  (atof txt) )
  16.                     (command "extrude"  sn  "" sum  "" )
  17.                     )
  18.                   )
  19.                 )
  20.               )
  21.             )
  22.     )
  23.   )

EDIT (John): Added code code tag for better readability.
« Last Edit: April 05, 2018, 09:36:48 AM by John Kaul (Se7en) »

BIGAL

  • Swamp Rat
  • Posts: 1434
  • 40 + years of using Autocad
Re: code is very slow problem
« Reply #1 on: April 06, 2018, 08:57:35 PM »
Maybe a couple of ideas using vlisp

(setq pts (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) x))) as it is a pline you can get-cordinates directly using VL

(setq txt (cdr (assoc 1 elist))) You can get textstring rather than use entgets.

Code: [Select]
; pline co-ords example
; By Alan H
(defun getcoords (ent)
  (vlax-safearray->list
    (vlax-variant-value
      (vlax-get-property
    (vlax-ename->vla-object ent)
    "Coordinates"
      )
    )
  )
)
 
(defun co-ords2xy ()
; convert now to a list of xy as co-ords are x y x y x y if 3d x y z x y z
(setq numb (/ (length co-ords) 2))
(setq I 0)
(repeat numb
(setq xy (list (nth i co-ords)(nth (+ I 1) co-ords) ))
(setq co-ordsxy (cons xy co-ordsxy))
(setq I (+ I 2))
)
)

; program starts here
(setq co-ords (getcoords (car (entsel "\nplease pick pline"))))
(co-ords2xy)
; look at variable co-ordsxy which is a list of vertices
(princ co-ordsxy)
A man who never made a mistake never made anything