ILoveMadoka Posted December 16, 2009 Share Posted December 16, 2009 (edited) I have a routine that changes text justification to Middle Center. It works fine if TEXT is selected. We cannot use MTEXT so if a piece of MTEXT is selected it explodes it. I don't know how to continue the routine after exploding other than reselecting the objects again. If someone could help me out I'd appreciate it. TIA!! Here's what I have... (defun C:JMC (/ ss1 sslen index ent1 enttyp bspt1) (prompt "\nSet to Middle Center Justification . . .") (setq ss1 (ssget)) (setq sslen (sslength ss1) index 0 tents 0 ) ; end setq (repeat sslen (setq ent1 (entget (ssname ss1 index)) enttyp (cdr (assoc 0 ent1)) ) ; end setq (if (= enttyp "MTEXT") (progn (Command "Explode" ss1) (alert "Text was MTEXT! Rerun the command. ") ;I put this note just to help notify me.. ;How do you select the text entities that made up the MTEXT group? ) ) (if (= enttyp "TEXT") (progn (setq bspt1 (cdr (assoc 10 ent1))) (setq ent1 (subst (cons 11 bspt1) (assoc 11 ent1) ent1)) (entmod ent1) (setq ent1 (subst (cons 72 1) (assoc 72 ent1) ent1)) (setq ent1 (subst (cons 73 2) (assoc 73 ent1) ent1)) (entmod ent1) (setq tents (+ tents 1)) ) ; end progn ) ; end if (setq index (+ index 1)) ) ; end repeat (princ) ) ; end defun Edited April 3, 2014 by rkmcswain added [CODE] tags Quote Link to comment Share on other sites More sharing options...
ILoveMadoka Posted December 16, 2009 Author Share Posted December 16, 2009 For some reason all my formatting was removed with my post.. Sorry about that! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 16, 2009 Share Posted December 16, 2009 Would this help you at all? http://www.cadtutor.net/forum/showthread.php?t=42438 Quote Link to comment Share on other sites More sharing options...
ILoveMadoka Posted December 16, 2009 Author Share Posted December 16, 2009 Lee... I've loooked at those routines before I'm hoping to use a few of them for other needs.. This little routine of mine is part of a larger set used when a user has created text incorrectly and I need to change it quickly. Really what I want is a routine that will not only converts MTEXT to TEXT but also changes the justification to MC and then centers that text in a box. I'm slowly pecking away at it. I have subroutines that eventually get it done but even then, there are a few bugs in my centering routine. Works fine some times, doesn't work at all sometimes. I cannot consistently recreate the error. Just getting past this little snag will streamline me quite a bit... I know it's easy, I'm just not a great programmer.. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 16, 2009 Share Posted December 16, 2009 Perhaps something along these lines? (defun C:JMC (/ i ss ent tmp elst) (prompt "\nSet to Middle Center Justification . . .") (if (setq i -1 ss (ssget "_:L" '((0 . "TEXT,MTEXT")))) (while (setq ent (ssname ss (setq i (1+ i)))) (if (eq "MTEXT" (cdr (assoc 0 (setq elst (entget ent))))) (progn (command "_.explode" ent) (setq ent (entlast)))) (setq tmp (cdr (assoc 10 elst))) (setq elst (entmod (subst (cons 11 tmp) (assoc 11 elst) eLst)) elst (entmod (subst (cons 72 1) (assoc 72 elst) elst)) elst (entmod (subst (cons 73 2) (assoc 73 elst) elst))))) (princ)) Quote Link to comment Share on other sites More sharing options...
alanjt Posted December 16, 2009 Share Posted December 16, 2009 Just so you know, JustifyText will allow the user to set the justification to whatever wanted, without moving the text. Quote Link to comment Share on other sites More sharing options...
ILoveMadoka Posted December 16, 2009 Author Share Posted December 16, 2009 Lee.. I ran this and it is making (or leaving) the text left justified. I tried it on existing mtext and create some new mtext with the same result. Maybe there was something weird in my original code?? Alan.. I knew that and have other "justification" routines as well. This is quicky app for a specific situation where I didn't want any options. I wanted it to do just the one thing. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 16, 2009 Share Posted December 16, 2009 Sorry, try this instead: (defun C:JMC (/ *error* ExEnts ELST ENT I LSTENT MSS OV SS TMP VL) (prompt "\nSet to Middle Center Justification . . .") (defun *error* (msg) (and ov (mapcar 'setvar vl ov)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ)) (defun ExEnts (ent / a) (if (setq ent (entnext ent)) (cons ent (ExEnts ent)))) (setq vl '("CMDECHO" "QAFLAGS") ov (mapcar 'getvar vl)) (mapcar 'setvar vl '(0 1)) (if (setq i -1 ss (ssget "_:L" '((0 . "TEXT,MTEXT")))) (progn (if (setq mss (ssget "_P" '((0 . "MTEXT")))) (progn (setq lstent (entlast)) (command "_.explode" mss "") (mapcar (function (lambda (x) (ssadd x ss))) (ExEnts (cond (lstent) ((entlast))))))) (while (setq ent (ssname ss (setq i (1+ i)))) (setq tmp (cdr (assoc 10 (setq elst (entget ent))))) (setq elst (entmod (subst (cons 11 tmp) (assoc 11 elst) eLst)) elst (entmod (subst (cons 72 1) (assoc 72 elst) elst)) elst (entmod (subst (cons 73 2) (assoc 73 elst) elst)))))) (mapcar 'setvar vl ov) (princ)) Quote Link to comment Share on other sites More sharing options...
ILoveMadoka Posted December 16, 2009 Author Share Posted December 16, 2009 I had to make one small change for it to work the way I wanted it to.. I added this line: elst (entmod (subst (cons 71 0) (assoc 73 elst) elst)) Thank you so much!! I would have never figured this out by myself!! Here's the entire routine... (defun C:JMC (/ *error* ExEnts ELST ENT I LSTENT MSS OV SS TMP VL) (prompt "\nSet to Middle Center Justification . . .") (defun *error* (msg) (and ov (mapcar 'setvar vl ov)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ)) (defun ExEnts (ent / a) (if (setq ent (entnext ent)) (cons ent (ExEnts ent)))) (setq vl '("CMDECHO" "QAFLAGS") ov (mapcar 'getvar vl)) (mapcar 'setvar vl '(0 1)) (if (setq i -1 ss (ssget "_:L" '((0 . "TEXT,MTEXT")))) (progn (if (setq mss (ssget "_P" '((0 . "MTEXT")))) (progn (setq lstent (entlast)) (command "_.explode" mss "") (mapcar (function (lambda (x) (ssadd x ss))) (ExEnts (cond (lstent) ((entlast))))))) (while (setq ent (ssname ss (setq i (1+ i)))) (setq tmp (cdr (assoc 10 (setq elst (entget ent))))) (setq elst (entmod (subst (cons 11 tmp) (assoc 11 elst) eLst)) elst (entmod (subst (cons 72 1) (assoc 72 elst) elst)) elst (entmod (subst (cons 73 2) (assoc 73 elst) elst)) elst (entmod (subst (cons 71 0) (assoc 73 elst) elst)) )))) (mapcar 'setvar vl ov) (princ)) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 16, 2009 Share Posted December 16, 2009 Thanks Madoka May I ask why you would want to mess with DXF 71? Quote Link to comment Share on other sites More sharing options...
ILoveMadoka Posted December 16, 2009 Author Share Posted December 16, 2009 Oops! Even though it worked it should have been this: elst (entmod (subst (cons 71 0) (assoc 71 elst) elst)) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 16, 2009 Share Posted December 16, 2009 Oops!Even though it worked it should have been this: elst (entmod (subst (cons 71 0) (assoc 71 elst) elst)) Gotcha .. Quote Link to comment Share on other sites More sharing options...
ILoveMadoka Posted December 16, 2009 Author Share Posted December 16, 2009 It still wasn't working for me until I added that. I pulled the entity data from left justified text and center justified text and that was one of the differences. Is my lack of knowledge showing??? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 16, 2009 Share Posted December 16, 2009 That's weird, DXF 71 just determines whether text is backward or upside-down... Quote Link to comment Share on other sites More sharing options...
alanjt Posted December 16, 2009 Share Posted December 16, 2009 Alan.. I knew that and have other "justification" routines as well. This is quicky app for a specific situation where I didn't want any options. I wanted it to do just the one thing. Right, but you can call it through Lisp (just as explode is called) and specify a specific justification. I was just offering that since you made it sound like you were new to programming. Quote Link to comment Share on other sites More sharing options...
ILoveMadoka Posted December 16, 2009 Author Share Posted December 16, 2009 Alan... Like Lee your opinions are highly regarded in my world. I didn't mean anything by "rejecting" your suggestion as it were. If it came across negatively in any way I apologize!! I get blinders on and want to fix what I'm trying to do without considering another option. My bad there.. Quote Link to comment Share on other sites More sharing options...
alanjt Posted December 16, 2009 Share Posted December 16, 2009 Alan...Like Lee your opinions are highly regarded in my world. I didn't mean anything by "rejecting" your suggestion as it were. If it came across negatively in any way I apologize!! I get blinders on and want to fix what I'm trying to do without considering another option. My bad there.. Oh, no harm done, never even interpreted it that way. I just wanted to make sure you were aware of that, as an option. Quote Link to comment Share on other sites More sharing options...
ILoveMadoka Posted December 16, 2009 Author Share Posted December 16, 2009 With the DXF 71 thing.. I'm working with drawings converted from Solidworks and text is coming in as blocks. I'm getting frustrated with it. I do have my proggie working. [THANK YOU!!!!] I don't know why, but the DXF 71 line made it work... Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted December 16, 2009 Share Posted December 16, 2009 With the DXF 71 thing..I'm working with drawings converted from Solidworks and text is coming in as blocks. I'm getting frustrated with it. I do have my proggie working. [THANK YOU!!!!] I don't know why, but the DXF 71 line made it work... Not a problem - whatever works! 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.