Author Topic: Iteration and (ssget)  (Read 1680 times)

0 Members and 1 Guest are viewing this topic.

ribarm

  • Gator
  • Posts: 3297
  • Marko Ribar, architect
Iteration and (ssget)
« on: August 19, 2018, 02:22:14 PM »
Hi all...
Maybe I am wrong for asking this question as I think I know an answer, but anyway I'll ask it to hear your thoughts...

I have a lisp in which I am iterating through point list...
Every time point is checked - iterated, I acquire (ssget "_C" p p)... Maybe I am wrong, but I suppose I can do this only about 512 checkings (times) which is limit for maximum memory storage of selection sets... Now, if I have more than 512 points, how can I go and pass this issue... I think the answer is that I should put (gc) after (ssget), but I am not sure... Am I wrong or right? Is (gc) answer and if not then what is, and what is then the purpose of (gc) function after all?

Thanks for your insight in advance...
Regards, M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3297
  • Marko Ribar, architect
Re: Iteration and (ssget)
« Reply #1 on: August 19, 2018, 04:00:04 PM »
I figured something, it's not (gc) which remains mistery - I only know that it occurs in some codes with excell to cad and cad to excell lisps...

Here is my finding :

Code - Auto/Visual Lisp: [Select]
  1. (defun c:xxx ( / k )
  2.   (setq k 0)
  3.   (repeat 129 ;; actually maximum number of selection sets is not 512, but 129, you can check this if you remove or comment last (set ... nil) line...
  4.     (setq k (1+ k))
  5.     (set (read (strcat "ss" (itoa k))) nil) ;; this line is prevention only
  6.     (set (read (strcat "ss" (itoa k))) (ssget "_C" '(0.0 0.0 0.0) '(0.0 0.0 0.0)))
  7.     ;;; do your stuff with ssn ;;;
  8.     (set (read (strcat "ss" (itoa k))) nil) ;; this line is neccessity for clearing sel. set out of memory
  9.   )
  10.   (princ)
  11. )
  12.  

I hope that code explains everything very well... Note that if you don't assign sel. set to some variable - if you just use (ssget "_C" p p) and then (ssget "_P") then this limit will never occur... I had luck - in my lisp I did just that without assignments to variables...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Re: Iteration and (ssget)
« Reply #2 on: August 20, 2018, 09:20:33 AM »
Store selset in entity list:


Code: [Select]
(setq k 0)
Command: (setq SelSet (ssget "_C" '(0.0 0.0 0.0) '(1000.0 1000.0 0.0)))
<Selection set: 22>
Command: (set (read (strcat "el" (itoa k))) (vl-remove-if 'listp (mapcar 'cadr (ssnamex SelSet))))
(<Nome entità: 7ff48fe0a2d0> <Nome entità: 7ff48fe0a2e0> ...)
Command: (length el0)
14


roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Iteration and (ssget)
« Reply #3 on: August 20, 2018, 09:34:12 AM »
@ribarm:
I'd like to see the structure of your code. Acquiring 100+ selection sets before processing them seems an unlikely scenario. If you process the set in each iteration and keep using the same variable name for the set, there should be no problems I think.

FYI: A quick check with test code similar to yours shows that BricsCAD does not have this limitation.
Code: [Select]
(defun c:test ( / k)
  (setq k 0)
  (repeat 2048
    (setq k (1+ k))
    (set (read (strcat "ss" (itoa k))) (ssget "_C" '(0.0 0.0 0.0) '(0.0 0.0 0.0)))
  )
  (princ)
)
Code: [Select]
(sslength ss2048) => 15
« Last Edit: August 20, 2018, 09:42:00 AM by roy_043 »

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Iteration and (ssget)
« Reply #4 on: August 20, 2018, 10:08:37 AM »
Backing up a step or two... does it *really* matter if the rest of the points outside of a few hundred are known/not known right away?  There are very few situations where you need more than the immediately adjacent points to a given point.
If you are going to fly by the seat of your pants, expect friction burns.

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