Custom Dtext Routine Help

Discussion in 'AutoCAD' started by akdrafter, Feb 29, 2004.

  1. akdrafter

    akdrafter Guest

    Hello All,

    Specs: Acad 2002 & WinXP Pro

    I have written a customized DTEXT routine to set up all of the variables of the dtext so that the user does not have to. Items like: full text style info, layer, dimscale, text height, justification, etc... I have added many other items to the routine. See the code. The code I have pasted into this message is the DTEXT justified to the Bottom Left. I have one massive routine that does all of the justifications, but I have only posted this part of the routine as it is the one that I would like to change.

    When you run this routine it does everything prefectly. However if you enter more than one line of dtext it uses the first line of dtext as it's start point. Which is correct. What I want to do is to be able to have the routine recognize that the user has started another line and move all previous lines up one line. I have read some posts on what that line spacing is. As best as I can tell it is 1.62. I do not want to use mtext as I do not like using mtext for what I plan on using this type of text routine for. I generally only enter 1 line, but sometimes I enter 2 or 3 lines of dtext and there lies the problem of using bottom left justification. The justification problem would be the same for bottom right.

    So, can anyone lead me in the right direction to solving this one? Thanks in advance.

    "Catch" Ya Later,
    AKDRAFTER

    ;; TBL.lsp
    ;;
    ;; By Timothy J. Jaronik Sr.
    ;; February, 2004
    ;;
    ;; A routine to create Dtext with a justification of bottom left and moved 3/16" to the east (0 angle) of the user picked point
    ;;
    ;;;;;;;;;;;;;;;BEGIN ERROR HANDLING FUNCTION;;;;;;;;;;;;;;;
    ;;
    (defun ERRTRAP (msg)
    (princ "\n Error: ")
    (if msg (princ msg))
    (setvar "CLAYER" CLA)
    (setvar "CMDECHO" CME)
    (setvar "OSMODE" OSM)
    (setvar "ORTHOMODE" OTHM)
    (setvar "SNAPMODE" SNM)
    (setvar "TEXTSTYLE" TSTYLE)
    (setq *ERROR* OLDERR)
    (prompt "\n Resetting System Variables... ")
    (princ)
    )
    ;;
    ;;;;;;;;;;;;;;;END ERROR HANDLING FUNCTION;;;;;;;;;;;;;;;
    ;;
    (defun C:TBL ( / OLDERR *ERROR* CLA CME OSM OTHM SNM TSTYLE DIMSC MD SP1 SP2); begin defun
    (setq OLDERR *ERROR*); store current error trap
    (setq *ERROR* ERRTRAP); change current error trap to the new error trap
    (setq CLA(getvar "CLAYER")); store current layer
    (setq CME(getvar "CMDECHO")); store current command echo state
    (setvar "CMDECHO" 0); turn command echoing off
    (setq OSM(getvar "OSMODE")); store the current osnap mode
    (setvar "OSMODE" 0); turn osnap off
    (setq OTHM(getvar "ORTHOMODE")); store the current orthomode
    (setvar "ORTHOMODE" 0); turn ortho off
    (setq SNM(getvar "SNAPMODE")); store current snap
    (setvar "SNAPMODE" 0); turn snap off
    (setq TSTYLE(getvar "TEXTSTYLE")); store current text style
    (setq DIMSC(getvar "DIMSCALE")); retrieve current dimscale
    (setq MD(* DIMSC 0.18750000)); move distance 3/16" multiplied by the current dimscale
    (command "-layer" "thaw" "TEXT" "on" "TEXT" "make" "TEXT" "color" "4" "TEXT" "lt" "continuous" "TEXT" ""); thaw, turn on, if it is already defined, it will be redefined
    (command "-style" "ROMANS" "ROMANS.shx" "0.00000000" "1.00000000" "0.00000000" "N" "N" "N"); create ROMANS text style, if it is already defined, it will be redefined
    (setq SP1(getpoint "\n Pick the BOTTOM LEFT point: ")); prompt user for start point of DTEXT
    (setq SP2(list (+ (car SP1) MD) (- (cadr SP1) 0.0))); redefine start point 0.18750000 in the east (0 angle) direction
    (command "._dtext" "_J" "_BL" SP2 (* DIMSC 0.09375000) "0.00000000"); start DTEXT command with all DTEXT variables
    (setq *ERROR* OLDERR); restore original error trap
    (setvar "CLAYER" CLA); return original layer
    (setvar "CMDECHO" CME); restore original command echo state
    (setvar "OSMODE" OSM); restore original osnap mode
    (setvar "ORTHOMODE" OTHM); restore original ortho mode
    (setvar "SNAPMODE" SNM); restore original snap mode
    (setvar "TEXTSTYLE" TSTYLE); restore original text style
    (princ); finish clean
    ); end defun
     
    akdrafter, Feb 29, 2004
    #1
  2. akdrafter

    R.K. McSwain Guest

    As best as I can tell it is 1.62.

    I think is varies slightly depending on the font, but it's closer to 1.71
     
    R.K. McSwain, Mar 1, 2004
    #2
  3. (defun txtlinespcg (e)

    ;; Extract the height of the linefeed from the abs value of the
    +--+ 2nd point
    ;; y coordinate of the first point in the textbox function. "1\n1" =
    __ |1 |___ text baseline
    ;; Use the string "1\n1" where \n means a linefeed character
    __ | 1|___ linefeed height
    ;; (use the "1" character each side so that it can figure out 1st point
    +--+
    ;; the height of the linefeed...)

    (abs (cadar (textbox
    (list (cons 0 "TEXT")
    (assoc 7 e)
    (assoc 40 e)
    (assoc 10 e)
    (cons 1 "1\n1")
    )
    )
    )
    )
    )
     
    Allen Johnson, Mar 1, 2004
    #3
  4. akdrafter

    akdrafter Guest

    Allen,

    I am not sure how to use what you posted. I kinda understand how it works, but not sure how to impliment it. I worked on this for hours on Sunday and I was able to get my routine to enter the text in the 90 angle, but the text is basically line feeding up instead of down. I figured it was a good starting point. I am attaching the the code I came up with. I have ommitted the comments for clarity.

    I am also using the DTR function instead of doing all of the car functions. I think if I could group all entities created with this, then I could store the insert point of the last line of text created and then simply move all of those text entities up to the original start point.

    Anyone have any ideas?

    "Catch" Ya Later,
    AKDRAFTER

    ;; TBL2.lsp
    ;;
    ;; By Timothy J. Jaronik Sr.
    ;; February, 2004
    ;;
    ;; A routine to create Dtext with a justification of bottom left and moved 3/16" to the east (0 angle) of the user picked point
    ;;
    ;;;;;;;;;;;;;;;BEGIN ERROR HANDLING FUNCTION;;;;;;;;;;;;;;;
    ;;
    (defun ERRTRAP (msg)
    (princ "\n Error: ")
    (if msg (princ msg))
    (setvar "CLAYER" CLA)
    (setvar "CMDECHO" CME)
    (setvar "OSMODE" OSM)
    (setvar "ORTHOMODE" OTHM)
    (setvar "SNAPMODE" SNM)
    (setvar "TEXTSTYLE" TSTYLE)
    (setq *ERROR* OLDERR)
    (prompt "\n Resetting System Variables... ")
    (princ)
    )
    ;;
    ;;;;;;;;;;;;;;;END ERROR HANDLING FUNCTION;;;;;;;;;;;;;;;
    ;;
    ;;;;;;;;;;;;;;;BEGIN DTR FUNCTION;;;;;;;;;;;;;;;
    ;;
    (defun DTR (a)
    (* PI (/ a 180.0))
    )
    ;;
    ;;;;;;;;;;;;;;;END DTR FUNCTION;;;;;;;;;;;;;;;
    ;;
    ;;
    (defun C:TBL2 ( / OLDERR *ERROR* CLA CME OSM OTHM SNM TSTYLE DIMSC DSTH TXSP SP0 SP1 TXT)
    (setq OLDERR *ERROR*)
    (setq *ERROR* ERRTRAP)
    (setq CLA(getvar "CLAYER"))
    (setq CME(getvar "CMDECHO"))
    (setvar "CMDECHO" 0)
    (setq OSM(getvar "OSMODE"))
    (setvar "OSMODE" 0)
    (setq OTHM(getvar "ORTHOMODE"))
    (setvar "ORTHOMODE" 0)
    (setq SNM(getvar "SNAPMODE"))
    (setvar "SNAPMODE" 0)
    (setq TSTYLE(getvar "TEXTSTYLE"))
    (setq DIMSC(getvar "DIMSCALE"))
    (setq TXTH 0.09375000)
    (setq DSTH(* DIMSC TXTH))
    (setq TXSP(* DSTH 1.619))
    (command "-layer" "thaw" "TEXT" "on" "TEXT" "make" "TEXT" "color" "4" "TEXT" "lt" "continuous" "TEXT" "")
    (command "-style" "ROMANS" "ROMANS.shx" "0.00000000" "1.00000000" "0.00000000" "N" "N" "N")
    (setq SP0(getpoint "\n Pick the BOTTOM LEFT point: "))
    (setq SP1(polar SP0 (DTR 0.0) (* DIMSC 0.18750000)))
    (setq X "T")
    (while X
    (setq TXT(getstring "\n Enter Text: "))
    (command "._text" "_J" "_BL" SP1 (* DIMSC 0.09375000) "0.00000000" TXT)
    (setq SP1(polar SP1 (DTR 90.0)TXSP))
    (if(= TXT "")(setq X nil))
    )
    (setq *ERROR* OLDERR)
    (setvar "CLAYER" CLA)
    (setvar "CMDECHO" CME)
    (setvar "OSMODE" OSM)
    (setvar "ORTHOMODE" OTHM)
    (setvar "SNAPMODE" SNM)
    (setvar "TEXTSTYLE" TSTYLE)
    (princ)
    )
     
    akdrafter, Mar 1, 2004
    #4
  5. It works by calculating the height of the linefeed character based upon the
    entity data supplied

    For example, select a text object:

    Command: (setq e (entget (car (entsel))))

    Select object: ((-1 . <Entity name: 7efc5a88>) (0 . "TEXT") (330 . <Entity
    name: 7efadcb8>) (5 . "3209") (100 . "AcDbEntity") (67 . 0) (410 . "Model")
    (8
    .. "S-ANNO-NOTE") (100 . "AcDbText") (10 640.102 -387.666 0.0) (40 . 6.0) (1
    ..
    "SW") (50 . 1.5708) (41 . 1.0) (51 . 0.0) (7 . "STANDARD") (71 . 0) (72 . 1)
    (11 640.102 -381.951 0.0) (210 0.0 0.0 1.0) (100 . "AcDbText") (73 . 0))

    Then, to find the line spacing of the style "Standard" at a text height of
    6.0:

    Command: (txtlinespcg e)
    10.2857


    If you know all the properties (Style name = "Sectitle", and height = 9.0).
    use something like this to get the height of the linefeed character

    Create a temporary enitity data list:

    Command: (setq e (list (cons 0 "TEXT") (cons 7 "Sectitle") (cons 40 9.0)
    (cons 10 (list 0 0 0)) (cons 1 "1\n1")))
    ((0 . "TEXT") (7 . "Sectitle") (40 . 9.0) (10 0 0 0) (1 . "1\n1"))

    And supply it to txtlinespcg:

    Command: (txtlinespcg e)
    14.8966

    So, say you want to move your newly created text object up one line spacing:

    (setq e (entget (entlast)))
    (setq y (txtlinespcg e))
    (command "move" "last" "" (list 0 y) "")
     
    Allen Johnson, Mar 1, 2004
    #5
  6. You may also want to investigate the AutoLay program (I think posted in
    customer files somewhere)
    It is supposed to do all that for you using reactors.

    Ah ha, found this:

    go to the 'customer-files' NG and download AutoLay[3.0].zip posted on
    11/20/02.
     
    Allen Johnson, Mar 1, 2004
    #6
  7. akdrafter

    akdrafter Guest

    Allen,

    Correct me if I am wrong... this would only work for no more than 2 lines of text? It apperas to me that unless you add all text entities to a list, then you would only be placing text on top of text if you entered 3 or more lines of text.

    I am honestly trying to figure this out on my own and doing the best I can. But I always look to the very knowledgeable folks in here to guide me along. :)

    "Catch" Ya Later,
    AKDRAFTER
     
    akdrafter, Mar 1, 2004
    #7
  8. akdrafter

    akdrafter Guest

    Forgot to add this thought.

    If I could just run the dtext command, which would give an interactive approach to entering the text, and add all of the text to a list, then I could extract the point of the last piece of text and simply move all of the text in the list that was created to the original insertion point.

    Would that work?

    "Catch" Ya Later,
    AKDRAFTER
     
    akdrafter, Mar 1, 2004
    #8
  9. akdrafter

    akdrafter Guest

    Allen,

    I can't seem to go back as far as 11/20/02 or find the autolay in a search.

    Any ideas?

    "Catch" Ya Later,
    AKDRAFTER
     
    akdrafter, Mar 1, 2004
    #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.