Author Topic: sort items into a selection set.  (Read 22147 times)

0 Members and 2 Guests are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
sort items into a selection set.
« Reply #15 on: November 25, 2003, 09:23:09 AM »
After you have sorted the "objects" what do you want in return, vla-objects?
TheSwamp.org  (serving the CAD community since 2003)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
sort items into a selection set.
« Reply #16 on: November 25, 2003, 09:36:38 AM »
smad

Quote
You say that you don't get how the LAMBDA works? Hmm, you did it the same way in your routine  What part of it is unclear?


I'm a poor coder but a Master Code Thief :lol:

I'll have to get back to you this afternoon, duity calls.

CAB
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

daron

  • Guest
sort items into a selection set.
« Reply #17 on: November 25, 2003, 09:38:44 AM »
Quote from: Mark Thomas
After you have sorted the "objects" what do you want in return, vla-objects?


Oh yeah.

SMadsen

  • Guest
sort items into a selection set.
« Reply #18 on: November 25, 2003, 09:39:24 AM »
Hehe CAB .. as long as you share what you 'borrow' :D

Daron, that made sense, thanks.

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
sort items into a selection set.
« Reply #19 on: November 25, 2003, 10:23:00 AM »
>But what if the number is negative?
>but what if it's a real?
This is tough! I can do a negitive (sorta) and a real using a combination of 'vl-string->list' and 'vl-remove-if BUT, if you have something like 15.2A-B, hahaha......... or AS1.2DF.S forget it. :D

BTW check this out.
Code: [Select]

(vl-remove-if
      '(lambda (z)
(cond ((> z 58))
      ((< z 45))
      ((= z 47))
      )
)
      lst
      )
TheSwamp.org  (serving the CAD community since 2003)

daron

  • Guest
sort items into a selection set.
« Reply #20 on: November 25, 2003, 10:46:04 AM »
Thanks Mark, but I highly doubt negatives, real, or alpha strings will ever give a problem.

daron

  • Guest
sort items into a selection set.
« Reply #21 on: November 25, 2003, 11:52:33 AM »
Mark, your first set that you put out is beautiful and useful for this job with just a little tweaking. Blink of an eye.

KerryB

  • Guest
sort items into a selection set.
« Reply #22 on: November 25, 2003, 02:06:51 PM »
As a casual viewer of this thread I must say I agree with Stig regarding not knowing what was actually required untill well into the thread.

Finding answers is sometimes difficult.
Finding the correct question is harder.

... this is not meant to pick on anybody, just an observation of something I am becoming increasingly aware of.  :)

Regards
Kerry

daron

  • Guest
sort items into a selection set.
« Reply #23 on: November 25, 2003, 02:58:46 PM »
Well, I wasn't trying to be too vague. I just wasn't sure how much info was too much. I thought what I had written was enough. I wasn't asking for anybody to do the work for me, just throw out some ideas, similar to the time Stig helped just by throwing out a couple of functions I hadn't considered. At the same time I knew I'd get a few different responses and thought it would be a good way of showing those who are just learning, something different. As far as not knowing until well into the thread, I'm sorry. At the same time, everybody had the right general idea and even though I stopped at the first one I tried, I'm sure they all work well. Mark's was able to take a function that would take 10 seconds to process for 112 lots and using parts of his I now notice no delay. All that was required was some input. Thank you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
sort items into a selection set.
« Reply #24 on: November 25, 2003, 07:53:35 PM »
Stig

i posted my comments or questions about lambda over in the Teach Me forum.

When and if you have time :)

CAB
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

daron

  • Guest
sort items into a selection set.
« Reply #25 on: November 26, 2003, 12:03:35 AM »
What, you can't hi-jack this thread like most people? You gotta go create your own, and in a different forum even. I see how it is. :lol:


Good work over there. I normally would be moving it back into this forum, but you set it up in such a way that it seems to start off as a tutorial.



*edited to make my intention more clear.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
sort items into a selection set.
« Reply #26 on: November 26, 2003, 08:07:47 AM »
No hijacking here, I just didn't want to interfere with your theme.

The lambda & other functions are an area I have been wanting to explore
because I didn't understand how they worked but your routine caused me
to look harder at them. Looking at how they preform in VLIDE during
trace I have begun to see how they function. I have  used
'(lambda (E1 E2) (< (cdr E1) (cdr E2)) and it did not trace but
this did (function(lambda (E1 E2) (< (cdr E1) (cdr E2))))) and I was
able to see it.


You all speak the language so fluently and I only know enough words to
get the jest of what you are saying. It is frustrating at times but I have
learned enough to steal peaces of code and reuse them. :)

CAB
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
sort items into a selection set.
« Reply #27 on: November 26, 2003, 08:28:33 AM »
Cab...me thinks that was another issue of sarcasm
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
sort items into a selection set.
« Reply #28 on: November 26, 2003, 10:02:47 AM »
I thought so, but you can't always tell :D

CAB
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
sort items into a selection set.
« Reply #29 on: November 27, 2003, 08:29:08 AM »
SMadsen,
I'm at it again. :)
Here is your routine with corrections to my comments
Also added a few more & added to the calling routine

This is the first time I have looked hard at the OR statement
Code: [Select]
((or ss (setq ss (getss lyr)))
if the first condition is true nothing else is processed and True is returned

Can't believe how much I have learned from this one routine, Thanks
As Se7en said looking at each line in TRACE mode will tell you volumes.
I think I'll search out a few more of your routines to look at if you don't mind?
  (as soon as I can get time)


Code: [Select]
;; Sort function by SMadsen
;; function called with sel set and layer name
;;  note, values ss or lay may be nil
(defun selsort (ss lyr / elst a n ent num? newSs) ; entry point of routine
 
  ;;  ======================================================
  ;;  LOCAL subroutine getss attempts to get a selection set
  ;;  ======================================================
  (defun getss (l) ; if sel set nil, go get one
    (ssget "X" ; get all of drawing in a list with the following filter
  (list '(0 . "TEXT") ; get only TEXT objects
(cons 8        ; get only items on this layer (8 . layername)
      (cond (l)   ; COND test for nil layername, returns layer NAME
    ("*") ; OR returns the wildcard character to get ALL Layers
      )
)
  )
    )
  )

  ;;  ========================
  ;;  Main routine starts here
  ;;  ========================
  (cond  ; this cond stmt has only one condition & return nil if false
    ; if ss is not nil skip (setq ss (getss lyr))) and proceed to the next line
    ; if is nil, call subroutine getss and if can't find any on layer do nothing
    ((or ss (setq ss (getss lyr)))
     (setq a 0  ; set pointer to 0
  newSs (ssadd) ; create an empty sel set
     )
     (repeat (sslength ss) ; loop for each item in the sel set
       (setq ent (ssname ss a)) ; get the name of each item in the set one at a time
       (if (numberp  ; test num? to see if it is a number, skip (setq elst if not number
    (setq num?  ; store the word in var num?
   (read  ; get the first word if text has a space character
     (cdr  ; get the TEXT only
(assoc 1  ; get the TEXT doted pair
      (entget ent) ; get entity data
      ))))) ; end of the "if test"
;;  if test is true do this next setq
(setq elst ; build a list of name and text
(cons   ; add dotted pair list to elst ((ename . 25) (ename . 40))
 (cons ent num?) ; create a dotted pair of name & number (ename . 25)
    elst))
       ) ; end if
       (setq a (1+ a)) ; increment pointer
     ) ; end repeat
     (setq elst ; rebuild list of sorted name & text
   ;;;  you got me, don't understand yet how this works
   (vl-sort elst (function (lambda (x y) (< (cdr x) (cdr y)))))
     )
     (foreach n elst ; step through newly sorted doted pair list, n = (ename . 25)
       (ssadd  ; add ename to end of new sel set newSs
(car n)   ; get ename only from dotted pair
    newSs)
     ) ; end foreach
    ) ; end of cond 1
  ) ; end cond
 
  ;;  "foreach" returns the last value & "ssadd" returns the sel set after each add
  ;;   therfore the sorted sel set is returned when the function is complete
  ;;  EXCEPT if no ss was passed AND no ss was found on the layer
  ;;  THEN nil is returned

 
); end defun selsort


;; routine to call function
(defun C:srt (/ TextSs)
 
  ;;  call selsort with layer only so All text on that layer will be analyzed
  (setq TextSs (selsort nil "zDtl xLight 3"))
 
  ;;  call selsort with nil nil and all text on all layers will be analyzed
  (setq TextSs (selsort nil nil))
 
  ;;  call selsort with user picked sel set, allow all layers to be analyzed
  (prompt "\nSelect text to be sorted.")
  (setq TextSs (selsort (ssget) nil))
 
  (princ)

)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.