Compare if an entity complies with a filter.

Compare if an entity complies with a filter.

carlos_m_gil_p
Advocate Advocate
1,030 Views
5 Replies
Message 1 of 6

Compare if an entity complies with a filter.

carlos_m_gil_p
Advocate
Advocate

Hello boys how are you.

 

You could tell me how I can compare a filter with a previously obtained entity.

 

For example:

 

I have an entity and a filter 3dpolyline, And I want you to return T if you comply with that.

 

(if (= entity '((0 . "POLYLINE") (-4 . "&") (70 . 8)))
(princ "Yes 3dpoly")
(princ "No 3dpoly")
)

I hope you can help me.
Thank you.
Excuse my English.

 

 


AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes
Accepted solutions (1)
1,031 Views
5 Replies
Replies (5)
Message 2 of 6

doaiena
Collaborator
Collaborator

This will do the job.

(if (and (equal (cdr (assoc 0 (entget entity))) "POLYLINE")
	 (equal (cdr (assoc 70 (entget entity))) 8)
) (princ "Yes 3dpoly") (princ "No 3dpoly") )
Message 3 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

@doaiena wrote:

....

....
	 (equal (cdr (assoc 70 (entget entity))) 8)
....

That will fail if the 3DPolyline is closed [which will add 1 to the (assoc 70) value] or Spline- or Fit-curved, and so on -- the 70-code entry contains information about far more than just whether a Polyline is 3D, and testing whether its value is specifically 8 will recognize only those that are open and not curve-edited.  It needs to test whether 8 is one of the binary bits that make up the 70-code value.

 

Try this [only the identification part -- alter as necessary to proceed to do something with the selected object depending on whether or not it's a 3DPolyline]:

 

(defun C:Is3DP (/ esel edata)
(if (setq esel (entsel "\nSelect object to find whether it's a 3DPolyline: ")) (progn ; then (setq edata (entget (car esel))) (prompt (strcat "\nThat object is " (if (and (member '(0 . "POLYLINE") edata) (= (logand (cdr (assoc 70 edata)) 8) 8) ); and "" ; then "not " ); if "a 3DPolyline." ); strcat ); prompt ); progn ); if
(princ)
); defun

 

OR, if you don't  need to do anything with the object other than to find out whether  it's a 3DPolyline [i.e. don't need to put the selection into a variable for any purpose], and  if you don't mind being stuck with the "Select objects:" prompt [always in the plural], it can be simplified down to this:

 

(defun C:Is3DP (/ ss)
  (if (ssget "_:S+." '((0 . "POLYLINE") (-4 . "&") (70 . 8)))
    (prompt "\nThat object is a 3DPolyline."); then
    (prompt "\nThat object is not a 3DPolyline."); else
  ); if
  (princ)
); defun

 

 

Kent Cooper, AIA
Message 4 of 6

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:
.... 

OR, if you don't  need to do anything with the object other than to find out whether  it's a 3DPolyline ....

.... 


Or even just:

(= (cdr (assoc 100 (reverse (entget (car (entsel "\nSelect possible 3DPolyline: ")))))) "AcDb3dPolyline")

 

returns T if it's a 3DPolyline, nil if it isn't.

Kent Cooper, AIA
0 Likes
Message 5 of 6

_gile
Consultant
Consultant
(member '(100 . "AcDb3dPolyline") (entget (car (entsel))))

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 6 of 6

carlos_m_gil_p
Advocate
Advocate
Hi guys, thank you all. I'm going to stay with Kent1Cooper, because I'll always need specific filters. Thank you.

AutoCAD 2026
Visual Studio Code 1.99.3
AutoCAD AutoLISP Extension 1.6.3
Windows 10 (64 bits)

0 Likes