Author Topic: to make fast lisp  (Read 4395 times)

0 Members and 1 Guest are viewing this topic.

dussla

  • Bull Frog
  • Posts: 291
to make fast lisp
« on: December 24, 2009, 09:36:29 AM »
(setq  sela (ssget "x" ) )
(command "change" sela "" "P"  "c" "251" "")

hi
friend ,  i need  your help again ~~~

above lisp routine  is to change color
but that routine is very slow  in big dwg file
is there the most fast routine to change color ~
i will wait freinds answer ~
mery chrismas

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: to make fast lisp
« Reply #1 on: December 24, 2009, 09:45:57 AM »
Either of these:

Code: [Select]
(defun c:cCol1 (/ i ss ent)
  (vl-load-com)

  (if (setq i -1 ss (ssget "_X"))
    (while (setq ent (ssname ss (setq i (1+ i))))
      (vla-put-color (vlax-ename->vla-object ent) 251)))

  (princ))



(defun c:cCol2 (/ i ss ent elst)

  (if (setq i -1 ss (ssget "_X"))
    (while (setq ent (ssname ss (setq i (1+ i))))
      (setq elst (entget ent))

      (if (assoc 62 elst)
        (entmod (subst (cons 62 251) (assoc 62 elst) elst))
        (entmod (append elst (list (cons 62 251)))))))

  (princ))


Not sure which is quicker
« Last Edit: December 24, 2009, 10:01:14 AM by Lee Mac »

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: to make fast lisp
« Reply #2 on: December 24, 2009, 09:52:22 AM »
You might find this thread to be useful.
http://www.theswamp.org/index.php?topic=55.0
TheSwamp.org  (serving the CAD community since 2003)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: to make fast lisp
« Reply #3 on: December 24, 2009, 10:06:26 AM »
Interesting result, on a SelectionSet of 10,000 points:

Code: [Select]
<< ActiveX took: 1.1700 secs. >>

<< Entmod took: 0.9360 secs. >>

Code: [Select]
<< ActiveX took: 1.1390 secs. >>

<< Entmod took: 0.9670 secs. >>

Code: [Select]
<< ActiveX took: 1.1240 secs. >>

<< Entmod took: 0.9830 secs. >>


Code: [Select]
(defun c:cCol1 (/ i ss ent time)
  (vl-load-com)

  (setq time (getvar "millisecs"))

  (if (setq i -1 ss (ssget "_X"))
    (while (setq ent (ssname ss (setq i (1+ i))))
      (vla-put-color (vlax-ename->vla-object ent) 251)))

  (princ (strcat "\n<< ActiveX took: "
                 (rtos (/ (- (getvar "millisecs") time) 1000.) 2 4) " secs. >>"))

  (princ))



(defun c:cCol2 (/ i ss ent elst time)

  (setq time (getvar "millisecs"))

  (if (setq i -1 ss (ssget "_X"))
    (while (setq ent (ssname ss (setq i (1+ i))))
      (setq elst (entget ent))

      (if (assoc 62 elst)
        (entmod (subst (cons 62 251) (assoc 62 elst) elst))
        (entmod (append elst (list (cons 62 251)))))))

  (princ (strcat "\n<< Entmod took: "
                 (rtos (/ (- (getvar "millisecs") time) 1000.) 2 4) " secs. >>"))

  (princ))

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: to make fast lisp
« Reply #4 on: December 24, 2009, 10:39:32 AM »
Just out of curiousity...

Code: [Select]
Command: tocolor

<< FULL ActiveX took: .484 secs. >>

Command:
Command:
TOCOLOR
<< FULL ActiveX took: .469 secs. >>

Command:
Command: ccol1

<< ActiveX took: .61 secs. >>

Command:
Command: ccol2

<< Entmod took: .953 secs. >>


Code: [Select]
(defun c:ToColor (/ time ss)
  (setq time (getvar "millisecs"))
  (if (setq ss (ssget "_X"))
    (progn
       (vlax-for x (setq ss (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
         (vla-put-color x 251))
      (vla-delete ss)))
    (princ (strcat "\n<< FULL ActiveX took: " (rtos (/ (- (getvar "millisecs") time) 1000.) 2 4) " secs. >>"))
  (princ))
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: to make fast lisp
« Reply #5 on: December 24, 2009, 10:44:14 AM »
Ooo.. get you   :-P

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: to make fast lisp
« Reply #6 on: December 24, 2009, 10:48:07 AM »
That is great to know - I may have to start using that method a bit more  ;-)

On 10,000 points

Code: [Select]
<< ActiveX took: 1.0610 secs. >>

<< Entmod took: 0.9050 secs. >>

<< FULL ActiveX took: 0.7950 secs. >>

Code: [Select]
<< ActiveX took: 1.0460 secs. >>

<< Entmod took: 0.9680 secs. >>

<< FULL ActiveX took: 0.7800 secs. >>

Nice one Alan  :-)


So I'm guessing "vlax-ename->vla-object" takes up the most time.

fixo

  • Guest
Re: to make fast lisp
« Reply #7 on: December 24, 2009, 11:16:14 AM »
Here is my attempt

Code: [Select]
(defun C:axcol (/ acapp adoc color pfs time)
(setq adoc (vla-get-activedocument
     (setq acapp (vlax-get-acad-object)
     )
      )
      )
(setq time (getvar "millisecs"))
(setq color (vla-getinterfaceobject acapp
(strcat "AutoCAD.AcCmColor." (itoa (atoi (getvar "acadver"))))))

(vla-put-colormethod color acColorMethodByACI)
(vla-put-colorindex color 251)
(setq pfs (vla-get-pickfirstselectionset adoc))
(vlax-invoke-method pfs 'Clear)
(vla-select pfs acselectionsetall)
(vlax-for a pfs
  (vla-put-truecolor a color)
  )
  (vlax-release-object color)
(princ (strcat "\n<< ActiveX took: "
                 (rtos (/ (- (getvar "millisecs") time) 1000.) 2 4) " secs. >>"))

(setq time (getvar "millisecs"))
    (princ)
  )
Result:
Code: [Select]
11,000 circles first run
<< Full ActiveX took: 1.7350 secs. >>
11,000 circles second run
<< Full ActiveX took: 1.4840 secs. >>
11,000 points first run
<< Full ActiveX took: 1.0160 secs. >>
11,000 points second run
<< Full ActiveX took: 0.9220 secs. >>

~'J'~
« Last Edit: December 24, 2009, 01:16:23 PM by fixo »

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: to make fast lisp
« Reply #8 on: December 24, 2009, 11:25:06 AM »
Yeah, I tested this a while back, out of curiosity. It would be even faster if vla-get-activedocument is a global variable and already defined. :wink:

If you notice, more of my stuff (lately) has that method over anything else.

From what I remember, repeat was even faster than while, but don't quote me on that.

That is great to know - I may have to start using that method a bit more  ;-)

On 10,000 points

Code: [Select]
<< ActiveX took: 1.0610 secs. >>

<< Entmod took: 0.9050 secs. >>

<< FULL ActiveX took: 0.7950 secs. >>

Code: [Select]
<< ActiveX took: 1.0460 secs. >>

<< Entmod took: 0.9680 secs. >>

<< FULL ActiveX took: 0.7800 secs. >>

Nice one Alan  :-)


So I'm guessing "vlax-ename->vla-object" takes up the most time.

Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: to make fast lisp
« Reply #9 on: December 25, 2009, 04:00:29 AM »
Hi,

Instead of using (ssget "_X"), it should be a little faster to run directly trough the entire database

Code: [Select]
(defun c:dbToColor (/ time)
  (setq time (getvar "millisecs"))
  (vlax-for l (vla-get-Layouts
                (vla-get-ActiveDocument (vlax-get-acad-object))
              )
    (vlax-for o (vla-get-Block l)
      (vla-put-color o 256)
    )
  )
  (princ (strcat "\n<< FULL ActiveX (w/out ssget) took: "
                 (rtos (/ (- (getvar "millisecs") time) 1000.) 2 4)
                 " secs. >>"
         )
  )
  (princ)
)

You can have a look here too
Speaking English as a French Frog

xianaihua

  • Guest
Re: to make fast lisp
« Reply #10 on: December 25, 2009, 05:23:57 AM »
Hi,gile!

thanks!
Provide you with the program is the fastest!