SteveDoingStuff Posted July 8, 2022 Posted July 8, 2022 Hi, I have put together a script, that requires the user to first select a line then a polyline. It the looks for the next vertices on the polyline (relative to the intersection point of those two lines). On those vertices are blocks that I want to be selected as pre_blk and post_blk respectively. What I dont understand is the ssget method apparently not applying the filter '((0 . "INSERT")) when called. Therefore I end up with the polyline selected as pre_blk (one of the blocks is correctly assigned to post_blk) when I type (sssetfirst nil pre_blk). I would attach a sample dwg but apparently its not possible here. (thanks to Lee-Mac and dlanorh for the supplied functions and code snippets, credited in the code): (defun c:selectblocks (/) (if (setq ss1 (ssget ":S")) (if (setq ss2 (ssget ":S")) ;; Look for previous and next vertex on polyline (foreach pnt (LM:intersectionsbetweensets ss1 ss2) ;; get the next vertices relative to the intersection point ;; thanks to dlanorh (https://www.cadtutor.net/forum/topic/68855-vertices-of-polyline-near-a-point/) (setq poly (vlax-ename->vla-object (ssname ss2 0))) (setq p_param (vlax-curve-getparamatpoint poly pnt)) (setq pre_vtx (vlax-curve-getpointatparam poly (fix p_param)) ;gets the coords of the vertex before post_vtx (vlax-curve-getpointatparam poly (1+ (fix p_param))) ;the coords of the vertex after ) ;;get blocks at vertices (setq filter '((0 . "INSERT"))) (setq pre_blk (ssget "_X" (list '(-4 . "=,=,=") (cons '10 pre_vtx) filter))) (setq post_blk (ssget "_X" (list '(-4 . "=,=,=") (cons '10 post_vtx) filter))) ;;if selection fails, try fence selection: (if (not pre_blk) (progn (setq co_incr (+ 0.18 (car pre_vtx))) ;;assuming a circle diameter of 0.25 cm (setq rest (cdr pre_vtx)) (setq incr (cons co_incr rest)) (setq pre_blk (ssget "_F" (list pre_vtx incr) filter)) ) ) (if (not post_blk) (progn (setq co_incr (+ 0.18 (car post_vtx))) ;;assuming a circle diameter of 0.25 cm (setq rest (cdr post_vtx)) (setq incr (cons co_incr rest)) (setq post_blk (ssget "_F" (list post_vtx incr) filter)) ) ) ) ) ) ) ;; Intersections Between Sets - Lee Mac ;; Returns a list of all points of intersection between objects in two selection sets. ;; ss1,ss2 - [sel] Selection sets (defun LM:intersectionsbetweensets (ss1 ss2 / id1 id2 ob1 ob2 rtn) (repeat (setq id1 (sslength ss1)) (setq ob1 (vlax-ename->vla-object (ssname ss1 (setq id1 (1- id1))))) (repeat (setq id2 (sslength ss2)) (setq ob2 (vlax-ename->vla-object (ssname ss2 (setq id2 (1- id2)))) rtn (cons (LM:intersections ob1 ob2 acextendnone) rtn) ) ) ) (apply 'append (reverse rtn)) ) ;; Intersections - Lee Mac ;; Returns a list of all points of intersection between two objects ;; for the given intersection mode. ;; ob1,ob2 - [vla] VLA-Objects ;; mod - [int] acextendoption enum of intersectwith method (defun LM:intersections (ob1 ob2 mod / lst rtn) (if (and (vlax-method-applicable-p ob1 'intersectwith) (vlax-method-applicable-p ob2 'intersectwith) (setq lst (vlax-invoke ob1 'intersectwith ob2 mod)) ) (repeat (/ (length lst) 3) (setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn) lst (cdddr lst) ) ) ) (reverse rtn) ) Quote
mhupp Posted July 8, 2022 Posted July 8, 2022 (edited) Since your using :S with ssget just switched them over to entsel opted not to extend either object to get intersections. please change to meat your needs. (defun c:selectblocks (/ obj1 obj2 pnt poly p_param pre_vtx pre_blk post_vtx post_blk incr) (if (and (setq obj1 (car (entsel "\nSelect Line: "))) (setq obj2 (car (entsel "\nSelect Polyline: ")))) (foreach pnt (LM:intersections (vlax-ename->vla-object obj1) (vlax-ename->vla-object obj2) acextendnone) ;Do not extend either object ;; get the next vertices relative to the intersection point ;; thanks to dlanorh (https://www.cadtutor.net/forum/topic/68855-vertices-of-polyline-near-a-point/) (setq poly (vlax-ename->vla-object obj2) p_param (vlax-curve-getparamatpoint poly pnt) pre_vtx (vlax-curve-getpointatparam poly (fix p_param)) ;gets the coords of the vertex before post_vtx (vlax-curve-getpointatparam poly (1+ (fix p_param))) ;the coords of the vertex after ) ;;if selection fails, try fence selection: (if (not (setq pre_blk (ssget "_X" (list '(0 . "INSERT") (cons 10 pre_vtx))))) (progn (setq incr (list (mapcar '+ pre_vtx '(1 0 0)) (mapcar '- pre_vtx '(1 0 0)))) ;extend fence in both directions (setq pre_blk (ssget "_F" incr '((0 . "INSERT")))) ) ) (if (not (setq post_blk (ssget "_X" (list '(0 . "INSERT") (cons 10 post_vtx))))) (progn (setq incr (list (mapcar '+ post_vtx '(1 0 0)) (mapcar '- post_vtx '(1 0 0)))) ;extend fence in both directions (setq post_blk (ssget "_F" incr '((0 . "INSERT")))) ) ) ) ) ) ;; Intersections - Lee Mac ;; Returns a list of all points of intersection between two objects ;; for the given intersection mode. ;; ob1,ob2 - [vla] VLA-Objects ;; mod - [int] acextendoption enum of intersectwith method (defun LM:intersections ( ob1 ob2 mod / lst rtn ) (if (and (vlax-method-applicable-p ob1 'intersectwith) (vlax-method-applicable-p ob2 'intersectwith) (setq lst (vlax-invoke ob1 'intersectwith ob2 mod)) ) (repeat (/ (length lst) 3) (setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn) lst (cdddr lst) ) ) ) (reverse rtn) ) Edited July 8, 2022 by mhupp 1 Quote
exceed Posted July 9, 2022 Posted July 9, 2022 (edited) in this line (setq filter '((0 . "INSERT"))) (setq pre_blk (ssget "_X" (list '(-4 . "=,=,=") (cons '10 pre_vtx) filter))) (setq post_blk (ssget "_X" (list '(-4 . "=,=,=") (cons '10 post_vtx) filter))) 1. do not mix " '(( " and " (list (cons ", it's better to know. you can convert that (setq filter (list (cons 0 "INSERT"))) 2. so after convert, you can see that (list (cons 0 "INSERT")) is already in the list. in example, when you use ssget (ssget "_X" '((0 . "INSERT"))) is correct. but your example has (ssget "_X" (list ~~ '((0 . "INSERT")))) if you want to add filter option. you can play in that () like this (ssget "_X" (list (cons 0 ~~) (cons 8 ~~) (cons 10 ~~))) 3. (cons '10 -> (cons 10 Edited July 9, 2022 by exceed 1 Quote
SteveDoingStuff Posted July 11, 2022 Author Posted July 11, 2022 On 7/9/2022 at 7:40 AM, exceed said: in this line (setq filter '((0 . "INSERT"))) (setq pre_blk (ssget "_X" (list '(-4 . "=,=,=") (cons '10 pre_vtx) filter))) (setq post_blk (ssget "_X" (list '(-4 . "=,=,=") (cons '10 post_vtx) filter))) 1. do not mix " '(( " and " (list (cons ", it's better to know. you can convert that (setq filter (list (cons 0 "INSERT"))) 2. so after convert, you can see that (list (cons 0 "INSERT")) is already in the list. in example, when you use ssget (ssget "_X" '((0 . "INSERT"))) is correct. but your example has (ssget "_X" (list ~~ '((0 . "INSERT")))) if you want to add filter option. you can play in that () like this (ssget "_X" (list (cons 0 ~~) (cons 8 ~~) (cons 10 ~~))) 3. (cons '10 -> (cons 10 Thank you very much @exceed and @mhupp, I wasn't aware of how sensitive the filter option is towards mixing those formats of dotted pair lists. When debugging, the value of what I got in (list '(-4 . "=,=,=") (cons '10 pre_vtx) filter) seemed legitimate, I also expected there to be an error message when the list is malformatted, instead it seems to be ignored. Since @devitg asked, and for further clarification (though it now works as intended), I now attached the dwg. Thank you all! selectblocks.dwg Quote
BIGAL Posted July 12, 2022 Posted July 12, 2022 (edited) For me when in doubt just use cons for everything. (setq pre_blk (ssget "_X" (list (cons -4 "=,=,=") (cons 10 pre_vtx)(cons 0 "INSERT")))) Edited July 12, 2022 by BIGAL 2 Quote
Recommended Posts
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.