Author Topic: How to process SelectionSet faster?  (Read 6748 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: How to process SelectionSet faster?
« Reply #15 on: December 01, 2012, 01:19:16 PM »
Using
Code: [Select]
(mapcar (function (lambda (code) (cdr (assoc code ed)))) '(10 11 12 13))will place my functions at the very bottom benchmark list

Using ssnamex will place the functions at the bottom -  ssnamex is incredibly slow  :wink:

BlackBox

  • King Gator
  • Posts: 3770
Re: How to process SelectionSet faster?
« Reply #16 on: December 01, 2012, 02:02:36 PM »
What are you doing inside the loop? The entget might be where most of the time is wasted. If so could your routine be redesigned not to need entget? I.e. just generate a new list to pass to entmod? Or even use the new properties methods.
 
Or could your routine be redesigned to use vla-objects? If so then using Method 5 from Lee's samples here might be faster.

Perhaps I've overlooked something, but for such a large selection, why not instead just iterate the ActiveSelectionSet Object  :??

RM, that was my suggestion.

As I said, perhaps I overlooked something... Having only skimmed the prior posts, I missed your 'use vla-objects' question, and did not preview the link provided. Oops.
"How we think determines what we do, and what we do determines what we get."

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: How to process SelectionSet faster?
« Reply #17 on: December 03, 2012, 12:09:54 AM »
irneb
Your sstest_vla returns wrong result (you typed cords instead coords...)
Thanks, fixed that in attached.
Using ssnamex will place the functions at the bottom -  ssnamex is incredibly slow  ;)
Thought so too, though they're not as bad as all that.
Code: [Select]
Testing on selection set of 1000 entities
Benchmarking ......... done for 32 iterations. Sorted from fastest.
Statement                                Increment  Time(ms) Normalize  Relative
--------------------------------------------------------------------------------
(SSTEST_VLA)                                    32      1763      1763     22.23
(SSTEST_REPEATDXF)                              16      1216      2432     16.12
(SSTEST_WHILEDXF)                               16      1217      2434     16.11
(SSTEST_MAPCARDXF)                              16      1248      2496     15.71
(SSTEST_FOREACHDXF)                             16      1264      2528     15.51
(SSTEST_VLA_DXF)                                 8      1420      5680      6.90
(SSTEST_REPEATPROP)                              2      1279     20464      1.92
(SSTEST_VLA_PROP)                                2      1436     22976      1.71
(SSTEST_WHILEPROP)                               2      2450     39200      1.00
--------------------------------------------------------------------------------
While the are slower than the normal ssname / vla versions, they're not as bad as the convert / prop versions. But that's because of the internals of the loop itself methinks. I think we've established somewhere else that the ssnamex is slow in comparison to a loop with ssname (if only looking at the selection iteration itself).
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: How to process SelectionSet faster?
« Reply #18 on: December 03, 2012, 02:06:39 PM »
I've done a little TIN processing work in LISP, and can vouch for the (relative) efficency of caching object data rather than repeatedly extracting/manipulating it.  The number of cycles can also be substantially reduced with some appropriate shortcuts to exit/jump to the next loop when there are no more valid calculation to make, some pre-sorting of triangles wrt. coordinates, and working with links to stored vertices of a connected triangle rather than comparing coordinates.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

litss

  • Guest
Re: How to process SelectionSet faster?
« Reply #19 on: December 27, 2012, 10:32:37 AM »
Thanks all you guys. I'm sorry to reply so late due to the heavy work...

Anyway, I will study all your sample routines to make mine works better. Actually, I am trying to convert some FEM models, which were drawn by CAD, into txt files. I need to get all the coordinates of "3dface" vertex and the layername of each tri-angle. I am not very good at Autolisp, especially VLa-xx. But I can write some simple loops to get the coordinates and princ them into a txt files. That is the way I am doing now. And each time I convert a model with 60,000 elements (3dface triangles), my laptop will need to run around 45 minites...I can only drink and wait...

I've also tried to save the CAD dwg into dxf, then read the dxf file and make it a big list to pick out the coordinates info. But it is nothing better than just repeat the ssname and entget.


Didge

  • Bull Frog
  • Posts: 211
Re: How to process SelectionSet faster?
« Reply #20 on: January 03, 2013, 08:35:55 AM »
Litss,

I suspect your long wait may be due to another coding issue altogether.
Using similar code on a slow workstation I'm processing 20,000 faces in less than a second.

Code: [Select]
(defun c:EXPORT-SURFACE ( / ent ss tmp c nfile start en elst p1 p2 p3 str)
  (if (and (setq ent (car (entsel "\nPick 3D Surface >")))
   (setq ss (ssget "X" (list (cons 0 "3DFACE")(cons 8 (cdr (assoc 8 (entget ent)))))))
   (if tinout
             (setq tmp (getfiled "Export 3D Surface to file" tinout "TIN" 1))
     (setq tmp (getfiled "Export 3D Surface to file" ""     "TIN" 1))
           )
      )
    (progn
      (setq tinout tmp c -1 nfile (open tinout "w") start (getvar "DATE"))
      (repeat (sslength ss)
        (setq en (ssname ss (setq c (1+ c))) elst (entget en))
        (setq p1 (cdr (assoc 10 elst)) p2 (cdr (assoc 11 elst)) p3 (cdr (assoc 12 elst)))
        (setq str (strcat (rtos (car p1) 2 3) "," (rtos (cadr p1) 2 3) "," (rtos (caddr p1) 2 3) ","
                    (rtos (car p2) 2 3) "," (rtos (cadr p2) 2 3) "," (rtos (caddr p2) 2 3) ","
  (rtos (car p3) 2 3) "," (rtos (cadr p3) 2 3) "," (rtos (caddr p3) 2 3)))
        (write-line str nfile)
      )
      (princ (strcat "\rExport Complete - Elapsed time: " (rtos (* 86400.0 (- (getvar "date") start)) 2 2) " secs."))
      (close nfile)
    )
  )
  (princ)
)
Think Slow......

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: How to process SelectionSet faster?
« Reply #21 on: January 04, 2013, 12:06:56 AM »
Yep, could you perhaps post the rest of your code? It does sound pretty strange to wait 45 min (even on 60000 items). There must be some other thing which is taking the bulk of the processing time. Perhaps that could be optimized.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.