Jump to content

MTEXT -> TEXT Justification Tweak Request


ILoveMadoka

Recommended Posts

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 by rkmcswain
added [CODE] tags
Link to comment
Share on other sites

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..

Link to comment
Share on other sites

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))

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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))

Link to comment
Share on other sites

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))

Link to comment
Share on other sites

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???

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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! :)

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...