Author Topic: SSGET Filter out XRefs along with other items  (Read 248 times)

0 Members and 1 Guest are viewing this topic.

cmwade77

  • Swamp Rat
  • Posts: 1361
SSGET Filter out XRefs along with other items
« on: May 02, 2022, 08:06:53 PM »
I would like to filter out RAY,XLINE,*TEXT and XREFs, but not blocks from SSGET

I have tried:
Code: [Select]
(setq SS (ssget "_:L" '((-4 . "<NOT") (-4 . "<AND") (0 . "INSERT") (1 . "*") (-4 . "AND>") (0 . "RAY,XLINE,*TEXT") (-4 . "NOT>"))))
As well as few other variations and I can't seem to get it to work. I am sure that I am missing something obvious.

ronjonp

  • Needs a day job
  • Posts: 7404
Re: SSGET Filter out XRefs along with other items
« Reply #1 on: May 02, 2022, 10:44:35 PM »
There isn't a direct filter for XREF's.

Windows 11 x64 - AutoCAD /C3D 2022

Custom Build PC

dexus

  • Newt
  • Posts: 55
Re: SSGET Filter out XRefs along with other items
« Reply #2 on: May 03, 2022, 07:07:45 AM »
How about something like this?
Filter by a list of known blocks, so it won't select the ones that are xrefs.
Code - Auto/Visual Lisp: [Select]
  1. (setq SS (ssget "_:L"
  2.   (list
  3.     '(0 . "INSERT")
  4.     (cons
  5.       2
  6.       (substr ; remove first ","
  7.         (apply
  8.           'strcat ; combine string
  9.           (mapcar
  10.             (function (lambda (s) (strcat "," s))) ; add "," in front so it can be used as a filter
  11.             (acet-table-name-list (list "block" 4 16)) ; List of blocks excluding xref's
  12.           )
  13.         )
  14.         2
  15.       )
  16.     )
  17.   )
  18. ))
« Last Edit: May 03, 2022, 07:18:54 AM by dexus »

mhupp

  • Newt
  • Posts: 136
Re: SSGET Filter out XRefs along with other items
« Reply #3 on: May 03, 2022, 07:14:44 AM »
There isn't a direct filter for XREF's.

You could put xref's on a custom layer and filter out said layer  (8 . "layname")

Code - Auto/Visual Lisp: [Select]
  1. (setq SS (ssget "_:L" '((-4 . "<NOT") (-4 . "<AND") (0 . "INSERT") (1 . "*") (-4 . "AND>") (0 . "RAY,XLINE,*TEXT") (8 . "layername") (-4 . "NOT>"))))

MSTG007

  • Gator
  • Posts: 2554
  • I can't remeber what I already asked! I need help!
Re: SSGET Filter out XRefs along with other items
« Reply #4 on: May 03, 2022, 08:03:06 AM »
Thats a great idea.

This is basic.

Code: [Select]
(defun c:XRL (/ objs ent i)
(setq objs (ssget "_X" '((0 . "INSERT"))))
(repeat (setq i (sslength objs))
       (setq ent (entget (ssname objs (setq i (1- i)))))
            (if (= 4 (logand 4 (cdr (assoc 70 (tblsearch "BLOCK" (cdr (assoc 2 ent)))))))
    (entmod (subst (cons 8 "LAYERNAME")(assoc 8 ent) ent))))
)
Civil3D 2020

cmwade77

  • Swamp Rat
  • Posts: 1361
Re: SSGET Filter out XRefs along with other items
« Reply #5 on: May 03, 2022, 11:43:48 AM »
There isn't a direct filter for XREF's.

You could put xref's on a custom layer and filter out said layer  (8 . "layname")

Code - Auto/Visual Lisp: [Select]
  1. (setq SS (ssget "_:L" '((-4 . "<NOT") (-4 . "<AND") (0 . "INSERT") (1 . "*") (-4 . "AND>") (0 . "RAY,XLINE,*TEXT") (8 . "layername") (-4 . "NOT>"))))

While this would be a great idea, unfortunately, I am needing to work with drawings often created by other companies and they don't always do this and I want to try to avoid modifying their drawings.

cmwade77

  • Swamp Rat
  • Posts: 1361
Re: SSGET Filter out XRefs along with other items
« Reply #6 on: May 03, 2022, 12:23:21 PM »
How about something like this?
Filter by a list of known blocks, so it won't select the ones that are xrefs.
Code - Auto/Visual Lisp: [Select]
  1. (setq SS (ssget "_:L"
  2.   (list
  3.     '(0 . "INSERT")
  4.     (cons
  5.       2
  6.       (substr ; remove first ","
  7.         (apply
  8.           'strcat ; combine string
  9.           (mapcar
  10.             (function (lambda (s) (strcat "," s))) ; add "," in front so it can be used as a filter
  11.             (acet-table-name-list (list "block" 4 16)) ; List of blocks excluding xref's
  12.           )
  13.         )
  14.         2
  15.       )
  16.     )
  17.   )
  18. ))

That could work, but I would also like to allow everything except xrefs, RAY, XLINE, *TEXT to be selected.

ETA: I just tried and all I get is a spinning wheel with this one.

mhupp

  • Newt
  • Posts: 136
Re: SSGET Filter out XRefs along with other items
« Reply #7 on: May 03, 2022, 12:33:02 PM »
xref have a property "path" blocks don't so you can check all entity's in selection set. If they have a path property remove it from the selection set with the following.

Code - Auto/Visual Lisp: [Select]
  1. (setq ss (ssget ...
  2. (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
  3.   (if (vlax-property-available-p (vlax-ename->vla-object ent) "Path")
  4.     (ssdel ent SS)
  5.   )
  6. )

ronjonp

  • Needs a day job
  • Posts: 7404
Re: SSGET Filter out XRefs along with other items
« Reply #8 on: May 03, 2022, 01:19:58 PM »
Maybe this:
Code - Auto/Visual Lisp: [Select]
  1. (defun _foo (/ bd r)
  2.   (setq r "")
  3.   (while (setq bd (tblnext "BLOCK" (null bd)))
  4.     (if (and (not (assoc 1 bd)) (= 2 (logand 2 (cdr (assoc 70 bd)))))
  5.       (setq r (strcat (cdr (assoc 2 bd)) "," r))
  6.     )
  7.   )
  8.   r
  9. )
  10. (ssget "_:L"
  11.        (list '(-4 . "<OR")
  12.              '(-4 . "<AND")
  13.              '(0 . "INSERT")
  14.              (cons 1 (_foo))
  15.              '(-4 . "AND>")
  16.              '(-4 . "<NOT")
  17.              '(0 . "RAY,XLINE,*TEXT")
  18.              '(-4 . "NOT>")
  19.              '(-4 . "OR>")
  20.        )
  21. )

Windows 11 x64 - AutoCAD /C3D 2022

Custom Build PC

cmwade77

  • Swamp Rat
  • Posts: 1361
Re: SSGET Filter out XRefs along with other items
« Reply #9 on: May 03, 2022, 02:32:03 PM »
Thanks to all of your posts, I have figured out two different ways to accomplish what I am trying to do.

First off, I want to clarify, that I want to prevent the selection of the xRefs, it seems some of the examples were trying to include them.

So, here are my methods:
Method 1:
Removes xRefs from selection set after finishing the section set.
Code: [Select]
(defun CW:SSRemoveXrefs (SS / idx en obj)
  (vl-load-com)
  (setq idx -1)
  (repeat (sslength ss)
    (setq en  (ssname ss (setq idx (1+ idx)))
          obj (vlax-ename->vla-object en)
    )
    (if (vlax-property-available-p obj 'Path)
      (progn
        (vla-highlight obj :vlax-false)
        (ssdel en ss)
        (setq idx (1- idx))
      )
    )
  )
  SS
)


This has the downside that it still looks like you are selecting xRefs, as you technically are and they are just being removed from the selection set, so I went with a different method.

Method 2
Filters xRefs from the selection set based on name:
Code: [Select]
(defun CW:SSRemoveXrefs (SS / idx en obj)
  (vl-load-com)
  (setq idx -1)
  (repeat (sslength ss)
    (setq en  (ssname ss (setq idx (1+ idx)))
          obj (vlax-ename->vla-object en)
    )
    (if (vlax-property-available-p obj 'Path)
      (progn
        (vla-highlight obj :vlax-false)
        (ssdel en ss)
        (setq idx (1- idx))
      )
    )
  )
  SS
)

Code: [Select]
(defun C:FD (/ SS xRefs) 
  (setq xRefs (CW:XREFList)) 
  (if xRefs
    (setq Filter (list
                   '(-4 . "<AND")
                   '(-4 . "<NOT")
                   '(0 . "RAY,XLINE,*TEXT")
                   '(-4 . "NOT>")
                   '(-4 . "<NOT")
                    (cons 2 xRefs)
                    '(-4 . "NOT>")
                   '(-4 . "AND>")
                 )
    )
    (setq Filter (list
                   '(-4 . "<NOT")
                   '(0 . "RAY,XLINE,*TEXT")
                   '(-4 . "NOT>")
                 )
    )
  )
  (while (not SS)   
    (setq SS (ssget "_:L" Filter))
  )
)

I tried to use some if statements to only use one (setq Filter but it would fail frequently, so this way worked.