Author Topic: change dtext justifcation - keep location  (Read 2262 times)

0 Members and 1 Guest are viewing this topic.

curmudgeon

  • Newt
  • Posts: 194
change dtext justifcation - keep location
« on: April 15, 2009, 11:25:06 AM »
what I was trying, and which failed was

Code: [Select]
(setq it (subst (assoc 72 txt) (assoc 72 it) it)
      it (subst (assoc 73 txt) (assoc 73 it) it)
      it (subst (cons 11 (cdr (assoc 10 it))) (assoc 11 it) it)
      )

(entmod it)

I grabbed a piece of text whose justification as bottom left, and one which I created as middle center.
the first I setq'd as it, and the second as txt.

entupd was tried as well. no joy.

I searched here and found a routine with some vl commands which ran, but the text moved when I ran it.
I don't groc the vl commands yet.

something is telling me I have succeeded with a similar task in the past, but I cannot find my own code, and I begin to doubt my memory. I have a couple hundred text entities I can select programatically very easily, but the would be far more useful to me if they were middle center justified. and this is the first of several files that need "tweeking".

thanks.

roy

Never express yourself more clearly than you are able to think.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: change dtext justifcation - keep location
« Reply #1 on: April 15, 2009, 03:06:13 PM »
This works for me.  Just change the alignment part to yours, and all should be good.

Code: [Select]
(defun c:Test ( / Sel Entdata oInsPt Obj InsPt TxAliPt Ang Dist)
   
    (setq Sel (entsel "\n Select text: "))
    (setq EntData (entget (car Sel)))
    (setq oInsPt (cdr (assoc 10 EntData)))
    (setq Obj (vlax-ename->vla-object (car Sel)))

    [color=red](vla-put-Alignment Obj (1+ (vla-get-Alignment Obj)))[/color]

    (entupd (car Sel))
    (setq EntData (entget (car Sel)))
    (setq InsPt (cdr (assoc 10 EntData))
        TxAliPt (cdr (assoc 11 EntData))
    )
    (setq Ang (angle InsPt oInsPt)
        Dist (distance InsPt oInsPt)
    )
    (setq EntData
        (subst
            (cons
                10
                (polar InsPt Ang Dist)
            )
            (assoc 10 EntData)
            EntData
        )
    )
    (entmod
        (subst
            (cons
                11
                (polar TxAliPt Ang Dist)
            )
            (assoc 11 EntData)
            EntData
        )
    )
    (entupd (car Sel))
    (princ)
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

curmudgeon

  • Newt
  • Posts: 194
Re: change dtext justifcation - keep location
« Reply #2 on: April 15, 2009, 04:41:46 PM »
 8-)

the lisp I understand, the vl commands I will study.
hey! I just got dear old Autocad to write to a gbXML formatted file for a building with almost 200 rooms, hexagonal rooms, interior courts - much stuff.

twas this project that made me look for all the help I could get, and why I ended up here.

ran enough write-line commands to produce an ascii file 1251 KB. and it feels good.
thanks guys. you've all been a great help. but I need to rest my old eyes now.

roy
Never express yourself more clearly than you are able to think.

hermanm

  • Guest
Re: change dtext justifcation - keep location
« Reply #3 on: April 15, 2009, 06:20:24 PM »
If you would like a free pre-packaged routine with a GUI, you are welcome to download Textjust.setup.zip from the AutopLISP utilities page at: www.tktn.com

Just unzip & run setup. It uses a modeless ODCL dialog.

Here is the align-text function from that package:

Code: [Select]
;;align-text
;;works for TEXT & ATTDEFs
(defun align_text (obj align keep-pos / inspt inspt2 alignpt disp var2list)
  (defun var2list ( var / )
    (vlax-safearray->list (vlax-variant-value var))
  );var2list
  (if (equal (type obj) 'ENAME )
   (setq obj (vlax-ename->vla-object obj)))
  (cond ((null keep-pos);;text will move when alignment changes
          (cond ((and (= align 0) (= 0 (vla-get-alignment obj)))
                  nil);must include this case!
                ((= 0 (vla-get-alignment obj));is left justified
                  (setq inspt (vla-get-insertionpoint obj))
                  (vla-put-alignment obj align)
                  (vla-put-textalignmentpoint obj inspt))
                ((= align 0);change to left justified
                  (setq alignpt (vla-get-textalignmentpoint obj))
                  (vla-put-alignment obj align)
                  (vla-put-insertionpoint obj alignpt))
                  (1 (vla-put-alignment obj align));all other cases
        ));null keep-pos
        ((eq keep-pos T);;text will not move when alignment changes
          (cond ((= align 0);change to left justified
                  (vla-put-alignment obj align))
                (1          ;all other cases
                    (setq inspt (var2list(vla-get-insertionpoint obj)))
                    (vla-put-alignment obj align)
                    (setq inspt2 (var2list(vla-get-insertionpoint obj))
                          disp (mapcar '- inspt inspt2)
                          alignpt (var2list (vla-get-textalignmentpoint obj))
                          alignpt (vlax-3d-point(mapcar '+ alignpt disp)))
                    (vla-put-textalignmentpoint obj alignpt))
        ));keep-pos
  );cond
);align_text



T.Willey

  • Needs a day job
  • Posts: 5251
Re: change dtext justifcation - keep location
« Reply #4 on: April 15, 2009, 06:27:05 PM »
Just an FYI Herman...

You can use the same idea you used with your help to get dynamic properties with the points.  vlax-get.. Will return a true point list, and you can use vlax-put.... with a true point list.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

hermanm

  • Guest
Re: change dtext justifcation - keep location
« Reply #5 on: April 15, 2009, 07:35:16 PM »
Thx, Tim.:)

Good pointer for anyone else reading, as well.

As you may guess, I just cut & pasted from what I had written (July 2007).

T.Willey

  • Needs a day job
  • Posts: 5251
Re: change dtext justifcation - keep location
« Reply #6 on: April 15, 2009, 07:42:43 PM »
Thx, Tim.:)

Good pointer for anyone else reading, as well.

As you may guess, I just cut & pasted from what I had written (July 2007).

I figured.  It was more to point it out to others who might come along later.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.