aridzv Posted August 3, 2023 Share Posted August 3, 2023 (edited) Hi. following this topic, I have a list ("Datalist" in the attached lisp) that contain a color and layer definition. the ssget list contain lines from 3 designated layer in the drawing,and each line has a color (obviously...). I need to take out all the lines from the ssget list that their color is not in the Datalist, and use that list in the foreach loop. is there a way to do it? I've attached a sample drawing that contain the lines to convert and the lisp. one line has a color number of 23 that is not in the Datalist. I need to take it out of the list that go to the foreach loop. Any help will be appreciated!! thanks, aridzv. PipeConvert_IRRI_UPDATE.lsp sample.dwg Edited August 3, 2023 by aridzv 1 Quote Link to comment Share on other sites More sharing options...
mhupp Posted August 4, 2023 Share Posted August 4, 2023 (edited) So close just need to add an if statement. Also sorted your list by color number -Edit Added undo points Fyi (foreach ent (mapcar 'cadr (ssnamex ss))) ;ssget "_X" (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) ;all other ssget (foreach obj (mapcar 'vlax-Ename->Vla-Object (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))) ;if you want vla-objects instead of ename (defun c:PipeConvert_IRRI_UPDATE (/ Datalist ss f i ent eData) (vl-load-com) (vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object)))) ;list (Color | Layer | Global Width) (setq Datalist '((1 "P_DN90-6" 0.2) (2 "P_DN250-6" 0.3) (3 "P_DN110-6" 0.25) (4 "P_DN63-6" 0.15) (5 "P_DN160-6" 0.3) (6 "P_DN50-6" 0.15) (7 "P_DN315-6" 0.3) (8 "P_DN140-6" 0.2) (9 "P_DN315-8" 0.3) (14 "P_DN90-10" 0.2) (20 "P_DN225-6" 0.3) (21 "P_DN32-4" 0.1) (22 "P_DN32-6" 0.1) (24 "P_DN16-4" 0.05) (26 "P_DN32-8" 0.1) (51 "P_DN25-6" 0.05) (52 "P_DN450-6" 0.3) (54 "P_DN25-4" 0.05) (56 "P_DN250-12.5" 0.3) (58 "P_DN63-10" 0.15) (81 "P_DN110-10" 0.25) (82 "P_DN280-6" 0.3) (86 "P_DN280-10" 0.3) (91 "P_DN110-12.5" 0.25) (92 "P_DN280-8" 0.3) (94 "P_DN40-6" 0.1) (96 "P_DN280-12.5" 0.3) (111 "P_DN140-10" 0.2) (112 "P_DN355-6" 0.3) (116 "P_DN40-8" 0.1) (120 "P_DN63-8" 0.15) (121 "P_DN140-8" 0.2) (122 "P_DN40-4" 0.1) (134 "P_DN110-8" 0.25) (171 "P_DN160-10" 0.3) (172 "P_DN160-8" 0.3) (174 "P_DN20-4" 0.05) (176 "P_DN160-12.5" 0.3) (178 "P_DN75-12.5" 0.15) (200 "P_DN225-8" 0.3) (201 "P_DN225-10" 0.3) (202 "P_DN75-6" 0.15) (204 "P_DN225-12.5" 0.3) (206 "P_DN75-10" 0.15) (208 "P_DN75-8" 0.15) (214 "P_DN50-10" 0.15) (230 "P_DN50-8" 0.15) (231 "P_DN200-6" 0.3) (234 "P_DN16-6" 0.05) (238 "P_DN90-8" 0.2) (252 "P_DN315-12.5" 0.3) (253 "P_DN315-10" 0.3) (254 "P_DN125-6" 0.2))) (if (setq ss (ssget "_X" '((0 . "LINE") (8 . "MAINLINE_PIPES,ZONE_PIPES,SPRAYLINES")))) (foreach ent (mapcar 'cadr (ssnamex SS)) (setq eData (mapcar '(lambda (d) (cdr (assoc d (entget ent)))) '(62 10 11))) (if (setq f (assoc (car edata) Datalist)) ;if f # isnt found skip entity (progn (ssdel ent ss) (entmake (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") '(90 . 2) '(70 . 0) (cons 8 (cadr f)) (cons 43 (caddr f)) (cons 10 (cadr eData)) (cons 10 (caddr eData)) ) ) ) ) ) ) (vla-endundomark doc) (princ) ) Edited August 4, 2023 by mhupp 2 1 Quote Link to comment Share on other sites More sharing options...
aridzv Posted August 4, 2023 Author Share Posted August 4, 2023 @mhupp TO THE RESCUE AGAIN (or should I say "as usual"...). worked like a charm. 6 hours ago, mhupp said: ... Also sorted your list by color number actually, this list is intentionally sorted by the layer name... many thanks again, aridzv. Quote Link to comment Share on other sites More sharing options...
aridzv Posted August 4, 2023 Author Share Posted August 4, 2023 @mhupp - I have a question about the "(vla-endundomark doc)". I see it in the lisp,and it raised an error,so I deleted it from the lisp and it work fine now. and there was no "(vla-StartUndoMark doc)".... what is the reason to use it? I've read this and this but couldn't figure out why it is needed in this lisp... thanks, aridzv Quote Link to comment Share on other sites More sharing options...
mhupp Posted August 4, 2023 Share Posted August 4, 2023 You didn't copy my complete code. Looking at your other post you need this in the start for it not to error. (defun c:PipeConvert_IRRI_UPDATE (/ Datalist ss f i ent eData) (vl-load-com) (vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object)))) Its always good practice to add undo marks if your doing a lot of different operations to a drawing. Say your ssget gets over 1000 lines it processes 723 of those 1000. that would take 1446 undo's one for each entity drawn and one for each line deleted. to return the drawing back to they way it was before the command was executed. You would basically have to hold Crtrl + Z for like 2-3 mins. Or just have the startundomark and endundomark and undo everything in one second. (if you wanted to) more here 1 Quote Link to comment Share on other sites More sharing options...
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.