Author Topic: Searching Entities With Multiple Point Criteria  (Read 2909 times)

0 Members and 1 Guest are viewing this topic.

David Bethel

  • Swamp Rat
  • Posts: 656
Searching Entities With Multiple Point Criteria
« on: January 24, 2017, 07:33:12 AM »
Good morning,

I have a needs from time to time in vanilla AutoLisp to find 3DFACE entities that match a given criteria. 

In this case select all faces that:
  • Have 2 points with Z axis = 36
  • Have 2 points with Z axis > 36

I came up with   7  ( 6) possible point order scenarios.  But there has to be a better way:


Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ ss i en ed)
  2.   (and (setq ss (ssget "X" (list (cons 0 "3DFACE")
  3.                                  (cons 8 "3D,3D-CHROME")
  4.                                  (cons -4 "<OR")
  5.                                    (cons -4 "<AND")
  6.                                      (cons -4 "*,*,=")(list 10 0 0 36)
  7.                                      (cons -4 "*,*,=")(list 11 0 0 36)
  8.                                      (cons -4 "*,*,>")(list 12 0 0 36)
  9.                                      (cons -4 "*,*,>")(list 13 0 0 36)
  10.                                    (cons -4 "AND>")
  11.                                    (cons -4 "<AND")
  12.                                      (cons -4 "*,*,=")(list 10 0 0 36)
  13.                                      (cons -4 "*,*,>")(list 11 0 0 36)
  14.                                      (cons -4 "*,*,=")(list 12 0 0 36)
  15.                                      (cons -4 "*,*,>")(list 13 0 0 36)
  16.                                    (cons -4 "AND>")
  17.                                    (cons -4 "<AND")
  18.                                      (cons -4 "*,*,=")(list 10 0 0 36)
  19.                                      (cons -4 "*,*,>")(list 11 0 0 36)
  20.                                      (cons -4 "*,*,>")(list 12 0 0 36)
  21.                                      (cons -4 "*,*,=")(list 13 0 0 36)
  22.                                    (cons -4 "AND>")
  23.                                    (cons -4 "<AND")
  24.                                      (cons -4 "*,*,>")(list 10 0 0 36)
  25.                                      (cons -4 "*,*,=")(list 11 0 0 36)
  26.                                      (cons -4 "*,*,=")(list 12 0 0 36)
  27.                                      (cons -4 "*,*,>")(list 13 0 0 36)
  28.                                    (cons -4 "AND>")
  29.                                    (cons -4 "<AND")
  30.                                      (cons -4 "*,*,>")(list 10 0 0 36)
  31.                                      (cons -4 "*,*,=")(list 11 0 0 36)
  32.                                      (cons -4 "*,*,>")(list 12 0 0 36)
  33.                                      (cons -4 "*,*,=")(list 13 0 0 36)
  34.                                    (cons -4 "AND>")
  35.                                    (cons -4 "<AND")
  36.                                      (cons -4 "*,*,>")(list 10 0 0 36)
  37.                                      (cons -4 "*,*,>")(list 11 0 0 36)
  38.                                      (cons -4 "*,*,=")(list 12 0 0 36)
  39.                                      (cons -4 "*,*,=")(list 13 0 0 36)
  40.                                    (cons -4 "AND>")
  41.                                  (cons -4 "OR>"))))
  42.         (setq i 0)
  43.         (while (setq en (ssname ss i))
  44.                (setq ed (entget en))
  45.                (entmod (subst (cons 8 "3D-NON") (assoc 8 ed) ed))
  46.                (setq i (1+ i))))
  47.   (prin1))

The need is for all flat vertical surfaces starting at 36" AFF have to be on a non reflective layer.

This could also be used with 2D WCS SOLIDs and TRACEs

Any ideas ?  Thanks!  -David
« Last Edit: January 26, 2017, 06:22:51 AM by David Bethel »
R12 Dos - A2K

ribarm

  • Gator
  • Posts: 3251
  • Marko Ribar, architect
Re: Searching Entities With Multiple Point Criteria
« Reply #1 on: January 24, 2017, 07:47:36 AM »
Actually you have 6 cases...
In your code lines 5-10 and 23-28 are the same... You can freely remove either case of those two...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Searching Entities With Multiple Point Criteria
« Reply #2 on: January 24, 2017, 08:00:41 AM »
I suppose the filter could be condensed slightly to:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo ( / enx idx sel )
  2.     (if
  3.         (setq sel
  4.             (ssget "_X"
  5.                '(
  6.                     (0 . "3DFACE")
  7.                     (8 . "3D,3D-CHROME")
  8.                     (-4 . "*,*,>=") (10 0 0 36)
  9.                     (-4 . "*,*,>=") (11 0 0 36)
  10.                     (-4 . "*,*,>=") (12 0 0 36)
  11.                     (-4 . "*,*,>=") (13 0 0 36)
  12.                     (-4 . "<OR")
  13.                         (-4 . "<AND")
  14.                             (-4 . "*,*,=") (10 0 0 36)
  15.                             (-4 . "*,*,=") (11 0 0 36)
  16.                         (-4 . "AND>")
  17.                         (-4 . "<AND")
  18.                             (-4 . "*,*,=") (10 0 0 36)
  19.                             (-4 . "*,*,=") (12 0 0 36)
  20.                         (-4 . "AND>")
  21.                         (-4 . "<AND")
  22.                             (-4 . "*,*,=") (10 0 0 36)
  23.                             (-4 . "*,*,=") (13 0 0 36)
  24.                         (-4 . "AND>")
  25.                         (-4 . "<AND")
  26.                             (-4 . "*,*,=") (11 0 0 36)
  27.                             (-4 . "*,*,=") (12 0 0 36)
  28.                         (-4 . "AND>")
  29.                         (-4 . "<AND")
  30.                             (-4 . "*,*,=") (11 0 0 36)
  31.                             (-4 . "*,*,=") (13 0 0 36)
  32.                         (-4 . "AND>")
  33.                         (-4 . "<AND")
  34.                             (-4 . "*,*,=") (12 0 0 36)
  35.                             (-4 . "*,*,=") (13 0 0 36)
  36.                         (-4 . "AND>")
  37.                     (-4 . "OR>")
  38.                 )
  39.             )
  40.         )
  41.         (repeat (setq idx (sslength sel))
  42.             (setq enx (entget (ssname sel (setq idx (1- idx)))))
  43.             (entmod (subst '(8 . "3D-NON") (assoc 8 enx) enx))
  44.         )
  45.     )
  46.     (princ)
  47. )

EDIT: Though, this does allow three or all four vertices to have Z=36.

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Searching Entities With Multiple Point Criteria
« Reply #3 on: January 24, 2017, 08:21:31 AM »
Actually you have 6 cases...
In your code lines 5-10 and 23-28 are the same... You can freely remove either case of those two...

OOPS !  Copy And Pasted Too many times !

Thanks !
R12 Dos - A2K

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Searching Entities With Multiple Point Criteria
« Reply #4 on: January 24, 2017, 08:26:37 AM »
EDIT: Though, this does allow three or all four vertices to have Z=36.

Thanks Lee,

Yes, that would be a problem.  If all vertices are at the same elevation, then I have another layer that they must reside on.  Render lighting and reflections work very differently on a true WSC plane surfaces
R12 Dos - A2K

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Searching Entities With Multiple Point Criteria
« Reply #5 on: January 24, 2017, 09:29:03 AM »
Coded blind without benefit of AutoCAD or coffee ...

Code: [Select]
(ssget "_X"
   '(
        (0 . "3DFACE")
        (8 . "3D,3D-CHROME")
        (-4 . "*,*,>=") (10 0 0 36)
        (-4 . "*,*,>=") (11 0 0 36)
        (-4 . "*,*,>=") (12 0 0 36)
        (-4 . "*,*,>=") (13 0 0 36)
        (-4 . "<OR")
            (-4 . "<AND")
                (-4 . "*,*,=") (10 0 0 36)
                (-4 . "<OR")
                    (-4 . "*,*,=") (11 0 0 36)
                    (-4 . "*,*,=") (12 0 0 36)
                    (-4 . "*,*,=") (13 0 0 36)
                (-4 . "OR>")
            (-4 . "AND>")
            (-4 . "<AND")
                (-4 . "*,*,=") (11 0 0 36)
                (-4 . "<OR")
                    (-4 . "*,*,=") (12 0 0 36)
                    (-4 . "*,*,=") (13 0 0 36)
                (-4 . "OR>")
            (-4 . "AND>")
            (-4 . "<AND")
                (-4 . "*,*,=") (12 0 0 36)
                (-4 . "*,*,=") (13 0 0 36)
            (-4 . "AND>")
        (-4 . "OR>")
    )
)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Searching Entities With Multiple Point Criteria
« Reply #6 on: January 25, 2017, 06:20:43 AM »
You guys git me thinking about the "*,*,>=:

Maybe its easier to just step thru that set:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo2 (/ z ss i en ed zl)
  2.   (setq z 36)
  3.  
  4.   (and (setq ss (ssget "X" (list (cons 0 "3DFACE")
  5.                                  (cons 8 "3D,3D-CHROME")
  6.                                  (cons -4 "*,*,>=")(list 10 0 0 z)
  7.                                  (cons -4 "*,*,>=")(list 11 0 0 z)
  8.                                  (cons -4 "*,*,>=")(list 12 0 0 z)
  9.                                  (cons -4 "*,*,>=")(list 13 0 0 z))))
  10.         (setq i 0)
  11.         (while (setq en (ssname ss i))
  12.                (setq ed (entget en)
  13.                      zl nil)
  14.                (foreach g '(10 11 12 13)
  15.                  (if (= z (nth 3 (assoc g ed)))
  16.                      (setq zl (cons 1 zl))))
  17.                (if (< 0 (length zl) 3)
  18.                    (entmod (subst (cons 8 "3D-NON") (assoc 8 ed) ed)))
  19.                (setq i (1+ i))))
  20.    (prin1))
  21.  

This way I on do any number of tests / modification tests  etc.

Thanks to all !  -David
R12 Dos - A2K

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Searching Entities With Multiple Point Criteria
« Reply #7 on: January 25, 2017, 06:14:50 PM »
Given that these are 3D Face objects, I wonder if this could be done by checking the normal vector of the face to filter out those which are/aren't pointing in the right direction.
If you are going to fly by the seat of your pants, expect friction burns.

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

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Searching Entities With Multiple Point Criteria
« Reply #8 on: January 25, 2017, 07:21:06 PM »
3DFaces have no normal.

I know: "that's not normal".
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Searching Entities With Multiple Point Criteria
« Reply #9 on: January 26, 2017, 12:23:47 PM »
3DFaces have no normal.

I know: "that's not normal".

It is odd that a 3D Face can be constructed from 4 points meaning it can define two planar surfaces as opposed to one...

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Searching Entities With Multiple Point Criteria
« Reply #10 on: January 26, 2017, 05:12:11 PM »
Quads vs. tris.  The endless debate continues.   :tickedoff:
If you are going to fly by the seat of your pants, expect friction burns.

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

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Searching Entities With Multiple Point Criteria
« Reply #11 on: January 27, 2017, 03:24:52 AM »
... vs. ngons.

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Searching Entities With Multiple Point Criteria
« Reply #12 on: January 27, 2017, 07:59:03 AM »
3DFaces have no normal.

I know: "that's not normal".

It is odd that a 3D Face can be constructed from 4 points meaning it can define two planar surfaces as opposed to one...

What I've always I found really odd is that is no way to determine which 3 points define either plane.  (10 11 12)  or (10 11 13)  So you cannot figure out where the bend edge is.

I believe 3DMax only uses 3 points.  ( at least in the autocad conversion using 3dsin )  Points 10 and 13 are equal .  If I remember correctly

-David
R12 Dos - A2K