SWfangirl Posted April 20, 2011 Share Posted April 20, 2011 I need some help. I have a drawing that has 2000+ utility poles in it. All of the poles are labed numerically using mtext. Is there a way to select just the odd values and delete them? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 20, 2011 Share Posted April 20, 2011 Welcome to CADTutor SWfangirl Perhaps try something like this: (defun c:DelOdd ( / ss i e ) (if (setq ss (ssget "_X" '((0 . "MTEXT") (8 . "[color=red]YourLayerHere[/color]")))) (repeat (setq i (sslength ss)) (setq e (ssname ss (setq i (1- i)))) (if (= 1 (logand 1 (atoi (cdr (assoc 1 (entget e)))))) (entdel e)) ) ) (princ) ) The above assumes the labels are integers and that the MText is unformatted and its string just contains a number and no other text. I have also added a layer filter to the Selection to only select MText on a certain layer, change the layer name (marked in red) to your MText Layer, or remove the (8 . "XX") part to select all MText. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 20, 2011 Share Posted April 20, 2011 Or this might be better: (defun c:DelOdd ( / ss i e ) (if (setq ss (ssget "_X" '((0 . "MTEXT")))) (repeat (setq i (sslength ss)) (setq e (ssname ss (setq i (1- i)))) (if (zerop (logand 1 (atoi (cdr (assoc 1 (entget e)))))) (ssdel e ss)) ) ) (sssetfirst nil ss) (princ) ) Will just select the 'Odd' MText so that you can delete them yourself. Quote Link to comment Share on other sites More sharing options...
SWfangirl Posted April 20, 2011 Author Share Posted April 20, 2011 The second one is PERFECT! Thank You so much! If no one else has told you yet.........YOU ROCK!! Quote Link to comment Share on other sites More sharing options...
David Bethel Posted April 20, 2011 Share Posted April 20, 2011 Are you trying to delete just the mtext label or is there some geometry ( ie circle ) that need to removed as well? That could be much more complicated. -David Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 20, 2011 Share Posted April 20, 2011 Thanks SWfangirl Enjoy! Quote Link to comment Share on other sites More sharing options...
SWfangirl Posted April 20, 2011 Author Share Posted April 20, 2011 Just the Mtext label. Picking one by one is bothersome. Quote Link to comment Share on other sites More sharing options...
alanjt Posted April 21, 2011 Share Posted April 21, 2011 (logand 1 Nicely done. Quote Link to comment Share on other sites More sharing options...
David Bethel Posted April 21, 2011 Share Posted April 21, 2011 And then there is always (= (rem i 2) 1) for positive integers Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 21, 2011 Share Posted April 21, 2011 Cheers guys Quote Link to comment Share on other sites More sharing options...
SWfangirl Posted April 28, 2011 Author Share Posted April 28, 2011 David- I am super new to writing code. How do you work (= (rem i 2) 1) into the lisp? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 28, 2011 Share Posted April 28, 2011 How do you work (= (rem i 2) 1) into the lisp? An example using my previous code: (defun c:DelOdd ( / ss i e ) (if (setq ss (ssget "_X" '((0 . "MTEXT")))) (repeat (setq i (sslength ss)) (setq e (ssname ss (setq i (1- i)))) (if (zerop (rem (abs (atoi (cdr (assoc 1 (entget e))))) 2)) (ssdel e ss)) ) ) (sssetfirst nil ss) (princ) ) Quote Link to comment Share on other sites More sharing options...
David Bethel Posted April 29, 2011 Share Posted April 29, 2011 (edited) Or maybe a bit more elementary: [b][color=BLACK]([/color][/b]defun c:doddtxt [b][color=FUCHSIA]([/color][/b]/ ss en ed tv ti[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget [color=#2f4f4f]"X"[/color] '[b][color=GREEN]([/color][/b][b][color=BLUE]([/color][/b]0 . [color=#2f4f4f]"*TEXT"[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [color=#8b4513];;;CREATE A PICKSET OF ALL TEXT ENTITIES[/color] [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss 0[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [color=#8b4513];;;WHILE THERE IS AN ENTITY NAME LEFT IN THE SET, GET THE FIRST ENAME[/color] [b][color=MAROON]([/color][/b]setq ed [b][color=GREEN]([/color][/b]entget en[b][color=GREEN])[/color][/b] [color=#8b4513];;;GET ENTITY DEFINTION[/color] tv [b][color=GREEN]([/color][/b]cdr [b][color=BLUE]([/color][/b]assoc 1 ed[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [color=#8b4513];;;GET THE ENTITY TEXT VALUE[/color] ti [b][color=GREEN]([/color][/b]atoi tv[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [color=#8b4513];;;CONVERT THE TEXT VALUE TO AN INTEGER[/color] [b][color=MAROON]([/color][/b]if [b][color=GREEN]([/color][/b]/= [b][color=BLUE]([/color][/b]rem ti 2[b][color=BLUE])[/color][/b] 0[b][color=GREEN])[/color][/b] [color=#8b4513];;;IF THE INTEGER IS NOT EVENLY DIVISIBLE BY 2 ( NOT EVEN )[/color] [b][color=GREEN]([/color][/b]entdel en[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [color=#8b4513];;;DELETE ENTITY[/color] [b][color=MAROON]([/color][/b]ssdel en ss[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [color=#8b4513];;;REMOVE THE ENAME FROM THE PICKSET[/color] [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] -David Edited April 29, 2011 by David Bethel Quote Link to comment Share on other sites More sharing options...
SWfangirl Posted April 29, 2011 Author Share Posted April 29, 2011 (edited) Thank you David, It really helps seeing what the code means. It is much easier to grasp this way. Trying to learn lisp is exciting and aggravating all at the same time. Edited April 29, 2011 by SWfangirl Fixed spelling error Quote Link to comment Share on other sites More sharing options...
David Bethel Posted April 29, 2011 Share Posted April 29, 2011 You're welcome. Sometimes we get a bit advanced for a beginner and forget how we learned best way back when. -David 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.