Jump to content

Recommended Posts

Posted

How to identify the selected polyline is closed or not by LISP

Posted

Here is one way to only select closed polylines

 

(ssget '((0 . "POLYLINE,LWPOLYLINE")(-4 . "&")(70 . 1)))

Posted

Lisp to select a lwpolyline and see if it's closed:

(vlax-curve-isClosed (car(entsel)))

You could also use the function to test preselected entities as well.

Posted

Thanks everybody for your codes and quick replies.

Posted
Here is one way to only select closed polylines

 

(ssget '((0 . "POLYLINE,LWPOLYLINE")(-4 . "&")(70 . 1)))

FWIW, you also need to check for:

(ssget '((0 . "lwpolyline") (-4 . "<OR") (70 . 1) [b](70 . 129)[/b] (-4 . "OR>")))

When PLINEGEN is set to 1.

  • Like 1
Posted

@ronjonp - did you try it?

 

The [&] is a Bitwise AND operator. To determine if the polyline is closed, you are looking for the presence of the "1" bit in the dxf70 code, not just the two values "1" and "129".

 

So the code I posted works on both heavy and lightweight polylines, regardless of the setting of PLINEGEN, whether or not it is a 3D polyline, spline fit, curve fit, etc.

 

Your code will only select lightweight closed polylines. It ignores closed heavy polylines, closed 3D polylines, closed spline fit/curve fit polylines, etc.

Posted
@ronjonp - did you try it?

 

The [&] is a Bitwise AND operator. To determine if the polyline is closed, you are looking for the presence of the "1" bit in the dxf70 code, not just the two values "1" and "129".

 

So the code I posted works on both heavy and lightweight polylines, regardless of the setting of PLINEGEN, whether or not it is a 3D polyline, spline fit, curve fit, etc.

 

Your code will only select lightweight closed polylines. It ignores closed heavy polylines, closed 3D polylines, closed spline fit/curve fit polylines, etc.

 

Thanks for the reply I did not know that! :)

Posted

For what it's worth, when matching a single bit-code (such as 1=Closed), I would be inclined to use the bitwise masked equals operator ("&=") which behaves the same as (= (logand )); though this is just syntactic sugar, as both bitwise operators will perform equally well in this case.

 

This post may help to explain the difference between the two bitwise operators ("&" and "&="), I also provide some examples in my reference here.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...