Isaac26a Posted Friday at 01:18 AM Posted Friday at 01:18 AM (edited) Hello again, I had this task that I usually have from time to time and wondered if there is a way to select only the vertical lines that are in the drawing to delete them, some are slightly to one side left or right. I was wondering if something like select the lines and sort them by a difference of the x coordinate of the start point less the x coordinate of the end point plus a fuzz distance equals zero or maybe there is something much more simple to do, here is the image and the sample dwg file Thanks to all for your kind help. sample01.dwg Edited Friday at 01:19 AM by Isaac26a Quote
mhupp Posted Friday at 03:11 AM Posted Friday at 03:11 AM (edited) ssget lines check endpoints to get angle tho not so vertical. vert.mp4 SVL.lsp Edited Friday at 03:15 AM by mhupp 1 Quote
Isaac26a Posted Friday at 03:49 AM Author Posted Friday at 03:49 AM Thank you Mhupp, it works like charm, I didn't know that '(equal )' would work like that, I thought that would return nil everytime, something new to learn, thank you again for your help. 1 Quote
mhupp Posted Friday at 10:15 AM Posted Friday at 10:15 AM Its using the fuzz option. looking for lines that have an angle that doesn't match 90° or 270° +/- the fuzz and removing them from the selection. So if you used 5 it would remove any line that outside of 85-95 and 265-275 You have to check both angles because of how the lines are drawn. Quote fuzz Type: Integer or Real A real number defining the maximum amount by which expr1 and expr2 can differ and still be considered equal. https://help.autodesk.com/view/ACAD_E/2026/ENU/?guid=GUID-7E85CB8F-B4DA-42F3-ABD3-89342A11EF9B Quote
Lee Mac Posted Friday at 10:52 AM Posted Friday at 10:52 AM Another - (defun c:test ( / e i s x ) (if (setq s (ssget "_X" '((0 . "LINE")))) (repeat (setq i (sslength s)) (setq i (1- i) e (ssname s i) x (entget e) ) (if (not (equal (cadr (assoc 10 x)) (cadr (assoc 11 x)) 1e-8)) (ssdel e s) ) ) ) (sssetfirst nil s) (princ) ) 3 Quote
marko_ribar Posted Friday at 02:13 PM Posted Friday at 02:13 PM (edited) It is unclear what should routine do with angled lines that are neither horizontal, nor vertical... Lee's example is removing from sel. set all horizontal lines and thus all angled and verticals are remained for (sssetfirst) deletion upon routine finish... Edited Friday at 02:14 PM by marko_ribar Quote
Isaac26a Posted Friday at 02:21 PM Author Posted Friday at 02:21 PM (edited) 4 hours ago, mhupp said: You have to check both angles because of how the lines are drawn. Quote fuzz Type: Integer or Real A real number defining the maximum amount by which expr1 and expr2 can differ and still be considered equal. https://help.autodesk.com/view/ACAD_E/2026/ENU/?guid=GUID-7E85CB8F-B4DA-42F3-ABD3-89342A11EF9B Thank you, with this information is easy to understand how it works, in the information that I had of the command didn't had the fuzz use, guess I have to check on the online site more about the commands again, there might be some things I'm missing Edited Friday at 03:09 PM by Isaac26a Quote
Isaac26a Posted Friday at 02:24 PM Author Posted Friday at 02:24 PM (edited) 4 hours ago, Lee Mac said: Another Thank you Lee, you did what I was thinking about, you used the difference in 'x' with a fuzz, also used '(equal )' with the fuzz, thanks as all of your work in the most simple way and in few lines. Amazing all your work, thank you. Edited Friday at 03:10 PM by Isaac26a Quote
Isaac26a Posted Friday at 02:27 PM Author Posted Friday at 02:27 PM 12 minutes ago, marko_ribar said: It is unclear what should routine do with angled lines that are neither horizontal, nor vertical... Lee's example is removing from sel. set all horizontal lines and thus all angled and verticals are remained for (sssetfirst) deletion upon routine finish... My apologies if I'm not clear in the things I want to be realized, sometimes I think is best that the images make it clear but I'll try to elaborate more on my following posts. thanks for your interest Quote
Lee Mac Posted Friday at 05:20 PM Posted Friday at 05:20 PM 3 hours ago, marko_ribar said: It is unclear what should routine do with angled lines that are neither horizontal, nor vertical... Lee's example is removing from sel. set all horizontal lines and thus all angled and verticals are remained for (sssetfirst) deletion upon routine finish... That's incorrect; my code is only retaining vertical lines (to within a tolerance of 1e-8) - any line for which the x-coordinate of the start point does not match the x-coordinate of the end point (up to the tolerance stated) will be removed from the set. Quote
Lee Mac Posted Friday at 05:21 PM Posted Friday at 05:21 PM 2 hours ago, Isaac26a said: Thank you Lee, you did what I was thinking about, you used the difference in 'x' with a fuzz, also used '(equal )' with the fuzz, thanks as all of your work in the most simple way and in few lines. Amazing all your work, thank you. You're welcome! I'm glad it helps. Quote
marko_ribar Posted 17 hours ago Posted 17 hours ago No Lee... I am quite right in my observation... If only you removed that (not) from test expression (not (equal (cadr (assoc 10 x)) (cadr (assoc 11 x)) 1e-8)), your snippet would work as OP desired (gripped selecting all verticals and angled lines for forthcoming deletion)... Quote
mhupp Posted 14 hours ago Posted 14 hours ago (edited) 2 hours ago, marko_ribar said: No Lee... I am quite right in my observation... If only you removed that (not) from test expression (not (equal (cadr (assoc 10 x)) (cadr (assoc 11 x)) 1e-8)), your snippet would work as OP desired (gripped selecting all verticals and angled lines for forthcoming deletion)... I think you might be getting caught up on the cadr? the list its looking at has the 10 and 11 as the first element so the 2nd element is going to be the x value. (10 370477.766247702 2284988.06147298 0.0) & (11 370477.775905386 2284983.23263075 0.0) the 1e-8 is to aggressive for @Isaac26a sample drawing that is why I added a dynamic fuzz the user can pick if they want true vertical lines just input 0. I started with the x value comparison, but isn't a good option for angled lines as it changes for lines of the same same angle but different lengths. and if you increase to pick up longer lines it will picked shorter lines that have a greater angle. Edited 14 hours ago by mhupp 1 Quote
marko_ribar Posted 12 hours ago Posted 12 hours ago You are right @mhupp... But that is why I don't like programming... I tend to write understandable codes... If I was to be asked I'd rather write it (not (equal (car (cdr (assoc 10 x))) (car (cdr (assoc 11 x))) 1e-8))... And this Lee's code selects only vertical lines like topic was stated... Either way, if OP wanted to select lines before deletion and remain only horizontals, then this testing expression should be different like I thought [(equal (cadr (cdr (assoc 10 x))) (cadr (cdr (assoc 11 x))) 1e-8)] Quote
mhupp Posted 8 hours ago Posted 8 hours ago (edited) 6 hours ago, marko_ribar said: But that is why I don't like programming... That's why I like programming its dealers choice. sometimes its easier to do the opposite to get the results you want. like this simple lisp that invert the selection. if you wanted to select everything but 3 circles and their are 150 items. select the three circles and run this code. ;; Invert Selection on Screen (defun C:SEE (/ SS SS1) (vl-load-com) (if (setq SS (ssget "_I")) (progn) (setq ss (ssadd)) ) (if (setq SS1 (ssget "_WP" (GetScreenCoords))) (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) (ssdel ent SS1) ) ) (sssetfirst nil SS1) ) ;;----------------------------------------------------------------------------;; ;Calculates Size of View Window (defun GetScreenCoords (/ ViwCen ViwDim ViwSiz VptMin VptMax) (setq ViwSiz (/ (getvar 'VIEWSIZE) 2) ViwCen (getvar 'VIEWCTR) ViwDim (list (* ViwSiz (apply '/ (getvar 'SCREENSIZE))) ViwSiz) VptMin (mapcar '- ViwCen ViwDim) VptMax (mapcar '+ ViwCen ViwDim) ) (list VptMin VptMax) ) -Edit Again if your only comparing x or y values of the line end points isn't a good option as lsaac26a said "some are slightly to one side left or right." and is using vertical as a relative term. whether you using (if (not vertical or (if horizontal to make the final selection set. both will fail to select anything in the sample drawing. that's why i jokingly put in "Vertical-ish lines Selected" as the final prompt. -edit edit forgot the post getscreencords lisp Edited 6 hours ago by mhupp 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.