Happy Hobbit Posted August 27, 2015 Share Posted August 27, 2015 I wonder if this is even possible? I'd like to crate an if statement to go inside an existing lisp that makes a decision based on entity type. Something along the lines of: (if (equal (0 . "text")) (WRITE: DEBURR ALL EDGES & CORNERS) (if ((equal (0 . "mtext")) (WRITE: DEBURR ALL\\P EDGES & CORNERS) )) ) The lisp I wish to insert it into is this: (defun C:TRDB ;Text Replace for Complete text/mtext strings to "DEBURR ALL EDGES & CORNERS" (/ tss tdata) (setq tss (ssget (list (cons 1 "*")))) (repeat (sslength tss) (setq tdata (entget (ssname tss 0)) tdata (subst (cons 1 "DEBURR ALL EDGES & CORNERS") (assoc 1 tdata) tdata) ); end setq (entmod tdata) (ssdel (ssname tss 0) tss) ); end repeat ) The difference is the addition of \\p into the mtext option Thanking you in anticipation - Harry Quote Link to comment Share on other sites More sharing options...
satishrajdev Posted August 27, 2015 Share Posted August 27, 2015 (edited) Hi Harry I didn't understand you post clearly.... but i have given a try for what i understood (defun C:TRDB (/ tss tdata i) (if (setq tss (ssget '(0 . "TEXT,MTEXT"))) [color="red"];set filter list as per your requirement[/color] (repeat (setq i (sslength tss)) (setq tdata (entget (ssname tss (setq i (1- i))))) (entmod (subst (cons 1 (cond ((equal (cdr (assoc 0 tdata)) "TEXT") (strcat "DEBURR ALL EDGES & CORNERS") ) ((equal (cdr (assoc 0 tdata)) "MTEXT") (strcat "DEBURR ALL\\P EDGES & CORNERS") ) ) ) (assoc 1 tdata) tdata ) ;end subst ) ;end entmod ) ;end repeat ) ;end if (princ) ) Edited August 28, 2015 by satishrajdev Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 27, 2015 Share Posted August 27, 2015 Hint: (cons 1 "*") is equal to nothing with or without Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 27, 2015 Share Posted August 27, 2015 (edited) A little more concise: (defun c:trdb ( / e i s ) (if (setq s (ssget '((0 . "TEXT,MTEXT")))) (repeat (setq i (sslength s)) (setq e (entget (ssname s (setq i (1- i))))) (entmod (subst (cons 1 (if (= "TEXT" (cdr (assoc 0 e))) "DEBURR ALL EDGES & CORNERS" "DEBURR ALL\\P EDGES & CORNERS")) (assoc 1 e) e ) ) ) ) (princ) ) Edited August 27, 2015 by Lee Mac Quote Link to comment Share on other sites More sharing options...
Happy Hobbit Posted August 27, 2015 Author Share Posted August 27, 2015 Hello Satishrajdev You obviously understood well enough to do a perfect reply Thank you for your code, it's very good. I'd never have got: (equal (cdr (assoc 0 tdata)) "TEXT") Any chance of explaining it to me? I can see that it's a cond(itional) statement checking if the entity is equal to "TEXT" but I don't really understand: (cdr (assoc 0 tdata)) - Harry Quote Link to comment Share on other sites More sharing options...
Happy Hobbit Posted August 27, 2015 Author Share Posted August 27, 2015 Satishrajdev, if multiple entities are selected I get: ; error: bad argument type: lselsetp nil Using Debug it's on line: (repeat (sslength tss) Lee, with your lisp I get DEBURR ALL\P EDGES & CORNERS on text items (one back slash), although it works perfectly on mtext Am I doing something wrong? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 27, 2015 Share Posted August 27, 2015 Satishrajdev, if multiple entities are selected I get: ; error: bad argument type: lselsetp nil (repeat (sslength tss) Recently being asked HERE Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 27, 2015 Share Posted August 27, 2015 Lee, with your lisp I get DEBURR ALL\P EDGES & CORNERS on text items (one back slash), although it works perfectly on mtext Am I doing something wrong? Apologies - I had referenced variable 'e' before it was defined - I have now corrected the above code. Quote Link to comment Share on other sites More sharing options...
Happy Hobbit Posted August 27, 2015 Author Share Posted August 27, 2015 That's spot on Lee I must admit I was convinced it was my mistake, I've never known a bug in you code before, although I bet you have... Sometimes debugging drives me nuts Thank you - Harry Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 27, 2015 Share Posted August 27, 2015 That's spot on Lee I must admit I was convinced it was my mistake, I've never known a bug in you code before, although I bet you have... Sometimes debugging drives me nuts Thank you - Harry You're most welcome Harry. I should probably avoid typing the code straight into the forum post box without testing anything (Blind Coding) Lee Quote Link to comment Share on other sites More sharing options...
BIGAL Posted August 28, 2015 Share Posted August 28, 2015 (assoc 0 "text") The 0 is the dxf code which in this case is equal to the object type.some examples 10 is start point 11 end 8 is layer name 40 is height note these numbers can have different meaning depending on the object. google dxf codes Quote Link to comment Share on other sites More sharing options...
satishrajdev Posted August 28, 2015 Share Posted August 28, 2015 Satishrajdev, if multiple entities are selected I get: ; error: bad argument type: lselsetp nil Using Debug it's on line: (repeat (sslength tss) Sorry, I was in hurry while leaving the office so didnt check the code properly... I have updated my code. Any chance of explaining it to me? - Harry DXF Code 0 shows which kind of entity it is... You can extract object type from Code 0 You can learn about DXf codes here http://docs.autodesk.com/ACD/2011/ENU/filesDXF/WSfacf1429558a55de185c428100849a0ab7-5df0.htm Quote Link to comment Share on other sites More sharing options...
Happy Hobbit Posted August 28, 2015 Author Share Posted August 28, 2015 The 0 is the dxf code which in this case is equal to the object type.some examples 10 is start point 11 end 8 is layer name 40 is height note these numbers can have different meaning depending on the object. google dxf codes I see now ! Thanks for that Bigal & Satishrajdev Quote Link to comment Share on other sites More sharing options...
satishrajdev Posted August 28, 2015 Share Posted August 28, 2015 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.