Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Select a polygon

11 REPLIES 11
Reply
Message 1 of 12
richer
480 Views, 11 Replies

Select a polygon

Hello,
I have a point inside a polygon.I want By this inside point i select the polygon.Without do anything.Please help
11 REPLIES 11
Message 2 of 12
Anonymous
in reply to: richer

richer,

I don't know the solution, but it will be interesting to hear what others
have to offer.

Joe Burke
Message 3 of 12
Anonymous
in reply to: richer

If were talking R15+, you can use an invisible ray and the IntersectWith method.

(defun ssgetpolys (P Layers / ray SS i ename poly coords)
;; Make an invisible ray:
(setq Ray
(entmakex
(list
'(0 . "RAY")'(100 . "AcDbEntity")'(100 . "AcDbRay")
'(8 . "0")'(60 . 1)(cons 10 P)'(11 1.0 1.0 0.0)
(cons 410 (getvar "ctab"))
)
)
Ray (vlax-ename->vla-object Ray)
)
;; Create selection set of polylines called SS:
(and
(or (= (type Layers) 'STR)(setq Layers "*"))
(setq SS
(ssget "X"
(list
'(0 . "*POLYLINE")
(cons 8 Layers)
'(-4 . "&")'(70 . 1) ;; Only closed ones
(cons 410 (getvar "ctab"))
)
)
)
(setq i 0)
(while (< i (sslength SS))
(setq Ename (ssname SS i)
Poly (vlax-ename->vla-object Ename)
Coords (vlax-invoke Ray "IntersectWith" Poly acExtendNone)
)
;; if the ray intersects an odd number of times, it's inside
(if (= (rem (/ (length Coords) 3) 2) 1)
(setq i (1+ i))
(ssdel Ename SS)
)
)
)
(vla-delete Ray)
SS ;; return the selection set
)

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ

"richer" wrote in message
news:f0ff1b5.-1@WebX.maYIadrTaRb...
> Hello,
> I have a point inside a polygon.I want By this inside point i select the
polygon.Without do anything.Please help
Message 4 of 12
Anonymous
in reply to: richer

On 7/29 I posted a thread with the subject Draw box around a closed lwpline.
The solution ended up using a bounding box to get the lower left point and upper right
point.

You can use a boundingbox around all plines to get the min and max points of the pline and
check to see if the inside point falls between the min & max of the bounding box, if so
then select the pline inside of the boundingbox.

--
Ken Alexander
Acad 2000
Win 2000
"richer" wrote in message news:f0ff1b5.-1@WebX.maYIadrTaRb...
> Hello,
> I have a point inside a polygon.I want By this inside point i select the polygon.Without
do anything.Please help
>
Message 5 of 12
Anonymous
in reply to: richer

Ken

your solution will not be accurate for
C-shaped or U-shaped closed polygons,
Joh's solution is excellent, except that
it might fail if the ray passes thru a vertex
or more.

mark


"Ken Alexander" wrote in message
news:488208AE36D5A56CEF2963002C4673BA@in.WebX.maYIadrTaRb...
> On 7/29 I posted a thread with the subject Draw box around a closed
lwpline.
> The solution ended up using a bounding box to get the lower left point and
upper right
> point.
>
> You can use a boundingbox around all plines to get the min and max points
of the pline and
> check to see if the inside point falls between the min & max of the
bounding box, if so
> then select the pline inside of the boundingbox.
>
> --
> Ken Alexander
> Acad 2000
> Win 2000
> "richer" wrote in message
news:f0ff1b5.-1@WebX.maYIadrTaRb...
> > Hello,
> > I have a point inside a polygon.I want By this inside point i select the
polygon.Without
> do anything.Please help
> >
>
Message 6 of 12
Anonymous
in reply to: richer

Nice... Thanks, John. 🙂

Joe Burke
Message 7 of 12
Anonymous
in reply to: richer

(defun getpoly ( / ss ptlist)
 (setq pt
(getpoint "\nSelect point inside polygon"))
 (command ".boundary" pt
"")
 (setq ptlist nil)
 (foreach x (entget (entlast))
 
(if (eq 10 (car x))
   (setq ptlist (cons (cdr x)
ptlist))
  )
 )
 (setq ptlist (reverse
ptlist))
 (entdel (entlast))
 (setq ss (ssget "cp" ptlist '((0 .
"POLYLINE,LWPOLYLINE"))))
 (print)
 (if ss (ssname ss
0))
)

 

Returns the entity name of the first polyline
found

 


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Hello,

I have a point inside a polygon.I want By this inside point i select the
polygon.Without do anything.Please help
Message 8 of 12
Anonymous
in reply to: richer

Hi jim,
Your programme is not working properly.the first polygon is not selected in this programme.please help.
Message 9 of 12
Anonymous
in reply to: richer

Jim,

I posted something recently in a thread called "selection like hatch"
7/18/02 which attempted to create a selection set using a boundary point
list as your getpoly function does. I found it highly unreliable. (ssget
"cp" ptlist) would often fail for no apparent reason.

Turns out sometimes boundary creates a pline with duplicate points. ssget
methods like "cp" "wp" and "f" will fail if there are duplicate points. So
you have to weed out duplicates if they exist. I wrote the following to do
that. If anyone has something similar/better, I'd love to see it. I'm pretty
new at this kind of stuff.

;remove duplicate points from point list
;arguments: OLST - pointlist, FUZ - fuzz distance
;returns new list with duplicates removed
(defun RemDupPts (OLST FUZ / NLST P1 P2)
(while (> (length OLST) 1)
(setq P1 (car OLST) P2 (cadr OLST))
(if (> (distance P1 P2) FUZ)
(setq NLST (cons P1 NLST))) ;if
(setq OLST (cdr OLST))
) ;while
(setq NLST (cons (last OLST) NLST)) ;seems safe?
(reverse NLST)
) ;end

Sample point list temp1:
((10103.1 1033.39 0.0) (9981.65 1035.87 0.0) (9944.66 1036.62 0.0) (9932.16
1036.87 0.0) (9931.53 1005.88 0.0) (9931.45 1001.88 0.0) (9931.45 1001.88
0.0)
(9930.79 969.888 0.0) (9930.79 969.888 0.0) (9930.54 957.391 0.0) (9954.53
956.902 0.0) (9984.53 956.291 0.0) (9990.53 956.169 0.0) (9995.53 956.067
0.0)
(9994.98 929.073 0.0) (10041.5 928.126 0.0) (10101.0 926.915 0.0) (10101.9
972.405 0.0))

Command: (remduppts temp1 0.1) - two duplicates removed
((10103.1 1033.39 0.0) (9981.65 1035.87 0.0) (9944.66 1036.62 0.0) (9932.16
1036.87 0.0) (9931.53 1005.88 0.0) (9931.45 1001.88 0.0) (9930.79 969.888
0.0)
(9930.54 957.391 0.0) (9954.53 956.902 0.0) (9984.53 956.291 0.0) (9990.53
956.169 0.0) (9995.53 956.067 0.0) (9994.98 929.073 0.0) (10041.5 928.126
0.0)
(10101.0 926.915 0.0) (10101.9 972.405 0.0))

Joe Burke
Message 10 of 12
Anonymous
in reply to: richer

Thanks Joe, I will put that to good use.
It turns out that Reeta had a deawing with adjoining polygons, so this
approach wouldn't work any
because it selected all that it touched.
I took a slightly different approach using a window and min/max points on
the polyline.

(defun getpoly ( / ss ptlist lastent min_max minpt maxpt)
(setq pt (getpoint "\nSelect point inside polygon"))
(setq lastent (entlast))
(command ".boundary" pt "")
(setq ptlist nil)
(foreach x (entget (entlast))
(if (eq 10 (car x))
(setq ptlist (cons (cdr x) ptlist))
))
(if (not (equal lastent (entlast)))
(entdel (entlast))
)
(setq ptlist (reverse ptlist))
(setq min_max
(list
(apply 'mapcar (cons 'min ptlist))
(apply 'mapcar (cons 'max ptlist))
)
minpt (car min_max)
maxpt (cadr min_max)
)
(setq ss (ssget "w" minpt maxpt '((0 . "POLYLINE,LWPOLYLINE"))))
(print)
(if ss
(ssname ss 0)
(alert "No polyline found")
)
)

"Joe Burke" wrote in message
news:A27E498EB375C29670135C1236A9EC4A@in.WebX.maYIadrTaRb...
> Jim,
>
> I posted something recently in a thread called "selection like hatch"
> 7/18/02 which attempted to create a selection set using a boundary point
> list as your getpoly function does. I found it highly unreliable. (ssget
> "cp" ptlist) would often fail for no apparent reason.
>
> Turns out sometimes boundary creates a pline with duplicate points. ssget
> methods like "cp" "wp" and "f" will fail if there are duplicate points. So
> you have to weed out duplicates if they exist. I wrote the following to do
> that. If anyone has something similar/better, I'd love to see it. I'm
pretty
> new at this kind of stuff.
>
> ;remove duplicate points from point list
> ;arguments: OLST - pointlist, FUZ - fuzz distance
> ;returns new list with duplicates removed
> (defun RemDupPts (OLST FUZ / NLST P1 P2)
> (while (> (length OLST) 1)
> (setq P1 (car OLST) P2 (cadr OLST))
> (if (> (distance P1 P2) FUZ)
> (setq NLST (cons P1 NLST))) ;if
> (setq OLST (cdr OLST))
> ) ;while
> (setq NLST (cons (last OLST) NLST)) ;seems safe?
> (reverse NLST)
> ) ;end
>
> Sample point list temp1:
> ((10103.1 1033.39 0.0) (9981.65 1035.87 0.0) (9944.66 1036.62 0.0)
(9932.16
> 1036.87 0.0) (9931.53 1005.88 0.0) (9931.45 1001.88 0.0) (9931.45 1001.88
> 0.0)
> (9930.79 969.888 0.0) (9930.79 969.888 0.0) (9930.54 957.391 0.0) (9954.53
> 956.902 0.0) (9984.53 956.291 0.0) (9990.53 956.169 0.0) (9995.53 956.067
> 0.0)
> (9994.98 929.073 0.0) (10041.5 928.126 0.0) (10101.0 926.915 0.0) (10101.9
> 972.405 0.0))
>
> Command: (remduppts temp1 0.1) - two duplicates removed
> ((10103.1 1033.39 0.0) (9981.65 1035.87 0.0) (9944.66 1036.62 0.0)
(9932.16
> 1036.87 0.0) (9931.53 1005.88 0.0) (9931.45 1001.88 0.0) (9930.79 969.888
> 0.0)
> (9930.54 957.391 0.0) (9954.53 956.902 0.0) (9984.53 956.291 0.0) (9990.53
> 956.169 0.0) (9995.53 956.067 0.0) (9994.98 929.073 0.0) (10041.5 928.126
> 0.0)
> (10101.0 926.915 0.0) (10101.9 972.405 0.0))
>
> Joe Burke
>
>
Message 11 of 12
Anonymous
in reply to: richer

Jim,

You're welcome. I'm thinking about your posted below.

Joe Burke

> Thanks Joe, I will put that to good use.
> It turns out that Reeta had a deawing with adjoining polygons, so this
> approach wouldn't work any
> because it selected all that it touched.
> I took a slightly different approach using a window and min/max points on
> the polyline.
>
> (defun getpoly ( / ss ptlist lastent min_max minpt maxpt)
> (setq pt (getpoint "\nSelect point inside polygon"))
> (setq lastent (entlast))
> (command ".boundary" pt "")
> (setq ptlist nil)
> (foreach x (entget (entlast))
> (if (eq 10 (car x))
> (setq ptlist (cons (cdr x) ptlist))
> ))
> (if (not (equal lastent (entlast)))
> (entdel (entlast))
> )
> (setq ptlist (reverse ptlist))
> (setq min_max
> (list
> (apply 'mapcar (cons 'min ptlist))
> (apply 'mapcar (cons 'max ptlist))
> )
> minpt (car min_max)
> maxpt (cadr min_max)
> )
> (setq ss (ssget "w" minpt maxpt '((0 . "POLYLINE,LWPOLYLINE"))))
> (print)
> (if ss
> (ssname ss 0)
> (alert "No polyline found")
> )
> )
>
> "Joe Burke" wrote in message
> news:A27E498EB375C29670135C1236A9EC4A@in.WebX.maYIadrTaRb...
> > Jim,
> >
> > I posted something recently in a thread called "selection like hatch"
> > 7/18/02 which attempted to create a selection set using a boundary point
> > list as your getpoly function does. I found it highly unreliable. (ssget
> > "cp" ptlist) would often fail for no apparent reason.
> >
> > Turns out sometimes boundary creates a pline with duplicate points.
ssget
> > methods like "cp" "wp" and "f" will fail if there are duplicate points.
So
> > you have to weed out duplicates if they exist. I wrote the following to
do
> > that. If anyone has something similar/better, I'd love to see it. I'm
> pretty
> > new at this kind of stuff.
> >
> > ;remove duplicate points from point list
> > ;arguments: OLST - pointlist, FUZ - fuzz distance
> > ;returns new list with duplicates removed
> > (defun RemDupPts (OLST FUZ / NLST P1 P2)
> > (while (> (length OLST) 1)
> > (setq P1 (car OLST) P2 (cadr OLST))
> > (if (> (distance P1 P2) FUZ)
> > (setq NLST (cons P1 NLST))) ;if
> > (setq OLST (cdr OLST))
> > ) ;while
> > (setq NLST (cons (last OLST) NLST)) ;seems safe?
> > (reverse NLST)
> > ) ;end
> >
> > Sample point list temp1:
> > ((10103.1 1033.39 0.0) (9981.65 1035.87 0.0) (9944.66 1036.62 0.0)
> (9932.16
> > 1036.87 0.0) (9931.53 1005.88 0.0) (9931.45 1001.88 0.0) (9931.45
1001.88
> > 0.0)
> > (9930.79 969.888 0.0) (9930.79 969.888 0.0) (9930.54 957.391 0.0)
(9954.53
> > 956.902 0.0) (9984.53 956.291 0.0) (9990.53 956.169 0.0) (9995.53
956.067
> > 0.0)
> > (9994.98 929.073 0.0) (10041.5 928.126 0.0) (10101.0 926.915 0.0)
(10101.9
> > 972.405 0.0))
> >
> > Command: (remduppts temp1 0.1) - two duplicates removed
> > ((10103.1 1033.39 0.0) (9981.65 1035.87 0.0) (9944.66 1036.62 0.0)
> (9932.16
> > 1036.87 0.0) (9931.53 1005.88 0.0) (9931.45 1001.88 0.0) (9930.79
969.888
> > 0.0)
> > (9930.54 957.391 0.0) (9954.53 956.902 0.0) (9984.53 956.291 0.0)
(9990.53
> > 956.169 0.0) (9995.53 956.067 0.0) (9994.98 929.073 0.0) (10041.5
928.126
> > 0.0)
> > (10101.0 926.915 0.0) (10101.9 972.405 0.0))
> >
> > Joe Burke
> >
> >
>
>
Message 12 of 12
Anonymous
in reply to: richer

What is it that you are thinking about? Is there another problem that I
missed?
It seems to work.


"Joe Burke" wrote in message
news:97F8D854B12AF289783D4B24C6F59343@in.WebX.maYIadrTaRb...
> Jim,
>
> You're welcome. I'm thinking about your posted below.
>
> Joe Burke
>
> > Thanks Joe, I will put that to good use.
> > It turns out that Reeta had a deawing with adjoining polygons, so this
> > approach wouldn't work any
> > because it selected all that it touched.
> > I took a slightly different approach using a window and min/max points
on
> > the polyline.
> >
> > (defun getpoly ( / ss ptlist lastent min_max minpt maxpt)
> > (setq pt (getpoint "\nSelect point inside polygon"))
> > (setq lastent (entlast))
> > (command ".boundary" pt "")
> > (setq ptlist nil)
> > (foreach x (entget (entlast))
> > (if (eq 10 (car x))
> > (setq ptlist (cons (cdr x) ptlist))
> > ))
> > (if (not (equal lastent (entlast)))
> > (entdel (entlast))
> > )
> > (setq ptlist (reverse ptlist))
> > (setq min_max
> > (list
> > (apply 'mapcar (cons 'min ptlist))
> > (apply 'mapcar (cons 'max ptlist))
> > )
> > minpt (car min_max)
> > maxpt (cadr min_max)
> > )
> > (setq ss (ssget "w" minpt maxpt '((0 . "POLYLINE,LWPOLYLINE"))))
> > (print)
> > (if ss
> > (ssname ss 0)
> > (alert "No polyline found")
> > )
> > )
> >
> > "Joe Burke" wrote in message
> > news:A27E498EB375C29670135C1236A9EC4A@in.WebX.maYIadrTaRb...
> > > Jim,
> > >
> > > I posted something recently in a thread called "selection like hatch"
> > > 7/18/02 which attempted to create a selection set using a boundary
point
> > > list as your getpoly function does. I found it highly unreliable.
(ssget
> > > "cp" ptlist) would often fail for no apparent reason.
> > >
> > > Turns out sometimes boundary creates a pline with duplicate points.
> ssget
> > > methods like "cp" "wp" and "f" will fail if there are duplicate
points.
> So
> > > you have to weed out duplicates if they exist. I wrote the following
to
> do
> > > that. If anyone has something similar/better, I'd love to see it. I'm
> > pretty
> > > new at this kind of stuff.
> > >
> > > ;remove duplicate points from point list
> > > ;arguments: OLST - pointlist, FUZ - fuzz distance
> > > ;returns new list with duplicates removed
> > > (defun RemDupPts (OLST FUZ / NLST P1 P2)
> > > (while (> (length OLST) 1)
> > > (setq P1 (car OLST) P2 (cadr OLST))
> > > (if (> (distance P1 P2) FUZ)
> > > (setq NLST (cons P1 NLST))) ;if
> > > (setq OLST (cdr OLST))
> > > ) ;while
> > > (setq NLST (cons (last OLST) NLST)) ;seems safe?
> > > (reverse NLST)
> > > ) ;end
> > >
> > > Sample point list temp1:
> > > ((10103.1 1033.39 0.0) (9981.65 1035.87 0.0) (9944.66 1036.62 0.0)
> > (9932.16
> > > 1036.87 0.0) (9931.53 1005.88 0.0) (9931.45 1001.88 0.0) (9931.45
> 1001.88
> > > 0.0)
> > > (9930.79 969.888 0.0) (9930.79 969.888 0.0) (9930.54 957.391 0.0)
> (9954.53
> > > 956.902 0.0) (9984.53 956.291 0.0) (9990.53 956.169 0.0) (9995.53
> 956.067
> > > 0.0)
> > > (9994.98 929.073 0.0) (10041.5 928.126 0.0) (10101.0 926.915 0.0)
> (10101.9
> > > 972.405 0.0))
> > >
> > > Command: (remduppts temp1 0.1) - two duplicates removed
> > > ((10103.1 1033.39 0.0) (9981.65 1035.87 0.0) (9944.66 1036.62 0.0)
> > (9932.16
> > > 1036.87 0.0) (9931.53 1005.88 0.0) (9931.45 1001.88 0.0) (9930.79
> 969.888
> > > 0.0)
> > > (9930.54 957.391 0.0) (9954.53 956.902 0.0) (9984.53 956.291 0.0)
> (9990.53
> > > 956.169 0.0) (9995.53 956.067 0.0) (9994.98 929.073 0.0) (10041.5
> 928.126
> > > 0.0)
> > > (10101.0 926.915 0.0) (10101.9 972.405 0.0))
> > >
> > > Joe Burke
> > >
> > >
> >
> >
>
>

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost