Author Topic: Difference between '(-4 . "&") and '(-4 . "&=")  (Read 4706 times)

0 Members and 2 Guests are viewing this topic.

ribarm

  • Gator
  • Posts: 3257
  • Marko Ribar, architect
Difference between '(-4 . "&") and '(-4 . "&=")
« on: February 18, 2017, 05:49:18 AM »
If you know this answer, please provide some info... To me it's the same, but then I am not completely sure...
If you have some simple explanation through examples, please provide them...

Thanks, M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Difference between '(-4 . "&") and '(-4 . "&=")
« Reply #1 on: February 18, 2017, 07:11:05 AM »
I found this

All relational operators except for the bitwise operators ("&" and "&=") are valid for both real- and integer-valued groups.
The bitwise operators "&" and "&=" are valid only for integer-valued groups. The bitwise AND, "&", is true if ((integer_group & filter) /= 0)—that is, if any of the bits set in the mask are also set in the integer group. The bitwise masked equals, "&=", is true if ((integer_group & filter) = filter)—that is, if all bits set in the mask are also set in the integer_group (other bits might be set in the integer_group but are not checked).




Hope it makes more sense to you than it does to me.  -David
R12 Dos - A2K

ribarm

  • Gator
  • Posts: 3257
  • Marko Ribar, architect
Re: Difference between '(-4 . "&") and '(-4 . "&=")
« Reply #2 on: February 18, 2017, 08:26:48 AM »
Thanks David, I'll let that someone chime in if he/she wants to shed some more light perhaps showing 2 examples with each usage...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Difference between '(-4 . "&") and '(-4 . "&=")
« Reply #3 on: February 18, 2017, 08:31:04 AM »
Lee included some description in his ssget reference:
http://www.lee-mac.com/ssget.html#relational
He wrote that
(-4 . "&") is Equivalent to: (/= 0 (logand bit filter))
and that
(-4 . "&=") is Equivalent to: (= filter (logand bit filter))
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Difference between '(-4 . "&") and '(-4 . "&=")
« Reply #4 on: February 18, 2017, 08:38:18 AM »
I tied this on a 3DFACE with group 70 set to 5

Code: [Select]
 
  (if (ssget "X" (list (cons -4 "&")
                          (cons 70 1)))
      (alert "& 1 T"))
  (if (ssget "X" (list (cons -4 "&")
                          (cons 70 4)))
      (alert "& 4 T"))

  (if (ssget "X" (list (cons -4 "&")
                          (cons 70 5)))
      (alert "& 5 T"))

  (if (ssget "X" (list (cons -4 "&=")
                          (cons 70 1)))
      (alert "&= 1 T"))
  (if (ssget "X" (list (cons -4 "&=")
                          (cons 70 4)))
      (alert "&= 4 T"))

  (if (ssget "X" (list (cons -4 "&=")
                          (cons 70 5)))
      (alert "&= 5 T"))

All came up T.  So it blew my therory out of the water.

-David

R12 Dos - A2K

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Difference between '(-4 . "&") and '(-4 . "&=")
« Reply #5 on: February 18, 2017, 08:41:24 AM »
Hi,

I'll try an example with the Polyline flag (70 dxf group code):
1 = Closed
128 = Plinegen

Code - Auto/Visual Lisp: [Select]
  1. '((0 . "LWPOLYLINE") (-4 . "&=") (70 . 129))
Select only closed polylines which plingen is on. IOW (70 . 129)

Code - Auto/Visual Lisp: [Select]
  1. '((0 . "LWPOLYLINE") (-4 . "&") (70 . 129))
Select both closed polylines and  polylines which plingen is on. IOW (70 . 1) or (70 . 128) or (70 . 129)

Used with a single bit, both operators are equivalent.

Speaking English as a French Frog

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Difference between '(-4 . "&") and '(-4 . "&=")
« Reply #6 on: February 18, 2017, 08:59:53 AM »
The previous example illustrates Lee's explanation.
(-4 . "&=") (70 . 129) stands for (= 129 (logand 129 (cdr (assoc 70 dxfLst))))
(-4 . "&") (70 . 129) stands for (< 0 (logand 129 (cdr (assoc 70 dxfLst))))


Speaking English as a French Frog

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Difference between '(-4 . "&") and '(-4 . "&=")
« Reply #7 on: February 18, 2017, 09:16:41 AM »
hhhmmmm  I didn't work that way in the scenario I was using. ? All of the tests returned T   -David
R12 Dos - A2K

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Difference between '(-4 . "&") and '(-4 . "&=")
« Reply #8 on: February 18, 2017, 09:39:17 AM »
Your test protocol does not make it possible to reveal the difference between the two operators.

You should have several faces with different DXF 70 values, e.g. (70 . 1), (70 . 4) and (70 . 5) and try both:
Code - Auto/Visual Lisp: [Select]
  1. (sssetfirst nil (ssget "_X" '((-4 . "&") (70 . 5))))
and
Code - Auto/Visual Lisp: [Select]
  1. (sssetfirst nil (ssget "_X" '((-4 . "&=") (70 . 5))))
Speaking English as a French Frog

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Difference between '(-4 . "&") and '(-4 . "&=")
« Reply #9 on: February 19, 2017, 06:08:35 AM »
You should have several faces with different DXF 70 values, e.g. (70 . 1), (70 . 4) and (70 . 5) and try both:

OK!   I tried it and saw the differences.  I must admit that I've never personally remembered an exact need for the &=

Thanks!  -David
R12 Dos - A2K

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Difference between '(-4 . "&") and '(-4 . "&=")
« Reply #10 on: February 19, 2017, 06:58:20 AM »
As said upper "&=" is only usefull with more than one flag.

For example, if you want to select all closed 3D polyline.

DXF reference for POLYLINE type:
1 = This is a closed polyline (or a polygon mesh closed in the M direction).
2 = Curve-fit vertices have been added.
4 = Spline-fit vertices have been added.
8 = This is a 3D polyline.
16 = This is a 3D polygon mesh.
32 = The polygon mesh is closed in the N direction.
64 = The polyline is a polyface mesh.
128 = The linetype pattern is generated continuously around the vertices of this polyline.


So you have to use flags = 9 ( 1 + 8 ).

With: '((0 . "POLYLINE") (-4 . "&") (70 . 9)) you'll select:
- all closed polylines (2D or 3D) and and polygon meshes closed in the M direction ( flag 1 )
- all 3D polylines even opened or closed ( flag 8 )

With:  '((0 . "POLYLINE") (-4 . "&=") (70 . 9)) you'll only select all closed 3D polylines ( flag 1 + 8 ).
« Last Edit: February 19, 2017, 07:37:59 AM by gile »
Speaking English as a French Frog

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Difference between '(-4 . "&") and '(-4 . "&=")
« Reply #11 on: February 19, 2017, 07:18:20 AM »
Perhaps the following graphic will also help to explain the difference:



EDIT: Wow - gile posted almost an identical example as I was drawing the above!

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Difference between '(-4 . "&") and '(-4 . "&=")
« Reply #12 on: February 19, 2017, 07:42:03 AM »
Interesting. 
Of the 25 or so lisp routines that I have using -4 "&", I found almost all were dealing with POLYLINEs.  Quite a few also had a
Code: [Select]
;to filter out meshes
(-4 . "<")
  (70 . 16)

;or

;to filter out any 3d entities
(-4 . "<")
  (70 . 8)


I'll keep this in mind ( if I can remember the exact details.

Thanks  -David
R12 Dos - A2K

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: Difference between '(-4 . "&") and '(-4 . "&=")
« Reply #13 on: February 20, 2017, 08:10:10 AM »
I do not know if this can be interesting but there are three cases for which a polyline can be closed:
Code: [Select]
; ALE_Pline_LwClosedP - Version: 1.01
;
; Return Values:
;   nil if LwPolyline is Open                         
;   1   if is Closed - (or logand 1 flag 70 is True) 
;   2   if is Open   BUT startpoint is equal endpoint   
;   3   if is Closed AND startpoint is equal endpoint   
;
; Example:
;  (ALE_Pline_LwClosedP (vlax-ename->vla-object (car (entsel "Poly: "))) 0.001)
;
(defun ALE_Pline_LwClosedP (LwPObj FuzFac)
  (cond
    ( (eq :vlax-true (vla-get-closed LwPObj))
      (if
        (equal
          (vlax-curve-getEndPoint LwPObj)
          (vlax-curve-getPointAtParam LwPObj (1- (vlax-curve-getEndParam LwPObj)))
        )
        3 1
      )
    )
    ( (equal (vlax-curve-getStartPoint LwPObj) (vlax-curve-getEndPoint LwPObj) FuzFac) 2 )
  )
)

ribarm

  • Gator
  • Posts: 3257
  • Marko Ribar, architect
Re: Difference between '(-4 . "&") and '(-4 . "&=")
« Reply #14 on: February 21, 2017, 12:25:21 AM »
To connect to Marc's observation, maybe firstly (c:fixclosed) and then filter for :

closed polylines with :
Code - Auto/Visual Lisp: [Select]
  1. (setq ss (ssget "_:L" '((0 . "*POLYLINE") (-4 . "&=") (70 . 1))))
  2.  

open polylines with :
Code - Auto/Visual Lisp: [Select]
  1. (setq ss (ssget "_:L" '((0 . "*POLYLINE") (-4 . "<not") (-4 . "&=") (70 . 1) (-4 . "not>"))))
  2.  

Code: [Select]
; ALE_Pline_ClosedP - Version: 1.01 - mod by M.R. (Vanilla Check for all Polyline types)
;
; Return Values:
;   nil if Polyline is Open                         
;   1   if is Closed
;   2   if is Open   BUT startpoint is equal endpoint   
;   3   if is Closed AND startpoint is equal endpoint   
;
; Example:
;  (ALE_Pline_ClosedP (car (entsel "Poly: ")) 0.001)
;
(defun ALE_Pline_ClosedP ( pl fuzz / conddata stvtx envtx )

  (defun conddata ( pl / v vv )
    (cond
      ( (= (cdr (assoc 0 (entget pl))) "LWPOLYLINE")
        (setq stvtx (cdr (assoc 10 (entget pl))))
        (setq envtx (cdr (assoc 10 (reverse (entget pl)))))
      )
      ( t
        (setq stvtx (cdr (assoc 10 (entget (setq v (entnext pl))))))
        (while (= (cdr (assoc 0 (entget v))) "VERTEX")
          (setq vv v v (entnext v))
        )
        (setq envtx (cdr (assoc 10 (entget vv))))
      )
    )
  )

  (cond
    ( (= 1 (logand 1 (cdr (assoc 70 (entget pl)))))
      (conddata pl)
      (if
        (equal stvtx envtx fuzz)
        3 1
      )
    )
    ( t
      (conddata pl)
      (if (equal stvtx envtx fuzz) 2)
    )
  )
)

(defun c:fixclosedpolylines ( / conddata ss i pl case stvtx envtx stpar b p f )

  (defun conddata ( pl / v vv vvv )
    (cond
      ( (= (cdr (assoc 0 (entget pl))) "LWPOLYLINE")
        (setq stvtx (cdr (assoc 10 (cdr (member (assoc 10 (reverse (entget pl))) (reverse (entget pl)))))))
        (setq envtx (cdr (assoc 10 (reverse (entget pl)))))
      )
      ( t
        (setq v (entnext pl))
        (while (= (cdr (assoc 0 (entget v))) "VERTEX")
          (setq vv v v (entnext v))
        )
        (setq envtx (cdr (assoc 10 (entget vv))))
        (setq v (entnext pl))
        (while (not (eq vv v))
          (setq vvv v v (entnext v))
        )
        (setq stvtx (cdr (assoc 10 (entget vvv))))
      )
    )
  )

  (if (cadr (sssetfirst nil (ssget "_X" '((0 . "*POLYLINE") (-4 . "<or") (70 . 0) (70 . 1) (70 . 8) (70 . 9) (70 . 128) (70 . 129) (-4 . "or>")))))
    (setq ss (ssget "_:L"))
  )
  (repeat (setq i (sslength ss))
    (setq pl (ssname ss (setq i (1- i))))
    (if (> (setq case (ALE_Pline_ClosedP pl 1e-6)) 1)
      (progn
        (conddata pl)
        (cond
          ( (= (cdr (assoc 100 (reverse (entget pl)))) "AcDbPolyline")
            (if (= case 3)
              (vla-put-closed (vlax-ename->vla-object pl) :vlax-false)
            )
            (setq stvtx (trans (list (car stvtx) (cadr stvtx) (cdr (assoc 38 (entget pl)))) pl 0))
            (setq envtx (trans (list (car envtx) (cadr envtx) (cdr (assoc 38 (entget pl)))) pl 0))
            (setq stpar (vlax-curve-getparamatpoint pl (vlax-curve-getclosestpointto pl stvtx)))
            (setq b (vla-getbulge (vlax-ename->vla-object pl) stpar))
            (setq p (trans (vlax-curve-getpointatparam pl (+ stpar 0.95)) 0 1))
          )
          ( (= (cdr (assoc 100 (reverse (entget pl)))) "AcDb2dPolyline")
            (setq f t)
            (command "_.CONVERTPOLY" "_L" pl "")
            (if (= case 3)
              (vla-put-closed (vlax-ename->vla-object pl) :vlax-false)
            )
            (setq stvtx (trans stvtx pl 0))
            (setq envtx (trans envtx pl 0))
            (setq stpar (vlax-curve-getparamatpoint pl (vlax-curve-getclosestpointto pl stvtx)))
            (setq b (vla-getbulge (vlax-ename->vla-object pl) stpar))
            (setq p (trans (vlax-curve-getpointatparam pl (+ stpar 0.95)) 0 1))
          )
          ( (= (cdr (assoc 100 (reverse (entget pl)))) "AcDb3dPolyline")
            (if (= case 3)
              (vla-put-closed (vlax-ename->vla-object pl) :vlax-false)
            )
            (setq stpar (vlax-curve-getparamatpoint pl (vlax-curve-getclosestpointto pl stvtx)))
            (setq p (trans (vlax-curve-getpointatparam pl (+ stpar 0.95)) 0 1))
          )
        )
        (while (not (and (equal stvtx (vlax-curve-getendpoint pl) 1e-6) (equal envtx (vlax-curve-getstartpoint pl) 1e-6)))
          (command "_.TRIM" pl "" "_non" p "")
          (if (vlax-erased-p pl)
            (setq pl (entlast))
          )
          (if (zerop (vlax-curve-getparamatpoint pl (vlax-curve-getendpoint pl)))
            (progn
              (entdel pl)
              (setq pl (entlast))
            )
            (setq p (trans (vlax-curve-getpointatparam pl (- (vlax-curve-getparamatpoint pl (vlax-curve-getendpoint pl)) 0.05)) 0 1))
          )
        )
        (entupd (cdr (assoc -1 (entmod (subst (cons 70 (1+ (cdr (assoc 70 (entget pl))))) (assoc 70 (entget pl)) (entget pl))))))
        (if b
          (progn
            (vla-setbulge (vlax-ename->vla-object pl) stpar b)
            (setq b nil)
          )
        )
        (if f
          (progn
            (command "_.CONVERTPOLY" "_H" pl "")
            (setq f nil)
          )
        )
      )
    )
  )
  (princ)
)

[EDIT : Code changed as it had lacks...]
« Last Edit: February 21, 2017, 06:33:09 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube