Lee Mac Posted September 3, 2017 Posted September 3, 2017 You have wrote both routines and a third to generate random points and evaluated them!! You are my hero!! You are too kind guigonse Questions: how do you make "solid" time measurements with Lisp? And with Visual Lisp? Personally, I reference the MILLISECS system variable; you can also use the (_vl-times) function. Roy has covered your other points - thanks Roy. Quote
guigonse Posted September 3, 2017 Posted September 3, 2017 @guigonse:In principle you are right, although your window points are not in the correct order. But please note this: Your code assumes a 2D drawing. The window selection has to be on-screen. Lee has already referred to this. The end and start point of the line are expressed in the WCS whereas the "CW" points are expressed in the current UCS. @Roy_043, you're right, selection points should form a loop, not a lace like mines do; third and fourth points should be invert their order, and p1 - p2 should be in WCS, probably using (trans ..) command... And thanks for clarifying criteria; just to be concise: isn't Lee Mac's answer 2D dependent too, when it uses an XY point (dist dist) for the filter selection? I understand that any kind of (ssget ..) that implies a "visual" selection will fail if some of the selection vertex's are out of screen... Lee Mac, thanks for "time control" info... Quote
Roy_043 Posted September 3, 2017 Posted September 3, 2017 (edited) @guigonse: Lee's code works in two steps. In the 'ssget' step all points within a certain bounding box are preselected. In a way this box is not a box as it has no Z-limits. In the next step the actual 3D distance of each preselected point to the line is checked for the final selection. BTW: You have used "_CW" in your code, this should be "_CP". I hadn't notice this before. And p1 and p2 should be translated from the WCS to the current UCS for the ssget function. Edited September 3, 2017 by Roy_043 Quote
BIGAL Posted September 4, 2017 Posted September 4, 2017 Re on screen as your picking a line you could some form of Zoom C factor so its just a nice size when you pick the objects and they will be on screen, something that I have had to with some code is zoom in a bit so it would work, in this case zoom out. Quote
guigonse Posted September 4, 2017 Posted September 4, 2017 @Roy_043, I'm writing without checking, apologies... I meant "Window-Polygon" selection. About Lee Mac's filtered pre-selection, my question was about the possibility of making it really tridimensional, adding a Z-distance filter too. @BIGAL, zoom's pre-process would be the easy way to guarantee all candidate nodes are on screen; again, as Mac Lee commented, it seems to be a question of efficiency (and interface politeness :-) Thanks' to all!! Quote
Roy_043 Posted September 4, 2017 Posted September 4, 2017 @guigonse: You are right: The preselection box could have Z-limits as well. And rereading Lee's code I notice the points from a polyline are not translated as they should be (OCS->WCS). Quote
guigonse Posted September 4, 2017 Posted September 4, 2017 Well, it's a (trans ..) matter in selection evaluation... This has been an exhaustive analysis thread!! Bravo!! Quote
hanhphuc Posted September 4, 2017 Posted September 4, 2017 Interesting discussion but OP doesn't respond? Both Tharwat's & Lee's are smart using offset-dis bounding box method, activeX & vanilla respectively. The different is Tharwat used selection crossing mode "C" points which expressed relative to the UCS, but the bounding box is in WCS coordinates, ie: Tharwat's code need to add trans if work in UCS. However he just provides us quick & dirty "c:Test" but it's enough telling us bounding box method is working, it doesn't metter UCS etc.. after all the forum is volunteery & foc. on the other hand, vla-offset method though we know is not efficient for this case due to the end point is parallel does not cover the required dis, it was just an alternative way for testing too. However Lee had free time to provide "fish" for OP, maybe he knew Tharwat already had provided activeX bounding box method so tried his best to write this custom vanilla bounding box as an alternative for readers, sorry if im wrong And rereading Lee's code I notice the points from a polyline are not translated as they should be (OCS->WCS). Since the selection filter corners ll & ur , ss are WCS coordinates, IMO there's no problem without trans. good job Lee This has been an exhaustive analysis thread!! Bravo!! FYI, if a line has big diffence in elevations at endpoint, vlax-curve-getclosestpointto would yield unexpected result it has beed discussed before, here consider vlax-curve-getclosestpointtoprojection Quote
Roy_043 Posted September 4, 2017 Posted September 4, 2017 @hanhphuc: If you check you will find that the points of an LWPOLYLINE are expressed in the OCS not in the WCS. Translating these points is required if you want a function that is not restricted to 2D drawings. Quote
Tharwat Posted September 4, 2017 Posted September 4, 2017 Here is the updated routine to work with UCS regardless of the visibility of the selected Line / LWpolyline. (defun c:Test ( / dis sel obj cad lft rgt int sad ssc ent pnt) ;; Tharwat - Date: 01.Sep.2017 ;; (if (and (setq dis (getdist "\nSpecify distance between line and points : ")) (princ "\nSelect Line/Polyline :") (setq sel (ssget "_+.:S:E" '((0 . "LINE,LWPOLYLINE")))) (setq cad (vlax-get-acad-object) obj (ssname sel 0)) ) (progn (vla-GetBoundingBox (vlax-ename->vla-object obj) 'lft 'rgt) (vla-zoomwindow cad lft rgt) (setq int -1 sad (ssadd)) (if (setq ssc (ssget "_C" (trans (mapcar '(lambda (c d) (+ d c)) (list dis dis 0.) (vlax-safearray->list rgt)) 0 1) (trans (mapcar '(lambda (c d) (- d c)) (list dis dis 0.) (vlax-safearray->list lft)) 0 1) '((0 . "POINT")))) (while (setq ent (ssname ssc (setq int (1+ int)))) (setq pnt (cdr (assoc 10 (entget ent)))) (if (<= (distance (vlax-curve-getclosestpointto obj pnt) pnt) dis) (ssadd ent sad)) ) ) (vla-zoomprevious cad) ) ) (sssetfirst nil sad) (princ) ) (vl-load-com) Quote
Lee Mac Posted September 4, 2017 Posted September 4, 2017 And rereading Lee's code I notice the points from a polyline are not translated as they should be (OCS->WCS). Well spotted Roy - below is an updated version to correct this, and to also place a 'lid' & 'base' on the ssget point filter box: (defun c:ptnearline ( / dis elv ent enx idx llp lst pnt pte sel tmp urp ) (initget 4) (if (and (setq dis (getdist "\nSpecify proximity: ")) (progn (while (not (progn (setvar 'errno 0) (setq ent (car (entsel "\nSelect line or polyline: "))) (cond ( (= 7 (getvar 'errno)) (prompt "\nMissed, try again.") ) ( (null ent)) ( (= "LINE" (cdr (assoc 0 (setq enx (entget ent))))) (setq llp (cdr (assoc 10 enx)) urp (cdr (assoc 11 enx)) tmp (mapcar 'max llp urp) llp (mapcar 'min llp urp) urp tmp ) ) ( (= "LWPOLYLINE" (cdr (assoc 0 enx))) (setq elv (list (cdr (assoc 38 enx))) lst (mapcar '(lambda ( x ) (trans (append (cdr x) elv) ent 0)) (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) enx)) llp (apply 'mapcar (cons 'min lst)) urp (apply 'mapcar (cons 'max lst)) ) ) ( (prompt "\nPlease select a line or polyline.")) ) ) ) ) ent ) (setq sel (ssget "_X" (list '(000 . "POINT") '(-04 . ">=,>=,>=") (cons 10 (mapcar '- llp (list dis dis dis))) '(-04 . "<=,<=,<=") (cons 10 (mapcar '+ urp (list dis dis dis))) (if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 . "Model") ) ) ) ) ) (repeat (setq idx (sslength sel)) (setq pte (ssname sel (setq idx (1- idx))) pnt (cdr (assoc 10 (entget pte))) ) (if (< dis (distance pnt (vlax-curve-getclosestpointto ent pnt))) (ssdel pte sel) ) ) ) (sssetfirst nil sel) (princ) ) (vl-load-com) (princ) 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.