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

selection set using existing polygon

9 REPLIES 9
Reply
Message 1 of 10
islam.a.hamza95
894 Views, 9 Replies

selection set using existing polygon

Hi all,

sorry if this question seems to be silly, i am beginner at autolisp 

I want to create  selection set from an existing polyline that the user picks.  The selection set should select everything inside of the closed polyline.

and i tried all arguments I know in ssget function and it didn't work for me.

can anyone help me ?

 

Labels (3)
9 REPLIES 9
Message 2 of 10
ВeekeeCZ
in reply to: islam.a.hamza95

If your polygon is lwpolyline without arc segments, you can use the attachment. That's probably not mine but looks good as an example of how to approach such a task.

Message 3 of 10

Regards  @islam.a.hamza95 

For what you require there are many examples in the forums. But if you want to learn, to start with the ssget method, you can use the following:

 

 

;;;1. Select the polyline and apply any method to get the list of points of its vertices
(setq p_list(entget(car(entsel"\nSelect the LwPolyline: "))))
;;;..........
;;;2. Apply the SSGET method, Polygon window. To select objects that are inside the selected polygon
(setq s (sssetfirst nil (ssget "_wp" (list p_list))))

 

 

 To learn, try first, if you can't, ask for help..., here we are happy to help


Carlos Calderon G
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 4 of 10
Sea-Haven
in reply to: islam.a.hamza95

Sometimes also want "CP".

 

For pline pts

 

(setq plent (entsel "\nPick pline"))
(if plent (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent))))))
(princ co-ord)

Note if you have arcs it becomes more complicated and need to use facets around the arcs.

 

Message 5 of 10
pbejse
in reply to: islam.a.hamza95


@islam.a.hamza95 wrote:

...and i tried all arguments I know in ssget function and it didn't work for me

 


 

CP
Crossing polygon selection; all objects crossing and inside of the specified polygon.
syntax is
(ssget "_CP"  [pt-list] [filter-list])

 

You need to retrieve the vertices of the selected polyline.

Note that objects visible in the drawing area at the time of selection  will be selected

 

HTH

Message 6 of 10
Kent1Cooper
in reply to: calderg1000


@calderg1000 wrote:
...
(setq p_list(entget(car(entsel"\nSelect the LwPolyline: "))))
(setq s (sssetfirst nil (ssget "_wp" (list p_list))))

That feeds the entire entity data list for the Polyline into the (ssget) function for a window polygon, but it can't take that -- it needs a list of points only.

 

Command: (setq s (sssetfirst nil (ssget "_wp" (list p_list))))
; error: bad list of points

Kent Cooper, AIA
Message 7 of 10
calderg1000
in reply to: Kent1Cooper

Dear @Kent1Cooper 

It's true, although my intention was just to give the OP an idea, to start. But surely I should have been much more explicit. Here is the complete code that allows the selection of objects inside a polygon (Lwpolyline)

(defun c:SelW (/ p_list p_coord)
  (setq p_list (entget (car (entsel "\nSelect the LwPolyline: "))))
  (if (setq
        p_coord (mapcar 'cdr
                        (vl-remove-if-not '(lambda (x) (= (car x) 10)) p_list)
                )
      )
    (sssetfirst nil (ssget "_wp" p_coord))
  )
)

 

 


Carlos Calderon G
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 8 of 10

 

Hi
Please- maybe get further help,
upload such sample.dwg

 

Message 9 of 10
_Tharwat
in reply to: calderg1000

What's if a user missed to select any object, what would happen ?

Of course an error message will be printed on command line and what's more it will break up the routine.

 

Again suppose a user picked another object which is does not have DXF 10 , what will happen ?

I will leave this answer for you.

 

Besides all of the above, the object(s) must be visible in current screen limits as @pbejse announced earlier. 😉

Message 10 of 10
Sea-Haven
in reply to: islam.a.hamza95

To make sure pick a pline can use this idea use ssget with E: option but also (0 . "LWPOLYLINE") as a filter it will then ignore a pick wrong object. You then use (ssname ss 0) to get pline object back out of the selection. Wrap it in a while to make sure correct pick.

 

(setq ss (ssget "_+.:E:S" '((0 . "LWPOLYLINE")))) I selected a line
Select entities: nil 

(setq ss  (ssget "_+.:E:S" '((0 . "LWPOLYLINE")))) I selected a pline
Select entities:<Selection set: 0000000068F17D70>

(setq ent (entget  (ssname ss 0)))

(setq ent (entget (ssname ss 0)))
((-1 . <Entity name: 68f15230>) (0 . "LWPOLYLINE") (5 . "11C49") (330 . <Entity name: 3eecdcb0>) (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "DEFAULT") (370 . -1) (100 . "AcDbPolyline") (90 . 3) (70 . 0) (43 . 0.0) (38 . 0.0) (39 . 0.0) (10 0.8 -9.8) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 1.93319257450986 -2.89233218885884) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 11.2740839009524 -3.94482885279246) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (210 0.0 0.0 1.0))

 

 

 

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report