Jump to content

Recommended Posts

Posted

Hello everybuddies,

 

I am new to lisp, so please for your advise.

I want to pick an existing multi-segment polyline and use it as a selection fence (ssget "_F")

 

As far as I understand I miss a simple piece of code that

lists the points of the polyline in a way that ssget can accept them as a list of points to define the fence.

 

(setq POLY (entsel "\n Pick a Fence Line crossing your beloved entities:"))

 

****POLY---->(please help!)----->POINTLIST****

 

(setq ss (ssget "_F" POINTLIST ) )

 

 

Thanx in advance

Posted

No code needed the Express Tool Fastsel already does that.

Posted

Thank you Tombu,

What I am asking for is a small part of a really complicated tool I am working on...

 

"Fastsel" returns a selection set that additionally contains the "fence" itself and I am not sure if I can use filter-lists after the command.

 

I will try to exclude entities laying on other layers...

 

EDIT:

Tried to use it into the lisp, but

(command "fastsel" ...) and (command "fsmode" ...) don't work.

I probably have to call Express tools somehow...

But I really prefer to have a clear lisp solution.

Posted

Select the polyline then use the vlax-curve* functions to place points on the selected polyline then use the ssget function with F string mode to get the objects you want to select.

 

I am writing from mobile so no codes available at the moment.:)

Posted
(defun c:SelectInside (/ ss i pt points)
 (if
   (and
     (setq ss (ssget ":S:E:L" '((0 . "LWPOLYLINE"))))
     (setq ss (ssname ss 0))
     (setq i -1.0)
     )
   (progn
     (while
       (setq pt (vlax-curve-getpointatparam ss (setq i (+ 1.0 i))))
        (setq points (cons (list (car pt) (cadr pt)) points))
     ) 
     (sssetfirst nil (ssdel ss (ssget "_cp" points)))
   )
 )
 (princ)
)

Posted

Thanx Tharwat (peace in your country bro),

 

Interesting! I would really appreciate it if you write later some lines to show me how it works with the vlax-curve functions.

Just have in mind that the tool is for urban planning.

Meaning that the fence i wanna use will be really long 5-6-7-8 Km...

It will be used to select polygons presenting plot-properties...

Posted
Thank you Tombu,

What I am asking for is a small part of a really complicated tool I am working on...

 

"Fastsel" returns a selection set that additionally contains the "fence" itself and I am not sure if I can use filter-lists after the command.

 

I will try to exclude entities laying on other layers...

 

EDIT:

Tried to use it into the lisp, but

(command "fastsel" ...) and (command "fsmode" ...) don't work.

I probably have to call Express tools somehow...

But I really prefer to have a clear lisp solution.

 

You could use (command "c:fastsel") or just (fastsel), but BlackBox's lisp solution is spot on.

Posted

Taking nothing away from Blackbox's suggestion above, here is another way to approach it:

(defun c:fencesel ( / sel )
   (if (setq sel (ssget "_+.:E:S" '((0 . "LWPOLYLINE") (-4 . "<NOT") (-4 . "<>") (42 . 0.0) (-4 . "NOT>"))))
       (sssetfirst nil
           (ssget "_F"
               (mapcar 'cdr
                   (vl-remove-if-not '(lambda ( x ) (= 10 (car x)))
                       (entget (ssname sel 0))
                   )
               )
           )
       )
   )
   (princ)
)

All of the suggested methods will only be compatible with straight-segmented polylines, since the ssget function will only accept a list of UCS points hence restricting the selection to a linear path. Therefore, in the above and below examples I have restricted the initial selection to polylines containing only straight segments.

 

Be aware that since the F mode string is a graphical selection method, all candidate objects must be visible in the drawing area in order to be included in the selection (this is documented in my reference here). For this reason, it can be beneficial to zoom to the extents of the fence path prior to evaluating the ssget expression, and then zoom to the previous view setting, e.g.:

(defun c:fencesel ( / app lst sel )
   (if (setq sel (ssget "_+.:E:S" '((0 . "LWPOLYLINE") (-4 . "<NOT") (-4 . "<>") (42 . 0.0) (-4 . "NOT>"))))
       (progn
           (setq app (vlax-get-acad-object)
                 lst (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) (entget (ssname sel 0))))
           )
           (apply 'vla-zoomwindow
               (cons app
                   (mapcar
                       '(lambda ( x ) (vlax-3D-point (apply 'mapcar (cons x lst))))
                       '(min max)
                   )
               )
           )
           (sssetfirst nil (ssget "_F" lst))
           (vla-zoomprevious app)
       )
   )
   (princ)
)
(vl-load-com) (princ)

Posted (edited)
Thanx Tharwat (peace in your country bro),

 

Thanks a lot , it is very kind of you to say that .

 

 

Interesting! I would really appreciate it if you write later some lines to show me how it works with the vlax-curve functions.

Just have in mind that the tool is for urban planning.

Meaning that the fence i wanna use will be really long 5-6-7-8 Km...

It will be used to select polygons presenting plot-properties...

 

 

I have changed my mind with vlax-curve-* functions with Intersectwith function , so try it and let me know .

 

(defun c:Test (/ s ss v g)
 ;; Tharwat 11.05.2015        ;;
 (princ "\nSelect LWpolyline :")
 (if (and (setq s (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))))
          (setq
            ss (ssget "_X"
                      (list '(0 . "LWPOLYLINE") (cons 410 (getvar 'CTAB)))
               )
          )
          (setq v (vlax-ename->vla-object (ssname s 0))
                g (ssadd)
          )
     )
   ((lambda (i / o)
      (while (setq o (ssname ss (setq i (1+ i))))
        (if (vlax-invoke
              v
              'Intersectwith
              (vlax-ename->vla-object o)
              AcExtendnone
            )
          (ssadd o g)
        )
      )
    )
     -1
   )
 )
 (sssetfirst nil g)
 (princ)
)(vl-load-com)

Edited by Tharwat
typo
Posted

just another $0.05 using VL you can get co-odds of a pline make them a list and use ssget F lst hate iPad spell check.

Posted

Thanx BrianTFC BUT who asked for a trimming tool?

 

 

Ok guys!

Thank you very much for your immediate response!

You gave me much more than a "polyline-turns-into-it's-points-list" code!

All the three suggestion worked pretty well, after some minor modifications.

Though in my case, Blackbox's suggestion fits best.

 

So this is how it looks like now (between the other lines) and works fine:

 

(princ "\n Pick a FENCE LINE crossing the polygons:")
(setq POLY (ssget ":S:E:L" '((0 . "LWPOLYLINE"))))
(setq POLY (ssname POLY 0))
(setq i -1.0)
(while
       (setq PNT (vlax-curve-getpointatparam POLY (setq i (+ 1.0 i)))) 
       (setq PNTlist (cons (list (car PNT) (cadr PNT)) PNTlist))	
) 

(setq ss (ssget  "_F" (reverse PNTlist)  '((8 . "MY-LAYER*") (0 . "*polyline")) ) )

Posted

Taking nothing away from Blackbox's suggestion above, here is another way to approach it:

 

Of the many things you do for this community, 'taking away' is not one that you can be accused of. :P

 

Cheers

Posted

Ok guys!

Thank you very much for your immediate response!

You gave me much more than a "polyline-turns-into-it's-points-list" code!

All the three suggestion worked pretty well, after some minor modifications.

Though in my case, Blackbox's suggestion fits best.

 

So this is how it looks like now (between the other lines) and works fine:

 

(princ "\n Pick a FENCE LINE crossing the polygons:")
(setq POLY (ssget ":S:E:L" '((0 . "LWPOLYLINE"))))
(setq POLY (ssname POLY 0))
(setq i -1.0)
(while
       (setq PNT (vlax-curve-getpointatparam POLY (setq i (+ 1.0 i)))) 
       (setq PNTlist (cons (list (car PNT) (cadr PNT)) PNTlist))	
) 

(setq ss (ssget  "_F" (reverse PNTlist)  '((8 . "MY-LAYER*") (0 . "*polyline")) ) )

 

Glad you got it sorted, Looper; I'm happy to help... Just be sure to come back here to benefit from other's code when this snippet is no longer suitable for other tasks down the road. :beer:

 

Cheers

Posted

Be sure man!

I am visiting cadtutor forum many years now (from time to time) but I never signed in to ask... I always find what I am looking for!

Probably I will come back very soon with a new question but first i want to struggle a little bit searching the old posts once more.

"That's the way aha - aha I like it aha - aha..."

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...