Finding center of text

Discussion in 'AutoCAD' started by JG, Sep 30, 2006.

  1. JG

    JG Guest

    Hello, I'm trying to write a lisp routine to rotate all
    selected text around it's center of location (so it doesn't
    move as when the insertion pt is used as with CHT )
    but I don't know how to find the data that shows the
    coordinates of the end pt of the text. It doesn't show
    in a list or object properties readout.
    Can someone give me a clue as to how to find this
    data info.
     
    JG, Sep 30, 2006
    #1
  2. JG

    Philippe Guest

    JG a écrit :
    Hello,

    Use the TEXTBOX lisp function...

    Philippe
     
    Philippe, Sep 30, 2006
    #2
  3. JG

    JG Guest

    Part of the solution might be to use use Express tools "justify text" to
    Ah yes I had already tried that but the cht rotation "always"
    centers it's rotation on the insertion point no matter where the
    text is justified.
     
    JG, Oct 1, 2006
    #3
  4. JG

    JG Guest

    Hello, Use the TEXTBOX lisp function...

    Thanks for the reply, but I don't know of any TEXTBOX
    lisp function. Is it downloadable somewhere?
    We are running AutoCad R-14 with Civil Design Softdesk8.
    We do have Bonus Tools but when I type in TEXTBOX
    I get "unknown command" .
     
    JG, Oct 1, 2006
    #4
  5. JG

    Guest Guest

    In the Help files for R14 (text, bounding box, AutoLISP) there is a
    lisp routine for drawing a box around text:

    (defun C:TBOX ( / textent tb ll ur ul lr)
    (setq textent (car (entsel "\nSelect text: ")))
    (command "ucs" "Object" textent)
    (setq tb (textbox (list (cons -1 textent)))
    ll (car tb)
    ur (cadr tb)
    ul (list (car ll) (cadr ur))
    lr (list (car ur) (cadr ll))
    )
    (command "pline" ll lr ur ul "Close")
    (command "ucs" "p")
    (princ)

    )

    Use that; draw the diagonal and rotate the text around the midpoint of
    the diagonal.

    There might be other ways...

    Brian.
     
    Guest, Oct 1, 2006
    #5
  6. JG

    JG Guest

    Thank you!
    This will do it I'm sure, just some trig from here.
     
    JG, Oct 1, 2006
    #6
  7. JG

    Jiro Guest

    HiHo;
    Here is a R14 lisp program and DCL.
    Hope this helps.
    .............................................................................
    .................
    SAVE BELOW as jrRoText.lsp
    .............................................................................
    ..................
    ;;;jrRoText
    ;;; A general text rotater
    ;;; Rotates text about the midpoint
    ;;; of selected text.
    ;;;========================================================

    (defun *error* (msg)
    (Alert msg)
    (princ)
    );end defun error

    ;==========================================================
    ; Set and Save System Variables
    ; REMBEMBER to edit the vlist list
    ;==========================================================
    (Defun pushvars ( )
    (setq vlist
    '(("cmdecho" . 0)
    ("osmode" . 0)
    ("OSNAPCOORD" . 1)
    ("PICKFIRST" . 1)
    ("AUNITS" . 0)
    ("ANGBASE" . 0)
    ("ANGDIR" . 0)
    )
    );end setq

    (ForEach pair vlist
    (Setq name (Strcase (CAR pair) T))
    (If (Not (Assoc name sysvars))
    (Setq
    sysvars (Cons (Cons name (GetVar name)) sysvars)
    )
    )
    (If (CDR pair)
    (Setvar name (CDR pair))
    )
    );end foreach
    );end pushvars

    ;==========================================================
    ; Restore System Variables
    ;==========================================================
    (Defun popvars ( )
    (ForEach pair sysvars
    (Setvar (CAR pair) (CDR pair))
    )
    (Setq *error* old_error)
    (Setq sysvars Nil)
    );end popvars

    ;=========================================================
    ;;;Start Subs
    ;==========================================================

    (defun jrotext ( )
    (setq DCL_ID (load_dialog "jrRoText.dcl"))
    (if (not (new_dialog "jrRoText" DCL_ID)) (exit))
    (action_tile "AngEnt" "(setq ang_in (atof $value))")
    (start_dialog)
    (unload_dialog DCL_ID)


    (setq hr (fix ang_in)
    mm (fix (* 100 (- ang_in hr)))
    ss (fix (- (* 10000 ang_in) (+ (* 10000 hr) (* 100 mm))))
    ang_out (+ hr (/ mm 60.0) (/ ss 3600.0))
    );setq

    (PRINC "\nSELECT TEXT TO ROTATE")
    (SETQ SS1 (SSGET '((0 . "TEXT")))
    len 0
    );end setq
    (WHILE (> (sslength ss1)len)
    (setq enam (SSNAME SS1 len))
    (get_middle)
    (command "ROTATE" enam "" middle ang_out)
    (setq len (1+ len))
    );end while

    );end jrotext
    ;==========================================================
    ; Middle point of text entity
    ;==========================================================

    (Defun get_middle ()
    (Command ".ucs" "e" enam)
    (Setq
    middle (Trans
    (Apply
    'xer_midpoint
    (TextBox (EntGet enam))
    )
    1
    0
    )
    )
    (Command ".ucs" "p")
    (Setq middle (Trans middle 0 1))
    );end get_middle

    ;===========================================================
    ; Midpoint between p1 and p2
    ;==========================================================
    (Defun xer_midpoint (p1 p2)
    (MapCar
    '(Lambda (x1 x2) (* 0.5 (+ x1 x2)))
    p1
    p2
    )
    );end xer_midpoint

    ;==========================================================
    ;;;End Subs
    ;==========================================================
    ;;;Start of main program
    ;==========================================================
    (defun c:grt (/ SumVars Stuff)
    (setq old_error *error*)
    (pushvars)
    ;;; The rest of the program goes here
    (jrotext)


    ;==========================================================
    (popvars)
    (princ)
    );end c:grt
    (prompt "\Enter grt to run")
    .............................................................................
    ..
    .............................................................................
    SAVE BELOW as jrRoText.dcl
    .............................................................................
    // jrRoText DCL
    // Use for comments
    // use ; for end of field

    jrRoText : dialog { // begin dialog definition
    label = "Rotate Text";

    :edit_box {
    label = "Enter Rotatation Angle DD.MMSS";
    key = "AngEnt";
    edit_width = 10;
    value = "0";
    }




    errtile;
    ok_cancel;

    }
     
    Jiro, Oct 1, 2006
    #7
  8. JG

    JG Guest

    Thank you! I will try this as soon as I get home.
    Also I wonder if you could help me with my outdated
    version of VLisp. I'm running the R-14 Version of Cad
    and Vlisp which I just installed. However when I try to
    Debug a file all of my
    Step Into
    Step Over
    Step Out
    are grayed out ?
    I have the breakpoint set at the first function
    I have the lsp file loaded and open
    I've also tried creating a project but the step functions
    seem hopeless grayed off. Do you know what I am
    doing wrong ??
     
    JG, Oct 1, 2006
    #8
  9. JG

    JG Guest

    Well I figured it out. You have to set the breakpoint
    "before" you load the file. Seems like "load" should
    have been "run" to me, but whatever.
     
    JG, Oct 1, 2006
    #9
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.