Fit justify mtext?

Discussion in 'AutoCAD' started by MiD-AwE, Mar 11, 2005.

  1. MiD-AwE

    MiD-AwE Guest

    Hey all,
    I'm trying to set up this scenario: From a menu (or LISP if necessary) the user selects a particular label and immediately is prompted to select the first point, after which they have the second (right side) grip of a fit justified single or multiline text object. This text needs to be set in code without user interaction so that the entire process is reduced to two mouse clicks and the text needs to be viewable before the second mouse click so that the user can see if the text is stretched too much.
    I've tried many methods all of which fail to allow the user to view the stretching text before the second and final mouse click.
    I was thinking of setting the string data (so that I could send either one line or several lines of text to the text command later with a foreach statement then capturing the first click into a variable. Then, beginning the text command where I could with the justify fit settings and the first point already acquired. The part I really am lost over is the tracking of the cursor and getting the second point to finalize the function. Any suggestions are greatly appreciated?
     
    MiD-AwE, Mar 11, 2005
    #1
  2. you can use grread to track the cursor.
    So boiled down, you want:
    1) pick mtext
    2) pick left side coordinate
    3) pick right side point after watching text stretch to correct width

    I assume the Y coord stays the same for the mtext ins point.
    This is interesting because you need to programmatically select the grip on the right and enter into the stretch
    command.

    So if anyone can tell us how to select a particular grip of an object and enter into the stretch command, we are set.


    MiD-AwE <>
    |>Hey all,
    |>I'm trying to set up this scenario: From a menu (or LISP if necessary) the user selects a particular label and immediately is prompted to select the first point, after which they have the second (right side) grip of a fit justified single or multiline text object. This text needs to be set in code without user interaction so that the entire process is reduced to two mouse clicks and the text needs to be viewable before the second mouse click so that the user can see if the text is stretched too much.
    |>I've tried many methods all of which fail to allow the user to view the stretching text before the second and final mouse click.
    |>I was thinking of setting the string data (so that I could send either one line or several lines of text to the text command later with a foreach statement then capturing the first click into a variable. Then, beginning the text command where I could with the justify fit settings and the first point already acquired. The part I really am lost over is the tracking of the cursor and getting the second point to finalize the function. Any suggestions are greatly appreciated?

    James Maeding
    jmaeding at hunsaker dot com
    Civil Engineer/Programmer
     
    James Maeding, Mar 12, 2005
    #2
  3. MiD-AwE

    MiD-AwE Guest

    Maybe it would make more sense to predefine the second insert point?

    I believe that it is possible to re-select the first point after the text object has been created, and the user would simply stretch the text from right to left. Setting the "OSNAP" "INS"- it could be as easy as that.
     
    MiD-AwE, Mar 12, 2005
    #3
  4. Try this for a start. You'll need to add processing for exiting the
    stretching, or just key escape when properly stretched.

    (defun c:ss (/ pp th txt en)
    (setq pp (getpoint "Select start point: ")
    th 2.25
    txt "This is the text"
    )
    (command "text" "Justify" "Fit" pp "@12<0" th txt)
    (setq en (entget (entlast)))
    (while (setq pp (cadr (grread t)))
    (echg en 11 pp)
    )
    )


    (defun ECHG (ent fld val)
    (setq ent (subst (cons fld val) (assoc fld ent) ent))
    (entmod ent)
    )
     
    Allen Johnson, Mar 14, 2005
    #4
  5. MiD-AwE

    MiD-AwE Guest

    It works beautifully.
    I found that I'm unable to use ortho with this and the text never enters. Hmm? I'm well pleased with getting this far with it. For some reason the only text that shows is "2.250000000000000".I believe that it is a result of this: "@12<0" th txt)
    Thanks for your help.
     
    MiD-AwE, Mar 15, 2005
    #5
  6. The reason you get "2.2500000" as text is that your textheight is fixed,
    whereas the routine assumes that the style textheight is variable.

    You should be able to fix by substituting this for the (command ....)

    (if (= 0 (field 40 (tblsearch "STYLE" (getvar "TEXTSTYLE"))))
    (command "text" "Justify" "Fit" pp "@12<0" th txt)
    (command "text" "Justify" "Fit" pp "@12<0" txt)
    )

    As to the orthomode, you'll need to write code to check to see if the
    orthomode is on, then constrain the pickpoint (pp) coordinates to X and Y
    changes only.
     
    Allen Johnson, Mar 15, 2005
    #6
  7. Oops, forgot the definition for the field function:

    (defun FIELD (val ent) (cdr (assoc val ent)))
     
    Allen Johnson, Mar 15, 2005
    #7
  8. Try this for orthomode checking:

    (defun c:ss (/ bp pp th txt en flag)
    (setq pp (getpoint "Select start point: ")
    th 2.25
    txt "This is the text"
    )
    (if (= 0 (field 40 (tblsearch "STYLE" (getvar "TEXTSTYLE"))))
    (command "text" "Justify" "Fit" pp "@12<0" th txt)
    (command "text" "Justify" "Fit" pp "@12<0" txt)
    )
    (setq en (entget (entlast))
    bp (field 10 en)
    )
    (while (setq pp (grread t))
    (if (= (car pp) 5)(echg en 11 (orthocheck bp (cadr pp))))
    )
    )

    (defun orthocheck (bp pp / an )
    (if (= (getvar "orthomode") 0)
    pp ;; ortho mode off, return pp unchanged
    (progn
    (setq an (rtd (angle bp pp)))
    (if (or (> an 315) (< an 45) (< 135 an 225))
    (list (car pp) (cadr bp))
    (list (car bp) (cadr pp))
    )
    )
    )
    )

    (defun ECHG (ent fld val)
    (setq ent (subst (cons fld val) (assoc fld ent) ent))
    (entmod ent)
    )

    (defun FIELD (val ent) (cdr (assoc val ent)))

    (defun RTD (a) ;Radians to degrees conversion
    (* 180.0 (/ a pi)))
     
    Allen Johnson, Mar 15, 2005
    #8
  9. MiD-AwE

    MiD-AwE Guest

    Thank you,

    Do you know how I can get the multiple lines of text to work with this. I tried this combination that only moves text to a new line but it doesn't carriage return:

    (setq pp (getpoint "Select start point : ")
    txt (strcat "Covered" "\n" "Patio")
    )
     
    MiD-AwE, Mar 15, 2005
    #9
  10. Do the (command ...) for each line, then get both of the entity lists and
    modify each with the new coordinates.
     
    Allen Johnson, Mar 15, 2005
    #10
  11. MiD-AwE

    MiD-AwE Guest

    This will work for exiting:

    instead of -
    Code:
    (while (setq pp (cadr (grread t)))
    just use this -
    Code:
    (prompt "\nSelect end point: ")
    (while (/= (car (setq pp (grread 't 1 0))) 3)
     
    MiD-AwE, Mar 17, 2005
    #11
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.