Author Topic: ssget filter list  (Read 12432 times)

0 Members and 1 Guest are viewing this topic.

ssbp

  • Guest
ssget filter list
« on: July 18, 2012, 02:35:40 PM »
I  need code to select all text (0 . "TEXT") with insertion point should be (OR (*.00000000) (*.25000000) (*.50000000) (*.75000000))

I have tried bellowed code, but it doesn't work for some drawings. So, want to select text with insertion point.

Thanks in Advance

(defun c:fe ()

(setq ss1 (ssget '((0 . "TEXT"))))

(if (= ss1 nil)
   (princ "There are no text entity containing your search !")
)

(setq lenth (sslength ss1))

(setq i 0)

(while (< i lenth)
   (setq va (ssname ss1 i))

   (setq b (entget va))

   (setq c (assoc 10 b))

   (setq d (cdr c))

   (setq e (nth 0 d))
   (setq g (fix e))
   (setq h (- e g))
   (if (or (= h 0.00000000) (= h 0.25000000) (= h 0.50000000) (= h 0.75000000)) (setq l 1) (setq l 0))

   (setq f (nth 1 d))
   (setq j (fix f))
   (setq k (- f j))
   (if (or (= k 0.00000000) (= k 0.25000000) (= k 0.50000000) (= k 0.75000000)) (setq m 1) (setq m 0))

   (if (or (= l 0) (= m 0)) (command "circle" d "0.75"))

   (setq i (1+ i))
)
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: ssget filter list
« Reply #1 on: July 18, 2012, 02:40:09 PM »
From my library:
HTH, welcome to the Swamp. 8-)

Code: [Select]
============================================================================
Thread by Stig
http://www.theswamp.org/index.php?topic=1333.msg16766#msg16766

I don't blame you. Filtering by coordinates isn't seen all that often but it is
built into SSGET. You need a relational test looking something like this:

(setq sset (ssget "X" '((-4 . "*,*,>=")(10 0.0 0.0 10.0))))

^this will filter all entities with a group 10 point that has Z greater than or
equal to 10.0

The relational test for each coordinate is separated by commas in the -4 group
and the point is simply given as it appears in the entity list, except each
coordinate is a criterion.

If you need to filter more point groups, you need to provide more -4 groups. For
example, to filter both group 10 and 11:

(setq sset (ssget "X" '((-4 . "*,*,>=")(10 0.0 0.0 10.0)(-4 . "*,*,>")(11 0.0 0.0 10.0))))

=======================================================================
CAB 03.29.08
get any nornal that is not 0 0 1
(setq ss (ssget "X" '((-4 . "<NOT")(210 0.0 0.0 1.0)(-4 . "NOT>")(-4 . "*,*,*")(210 0.0 0.0 1.0))))
=======================================================================
 Example by CAB
 Find a circle with a given center point
 
If the center point of the circle & the start point of the plines are the same this will get them.
(setq mdn (ssget "x" (list '(0 . "circle") (append '(10) stp))) )

If you need some wiggle room try this: [ignoring the z]
(setq wiggle 0.05)
(setq mdn (ssget "x" (list '(0 . "circle")
                            '(-4 . ">,*,*") (list 10 (- (car stp) wiggle) 0 0)
                            '(-4 . "<,*,*") (list 10 (+ (car stp) wiggle) 0 0)
                            '(-4 . "*,>,*") (list 10 0 (- (cadr stp) wiggle) 0)
                            '(-4 . "*,<,*") (list 10 0 (+ (cadr stp) wiggle) 0)
                            ) )
)

Reads like this:
(if  (and  (> (center x) (- (pt x) wiggle))
(< (center x) (+ (pt x) wiggle))
(> (center y) (- (pt y) wiggle))
(< (center y) (+ (pt y) wiggle))
    )
===============================
(ssget "x" '((50 . 3.14159)))  ; need to catch rounding errors
use
(ssget "x" '((-4 . ">") (50 . 3.14158)(-4 . "<") (50 . 3.14160)))



=============================
Example by Luis  uses a list of points

(setq filter (append (list '(-4 . "<AND") '(0 . "AECC_POINT") '(-4 . "<OR"))
                     (mapcar (function (lambda (x) (cons 90 x)))
                             num_list
                     )
                     (list '(-4 . "OR>") '(-4 . "AND>"))
             )
)
(ssget "X" filter)
============================================================
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.

ssbp

  • Guest
Re: ssget filter list
« Reply #2 on: July 18, 2012, 03:03:21 PM »
Thanks for your quick reply,
I have already gone through these post & tried. Acad gives error -; error: bad SSGET list value.
Sorry to say. but i did not understand problem.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: ssget filter list
« Reply #3 on: July 18, 2012, 03:07:15 PM »
Are you searching for a Y value of
Code: [Select]
(OR (*.00000000) (*.25000000) (*.50000000) (*.75000000))
Note that in ACAD the point may not be exact so you need to account for that.
Also with text the insert point may be DXF 10 or DXF 11
« Last Edit: July 18, 2012, 03:12:20 PM by 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.

ssbp

  • Guest
Re: ssget filter list
« Reply #4 on: July 18, 2012, 03:21:13 PM »
No.
i am looking for X and Y co-ordinates. where x will be 0.00000000 or 0.25000000 or 0.50000000 or..........N & same for Y.
how can i provide for (10 *,*,0) ? Z is 0.


CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: ssget filter list
« Reply #5 on: July 18, 2012, 11:45:29 PM »
Looking at your code I came up with this, not tested.
Code: [Select]
(defun c:fe (/ ss i ent elst dxf10 dxf11 dxfx dxfy)

  (if (setq ss (ssget (list '(0 . "TEXT") (cons 410 (getvar "ctab"))))) ; current space only
    (progn
      (setq i -1)
      (while (setq ent (ssname ss (setq i (1+ i))))
        (setq elst  (entget ent)
              dxf10 (cdr (assoc 10 elst))
              dxfx  (rem (car dxf10) 1) ; get fraction only, remove hole number
              dxfy  (rem (cadr dxf10) 1)
              dxf11 (cdr (assoc 11 elst)) ; this if text is not LEFT justified
        )
        (if (not (equal '(11 0.0 0.0 0.0) dxf11))
          (setq dxfx (rem (car dxf11) 1)
                dxfy (rem (cadr dxf11) 1)
          )
        )
        (if (or (vl-some (function (lambda (x) (equal x dxfx 0.00001))) '(0.0 0.25 0.5 0.75))
                (vl-some (function (lambda (x) (equal x dxfy 0.00001))) '(0.0 0.25 0.5 0.75)))
          (entmakex
            (list (cons 0 "CIRCLE")
                  (cons 6 "BYLAYER")
                  ;; (cons 8 "0") ; layer
                  (cons 10 (list dxfx dxfy 0.0))
                  (cons 39 0.0)
                  (cons 40 0.75) ; radius
                  (cons 62 256)
                  (cons 210 (list 0.0 0.0 1.0))
            )
          )
        )
      )
    )
    (princ "There are no text entity containing your search !")
  )
)

But looks like you were looking for x or y where the fraction = 0.00000000 or 0.25000000 or 0.50000000

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.

ssbp

  • Guest
Re: ssget filter list
« Reply #6 on: July 19, 2012, 01:15:49 PM »
Thank for your efforts.
Yes!
You are correct.
I am  looking for x and y where the fraction = *.00000000 or *.25000000 or *.50000000 or *.75000000

Don't want to check remainder after getting selection set. I need selection set with the bellowed condition

(10 *.00000000 *.00000000 0)
(10 *.25000000 *.00000000 0)
(10 *.50000000 *.00000000 0)
(10 *.75000000 *.00000000 0)
(10 *.00000000*.25000000 0)
(10 *.25000000*.25000000 0)
(10 *.50000000*.25000000 0)
(10 *.75000000*.25000000 0)
(10 *.00000000*.50000000 0)
(10 *.25000000*.50000000 0)
(10 *.50000000*.50000000 0)
(10 *.75000000*.50000000 0)
(10 *.00000000*.75000000 0)
(10 *.25000000*.75000000 0)
(10 *.50000000*.75000000 0)
(10 *.75000000*.75000000 0)

I hope you will understand what I need.
Any Idea on this ?



Thanks in advance


CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: ssget filter list
« Reply #7 on: July 19, 2012, 01:44:26 PM »
You can remove the items from the selection set that don't match.

What are you wanting to do with the selection set?
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.

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: ssget filter list
« Reply #8 on: July 19, 2012, 02:12:36 PM »
Code: [Select]
(setq dxfx (rem (car  dxf11) 1)
      dxfy (rem (cadr dxf11) 1)
)
...
(if (or (vl-some (function (lambda (x) (equal x dxfx 0.00001))) '(0.0 0.25 0.5 0.75))
        (vl-some (function (lambda (x) (equal x dxfy 0.00001))) '(0.0 0.25 0.5 0.75)))

Consider perhaps:

Code - Auto/Visual Lisp: [Select]
  1. (equal 0.0 (rem <value> 0.25) 1e-8)

 :-)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: ssget filter list
« Reply #9 on: July 19, 2012, 02:38:28 PM »
Oh, nice one Lee.
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
Re: ssget filter list
« Reply #10 on: July 19, 2012, 02:55:20 PM »
I am  looking for x and y where the fraction = *.00000000 or *.25000000 or *.50000000 or *.75000000

No way that I know of for ssget filter to ignore the integer portion of a real number.
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.

ssbp

  • Guest
Re: ssget filter list
« Reply #11 on: July 20, 2012, 08:26:58 AM »
Thanks for your quick reply.

Please find the attached files.
I have copied the text which has left alignment to the right side of the drawing. If you look on the right upper area, you will observed that the text marked with red rectangle is on the perfect co-ordinate as per requirement (*.00000000 or *.25000000 or *.50000000 or *.75000000). Still AutoCAD marks those text with a circle. I am preparing this lisp file for QC purpose and these things is not acceptable.
I have faced same kind of problem few months back (the program was about to insert block as per mentioned co-ordinate through lisp file, but some blocks goes here and there and not on given co-ordinate). I could not found solution for that.
Instead of checking of co-ordinate after selection, I was thinking to select those text only whose insertion point meets above mentioned condition.

Hope you will understand my problem.

Any solution for this ?

Thanks in Advance.


ronjonp

  • Needs a day job
  • Posts: 7527
Re: ssget filter list
« Reply #12 on: July 20, 2012, 09:00:57 AM »
Still not sure exactly what your looking for but give this a try (using Lee's rem idea). It will make the "good" text green and the "bad" text red.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:fe (/ E I P SS)
  2.   (setq i -1)
  3.   (if (setq ss (ssget '((0 . "TEXT") (72 . 0))))
  4.     (while (setq e (ssname ss (setq i (1+ i))))
  5.       (setq p (cdr (assoc 10 (entget e))))
  6.       (if (and (equal 0.0 (rem (car p) 0.25) 1e-8) (equal 0.0 (rem (cadr p) 0.25) 1e-8))
  7.         (vla-put-color (vlax-ename->vla-object e) 3)
  8.         (vla-put-color (vlax-ename->vla-object e) 1)
  9.         ;;(entmakex (list (cons 0 "CIRCLE") (cons 8 "0") (cons 10 p) (cons 39 0.0) (cons 40 0.75)))
  10.       )
  11.     )
  12.   )
  13.   (princ)
  14. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: ssget filter list
« Reply #13 on: July 20, 2012, 09:08:12 AM »
It an ACAD rounding error
This is what it shows in entget (10 629.0 258.0 0.0)
but this is the actual coordinate  628.9996190536 258.0
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
Re: ssget filter list
« Reply #14 on: July 20, 2012, 09:51:04 AM »
Revised code
Code: [Select]
(defun c:fe (/ ss i ent elst dxf10 dxf11 dxfx dxfy)

  (if (setq ss (ssget (list '(0 . "TEXT")))) ; current space only
    (progn
      (setq i -1)
      (while (setq ent (ssname ss (setq i (1+ i))))
        (setq elst  (entget ent)
              dxf10 (cdr (assoc 10 elst))
              dxfx  (rem (car dxf10) 1) ; get fraction only, remove hole number
              dxfy  (rem (cadr dxf10) 1)
              dxf11 (cdr (assoc 11 elst)) ; this if text is not LEFT justified
        )
        (if (not (equal '(0.0 0.0 0.0) dxf11))
          (setq dxfx (rem (car dxf11) 1)
                dxfy (rem (cadr dxf11) 1)
          )
        )
        (if (or (not(vl-some (function (lambda (x) (equal x dxfx 0.001))) '(0.0 0.25 0.5 0.75 1.0)))
                (not(vl-some (function (lambda (x) (equal x dxfy 0.001))) '(0.0 0.25 0.5 0.75 1.0))))
          (entmakex
            (list (cons 0 "CIRCLE")
                  (cons 6 "BYLAYER")
                  (cons 8 "0") ; layer
                  (assoc 10 elst)
                  (cons 39 0.0)
                  (cons 40 0.75) ; radius
                  (cons 62 256)
                  (cons 210 (list 0.0 0.0 1.0))
            )
          )
        )
      )
    )
    (princ "There are no text entity containing your search !")
  )
)
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.

ssbp

  • Guest
Re: ssget filter list
« Reply #15 on: July 20, 2012, 10:04:40 AM »
Thanks CAB,

I understand that, this happens to most upper right text i.e. - (A2)
But what about texts marked together with red rectangle i.e. - ENABLE RELAY & 3243,3243,3248
It happens to these texts also. And I don't think its ACAD rounding error.
Please help.


Thanks for code ronjonp.

I need ssget function with extended filter list like (cons 10 (OR (*.00000000) (*.25000000) (*.50000000) (*.75000000))) or with any other idea to select text entities with above insertion condition.

I hope this will give clear idea what I want

Thanks to both of you.
Awaiting for your positive reply.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: ssget filter list
« Reply #16 on: July 20, 2012, 10:25:39 AM »
My last routine ignores these as correct in my test.
I did have to convert the DWG to ACAD2006 for my test.
Did you try my last revision? Did it flagged the
ENABLE RELAY
3243,3243,3248

in the red rectangle?
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
Re: ssget filter list
« Reply #17 on: July 20, 2012, 10:55:56 AM »
Use the fuzz to adjust tolerance.
How close to a perfect match do you need?
0.2500000  +/- .01  ?

Code: [Select]
(defun c:fe (/ ss i ent elst dxf10 dxf11 dxfx dxfy fuzz)
  (setq fuzz 0.01)
  (if (setq ss (ssget (list '(0 . "TEXT"))))
    (progn
      (setq i -1)
      (while (setq ent (ssname ss (setq i (1+ i))))
        (setq elst  (entget ent)
              dxf10 (cdr (assoc 10 elst))
              dxfx  (rem (car dxf10) 1) ; get fraction only, remove hole number
              dxfy  (rem (cadr dxf10) 1)
              dxf11 (cdr (assoc 11 elst)) ; this if text is not LEFT justified
        )
        (if (not (equal '(0.0 0.0 0.0) dxf11))
          (setq dxfx (rem (car dxf11) 1)
                dxfy (rem (cadr dxf11) 1)
          )
        )
        (if (or (not(vl-some (function (lambda (x) (equal x dxfx fuzz))) '(0.0 0.25 0.5 0.75 1.0)))
                (not(vl-some (function (lambda (x) (equal x dxfy fuzz))) '(0.0 0.25 0.5 0.75 1.0))))
          (entmakex
            (list (cons 0 "CIRCLE")
                  (cons 6 "BYLAYER")
                  (cons 8 "0") ; layer
                  (assoc 10 elst)
                  (cons 39 0.0)
                  (cons 40 0.75) ; radius
                  (cons 62 256)
                  (cons 210 (list 0.0 0.0 1.0))
            )
          )
        )
      )
    )
    (princ "There are no text entity containing your search !")
  )
)
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.

ssbp

  • Guest
Re: ssget filter list
« Reply #18 on: July 20, 2012, 01:56:05 PM »
Thanks you

Yes! I have tried all possibilities. Everything! Still pursuing problem  :-(

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: ssget filter list
« Reply #19 on: July 20, 2012, 02:41:35 PM »
How close to a perfect match do you need?
0.2500000  +/- .005  ?

0.245
0.255
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.

ssbp

  • Guest
Re: ssget filter list
« Reply #20 on: July 20, 2012, 04:07:25 PM »
0.00000000

I have also tried by changing value of fuzz i.e. - 0.00000000

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: ssget filter list
« Reply #21 on: July 20, 2012, 04:23:35 PM »
0.0 will not work, object insertion points can vary. You need 0.00001 or something like that.
See for your self, try this on the text objects you think are in the correct position.
This is what I get 628.9996190536 258 0
You see it should be 629 but it is off by 0.000380946
Code: [Select]
(defun c:test()
  (setq ent (car(entsel))
        elst (entget ent)
        dxf10 (assoc 10 elst))
  (princ (strcat(rtos (cadr dxf10) 2 10)" "(rtos (caddr dxf10) 2 10)" "(rtos (cadddr dxf10) 2 10)))
  (princ)
)
Are you wanting to move the text to the exact location if they are not perfect?
« Last Edit: July 20, 2012, 04:27:57 PM by 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
Re: ssget filter list
« Reply #22 on: July 20, 2012, 06:15:21 PM »
OK try this for fixing the text.
Code: [Select]
(defun c:fe (/ ss i ent elst dxf10 dxf11 dxfx dxfy fuzz)
  (setq fuzz 0.00001)

  ; By MP
  (defun round (number by)
    (if (zerop by)
      number
      (+ (* (fix (/ number (setq by (abs by)))) by)
         (if (< (* 0.5 by) (rem number by))
           by
           0
         )
      )
    )
  )
  (defun myround (r) (* (round (/ r 0.25) 1.) 0.25))

  (if (setq ss (ssget (list '(0 . "TEXT") '(72 . 0))))
    (progn
      (setq i -1)
      (while (setq ent (ssname ss (setq i (1+ i))))
        (setq elst  (entget ent)
              dxf10 (assoc 10 elst)
              dxfx  (rem (cadr dxf10) 1) ; get fraction only, remove hole number
              dxfy  (rem (caddr dxf10) 1)
        )

        (if (or (not (vl-some (function (lambda (x) (equal x dxfx fuzz))) '(0.0 0.25 0.5 0.75 1.0)))
                (not (vl-some (function (lambda (x) (equal x dxfy fuzz))) '(0.0 0.25 0.5 0.75 1.0)))
            )
          (progn
            (setq newpoint (list 10 (myround (cadr dxf10)) (myround (caddr dxf10)) 0.0))
            (entmod (subst newpoint dxf10 elst))
            (entmakex
              (list (cons 0 "CIRCLE")
                    (cons 6 "BYLAYER")
                    (cons 8 "0") ; layer
                    (assoc 10 elst)
                    (cons 39 0.0)
                    (cons 40 0.75) ; radius
                    (cons 62 256)
                    (cons 210 (list 0.0 0.0 1.0))
              )
            )
          )
        )
      )
    )
    (princ "There are no text entity containing your search !")
  )
)
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
Re: ssget filter list
« Reply #23 on: July 25, 2012, 08:42:25 AM »
Where did you go???
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.

ssbp

  • Guest
Re: ssget filter list
« Reply #24 on: September 07, 2012, 12:54:30 AM »
Sorry guys,
I was busy with some urgent job on site.
I will be back within 2/3 days regarding this.

Thanks for reply.