Selection filter for 2dPolyline

Selection filter for 2dPolyline

Browning_Zed
Advocate Advocate
1,869 Views
18 Replies
Message 1 of 19

Selection filter for 2dPolyline

Browning_Zed
Advocate
Advocate

Hi All,
When using the entsel / nentselp function, I need to check if the picked object is "LWPOLYLINE" or "2DPOLYLINE". To check the LWPolyLine, I use the following expression:

 

 

(= (cdr (assoc 0 (entget (car (entsel "\nPick: "))))) "LWPOLYLINE")

 

 

how to make a check for 2DPolyLine besides this (not 3DPolyline)?

0 Likes
Accepted solutions (2)
1,870 Views
18 Replies
Replies (18)
Message 2 of 19

pbejse
Mentor
Mentor

@Browning_Zed wrote:

Hi All,
When using the entsel / nentselp function, I need to check if the picked object is "LWPOLYLINE" or


In terms of using entsel/nentsel/nentselp its basically the same as you already have

its just good habit to evaluate the values first

 

(while
  (setq e   (car (entsel "\nPick: ")))
	  (princ (Strcat "\nSelected Object is "
		  (cond
		    ((eq (setq etype (cdr (assoc 0 (setq ent (entget e))))) "LWPOLYLINE")
			" 2DPolyLine" 	)
		    ((eq etype	"POLYLINE") "3DPolyLine"
				     	)
		    ( "Something else other than a Polyline")))
		 )
  )

 

 

HTH

 

Message 3 of 19

Browning_Zed
Advocate
Advocate

Please, tell me, how to use the condition in this code:

(while
    (progn
        (setvar 'errno 0)
        (setq sel (nentselp "\nSelect LWPoly or 2DPoly <Exit>: "))
        (cond
            (   (= 7 (getvar 'errno))
                (princ "\nMissed, try again.")
            )
            (   (= 'ename (type (car sel)))
                (if
                    (not
                        <<!!! OBJECT IS LWPOLY OR 2DPOLY !!!>>
                    )
                    (princ "\nInvalid object selected.")
                )
            )
        )
    )
)
0 Likes
Message 4 of 19

pbejse
Mentor
Mentor

@Browning_Zed wrote:

Please, tell me, how to use the condition in this code:


Remember the loop will continue to prompt the user to select except the time the user press enter.

(defun c:demo ()
(while
    (progn
        (setvar 'errno 0)
        (setq sel (nentselp "\nSelect LWPoly or 2DPoly <Exit>: "))
        (cond
            (   (= 7 (getvar 'errno))
                (princ "\nMissed, try again.")
            )
            (   (= 'ename (type (car sel)))
	     	(if (/= (cdr (assoc 0 (entget (car sel)))) "LWPOLYLINE")
		  	(princ "\nInvalid Object Selected.")
                        (princ "\n <<!!! OBJECT IS LWPOLY OR 2DPOLY !!!>> | Do something or press enter to exit the loop")
		  	
                    )
	        )
            )
        )
    )
(princ)
)

 

0 Likes
Message 5 of 19

Browning_Zed
Advocate
Advocate

You do not understand me. I also need to check 2D polylines besides LW polylines.
This place in the code is marked like this: << HERE MUST BE CHECKED 2DPOLYLINE IS TRUE >>

(while
    (progn
        (setvar 'errno 0)
        (setq sel (nentselp "\nSelect LWPoly or 2DPoly <Exit>: "))
        (cond
            (   (= 7 (getvar 'errno))
                (princ "\nMissed, try again.")
            )
            (   (= 'ename (type (car sel)))
                (if
                    (not
                        (or (= (cdr (assoc 0 (entget (car sel)))) "LWPOLYLINE") ; LWPOLY IS TRUE
							<< HERE MUST BE CHECKED 2DPOLYLINE IS TRUE >>
						)
                    )
                    (princ "\nInvalid object selected.")
                )
            )
        )
    )
)
0 Likes
Message 6 of 19

hak_vz
Advisor
Advisor
Accepted solution
(and
	(setq e (car (entsel "\nPick: ")))
	(setq eo (vlax-ename->vla-object e))
	(or
		(= (vlax-get eo 'Objectname)   "AcDbPolyline")
		(= (vlax-get eo 'Objectname)   "AcDb2dPolyline") 		
	)
)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 7 of 19

pbejse
Mentor
Mentor

@Browning_Zed wrote:

You do not understand me. I also need to check 2D polylines besides LW polylines.
This place in the code is marked like this: << HERE MUST BE CHECKED 2DPOLYLINE IS TRUE >>


Did you even try to understand the snippet i posted?

What is your idea of 2DPOLYLINE anyway? "LWPOLYLINE" is 2Dpolyline or "AcDbPolyline"

While POLYLINE is "AcDb3dPolyline" or "3D Polyline"

 

 

0 Likes
Message 8 of 19

Browning_Zed
Advocate
Advocate

When polylines are picked, your code returns results:

LW polyline: T
2D polyline: T
3D polyline: T

 

I need:
LW polyline: T
2D polyline: T
3D polyline: nil

 

Only LW polyline or 2D polyline should be selected.

0 Likes
Message 9 of 19

CADaSchtroumpf
Advisor
Advisor

By filtering?

(sssetfirst nil (ssget '((0 . "*POLYLINE") (-4 . "<NOT") (-4 . "&") (70 . 120) (-4 . "NOT>"))))

 

Message 10 of 19

Browning_Zed
Advocate
Advocate

LW polyline = "AcDbPolyline"
2D polyline = "AcDb2dPolyline"
3D polyline = "AcDb3dPolyline"

0 Likes
Message 11 of 19

pbejse
Mentor
Mentor

@Browning_Zed wrote:

When polylines are picked, your code returns results:

LW polyline: T
2D polyline: T
3D polyline: T

Only LW polyline or 2D polyline should be selected.


Maybe i'm missing something, can you post an example with those 3 diffrent types if polyline so we can be on the same page?

 

0 Likes
Message 12 of 19

hak_vz
Advisor
Advisor

@Browning_Zed wrote:

When polylines are picked, your code returns results:

LW polyline: T
2D polyline: T
3D polyline: T

 

I need:
LW polyline: T
2D polyline: T
3D polyline: nil

 

Only LW polyline or 2D polyline should be selected.


I' ve changed code above

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 13 of 19

pbejse
Mentor
Mentor

@hak_vz wrote:
....
		(= (vlax-get eo 'Objectname)   "AcDb2dPolyline") 		
...

What?!!!?? there is an actual "AcDb2dPolyline"? 😮 silly me.

All these years and I did not know that?  Maybe i have not came across one before 🤔

 

0 Likes
Message 14 of 19

hak_vz
Advisor
Advisor

@pbejseYes, in dxf definition for POLYLINE entity is stands

100  Subclass marker (AcDb2dPolyline or AcDb3dPolyline)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 15 of 19

Kent1Cooper
Consultant
Consultant

@pbejse wrote:
....What?!!!?? there is an actual "AcDb2dPolyline"? 😮 silly me.

All these years and I did not know that?  Maybe i have not came across one before 🤔


Read about the PLINETYPE System Variable.  In addition to that determining whether new [non-3D] Polylines are "lightweight" [which are called "optimized" there] or "heavy," any time you use the Fit or Spline option in the PEDIT command on a LWPolyline, the result is a "heavy" 2D Polyline.

 

The confusion is understandable.  The entity type in entity data for both "heavy" 2D and 3D Polylines is (0 . "POLYLINE"), compared to (0 . "LWPOLYLINE") for "LightWeight" ones.  But in the Properties palette, a selected "lightweight" one is listed as just a "Polyline."  The other types have the "2D" or "3D" prefixes there.

Kent Cooper, AIA
Message 16 of 19

pbejse
Mentor
Mentor
Accepted solution

FWIW

 

(defun c:demo ()
(while
    (progn
        (setvar 'errno 0)
        (setq sel (entsel "\nSelect LWPoly or 2DPoly : "))
        (cond
            (   (= 7 (getvar 'errno))
                (princ "\nMissed, try again.")
            )
            (   (= 'ename (type (car sel)))
	     	(if ( not (member (vlax-get (setq ev (vlax-ename->vla-object (car sel))) 'Objectname) '("AcDb2dPolyline" "AcDbPolyline" "AcDb2dVertex")))
		  	(princ "\nInvalid Object Selected.")
                        (princ "\n <<!!! OBJECT IS LWPOLY OR 2DPOLY !!!>> | Do something or press enter to exit the loop")
		  	
                    )
	        )
            )
        )
  )
(princ)
)

 

 

0 Likes
Message 17 of 19

Browning_Zed
Advocate
Advocate

Thanks to hak_vz for solving the problem. Thanks pbejse too 🙂

As it was already noted, the confusion arises because of the same dxf codes for 2D and 3D polylines (0. "POLYLINE"), despite the fact that they are different objects.

I have attached a file where there are all three types of polylines: LW, 2D and 3D, if someone else needs it.

Message 18 of 19

Sea-Haven
Mentor
Mentor

red (0 . "POLYLINE") (100 . "AcDb2dPolyline")
green (0 . "POLYLINE")(100 . "AcDb3dPolyline")
white (0 . "POLYLINE")(100 . "AcDbPolyline")

0 Likes
Message 19 of 19

hak_vz
Advisor
Advisor

@Sea-Haven wrote:

red (0 . "POLYLINE") (100 . "AcDb2dPolyline")
green (0 . "POLYLINE")(100 . "AcDb3dPolyline")
white (0 . "POLYLINE")(100 . "AcDbPolyline")


We have for polylines something like

(0 . "LWPOLYLINE")
(100 . "AcDbEntity") 
(100 . "AcDbPolyline") 

This double key 100 may causes that not all entities are selected. Also for lwpolyline key 0 is not POLYLINE

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes