Dtext

There is a text setvar in autocad wherein you can select the insertion point of an existing line of text  to enter more text and if you hit enter a couple of times it stays in the text command and drops down to insert the text string at the correct point below the existing text.  So you can add additional lines of text with the correct line spacing below an existing line of text.

Any suggestions for bricscad to achieve the same result?

Comments

  •  The express tools, available for free in the Applications area of the web page, has a DTEXT to MTEXT conversion utility.  Just select the text, and it will be converted.  If you select several DTEXT objects, they are added to the MTEXT in the order they were chosen.

    -Joe
  • This code will append text below an existing text entity.  I have not used the code in several years but it should still work.  I now use an updated version that shows a cursor, but the new version requires AutoHotKey to capture the cursor control keys.  The updated version honors HOME, END, the left arrow key, the right arrow key, BACKSPACE, DELETE, ^C, ^V, and ^X, and allows selecting groups of characters.  It's close to a WYSIWYG on-screen editor for text.  I'll be happy to post those files if you'd like.

    Another option is to issue the TEXT command, shift+right click and select the insert esnap, click on the existing text, handle the height prompt, handle the rotation prompt, press the space bar once then press ENTER, then enter the new text.  This approach leaves an extra line of text in the drawing that consists of a single space.

    [code](defun c:addtext (/ *error* saved_cecolor saved_layer saved_text_size
                      saved_text_style gettx horizontal_alignment horizontal_code
                      insertion_point justification old_error_handler saved_osmode
                      flag selected_text text_style text_color text_layer
                      text_rotation text_height vertical_alignment vertical_code
                     )

      (defun DynText ( inputLst / marker)
        (setq marker (entlast))
        (command "_.text")
        (while inputLst
          (command (car inputLst))
          (setq inputLst (cdr inputLst))
        )
        (while (> (getvar "cmdactive") 0)
          (command pause)
        )
        (setvar "cmdecho" 0)
        (while (not (equal marker (entlast)))
          (setq marker (entlast))
          (command "_.text" "")                                                      ; restart text-command
          (princ "Text: ")
          (while (> (getvar "cmdactive") 0)
            (command pause)
          )
        )
        (setvar "cmdecho" 1)
      )

      (defun addtexterror (s)
        (princ s)
        (setvar "cmdecho" 0)
        (command "._undo" "end")
        (setvar "cecolor" saved_cecolor)
        (setvar "clayer" saved_layer)
        (setvar "textstyle" saved_text_style)
        (setvar "textsize" saved_text_size)
        (setvar "osmode" saved_osmode)
        (setvar "cmdecho" 1)
        (setq *error* old_error_handler)
        (princ)
      )

      (defun line_space (sample / text_style text_height dot1 dot1_entity          ; pass in a text entity
                         dot2 dot2_entity spacing)
        (setq text_style (cdr (assoc 7 sample)))                                   ; get the sample's style
        (setq text_height (cdr (assoc 40 sample)))                                 ; get the sample's height
        (command "TEXT"                                                            ; place a dot at 0,0,0
                 "S"
                 text_style
                 '(0.0 0.0 0.0)
                 text_height
                 0.0
                 "."
        )
        (setq dot1 (entlast))                                                      ; get the entity
        (setq dot1_entity (entget dot1))                                           ; get the entity's data
        (command "TEXT"                                                            ; place a second dot on a new line
                 ""
                 "."
        )
        (setq dot2 (entlast))                                                      ; get the entity
        (setq dot2_entity (entget dot2))                                           ; get the entity's data
        (setq spacing (abs (- (caddr (assoc '10 dot1_entity))                      ; calc the line spacing
                              (caddr (assoc '10 dot2_entity))
                           )
                      )
        )
        (entdel dot1)                                                              ; get rid of the evidence
        (entdel dot2)
        spacing
      )

      ;;CODE FOR PROGRAM
      (setvar "cmdecho" 0)
      (command "._undo" "begin")
      (setq old_error_handler  *error*
            *error* addtexterror
      )
      (setq saved_osmode (getvar "osmode"))
      (setq saved_layer (getvar "clayer"))
      (setq saved_text_style (getvar "textstyle"))
      (setq saved_text_size (getvar "textsize"))
      (setq saved_cecolor (getvar "cecolor"))
      (setvar "osmode" 64)                                                         ; set insert osnap
      (prompt "\nSelect text line to append new text below ... ")
      (setvar "osmode" 0)                                                          ; osnaps off
      (setq flag 0)
      (while (= flag 0)
        (progn
          (setq selected_text (entsel))                                            ; select the initial text
          (setq selected_text_data (entget (car selected_text)))                   ; get the entity
          (if (= (cdr (assoc 0 selected_text_data)) "TEXT")                        ; is it text?
            (setq flag                 1                                           ; set flag to exit loop
                  text_style           (cdr (assoc 7 selected_text_data))
                  horizontal_alignment (cdr (assoc 72 selected_text_data))
                  vertical_alignment   (cdr (assoc 73 selected_text_data))
                  text_height          (cdr (assoc 40 selected_text_data))
                  text_rotation        (cdr (assoc 50 selected_text_data))
                  text_layer           (cdr (assoc 8 selected_text_data))
                  text_color           (cdr (assoc 62 selected_text_data))
            )
          )
        )
      )
      (setvar "clayer" text_layer)                                                 ; make the text layer current
      (cond ((= horizontal_alignment 0) (setq horizontal_code "L"))                ; set justification flags
            ((= horizontal_alignment 1) (setq horizontal_code "C"))
            ((= horizontal_alignment 2) (setq horizontal_code "R"))
            ((= horizontal_alignment 4) (setq horizontal_code "M"))
      )
      (cond ((= vertical_alignment 0) (setq vertical_code ""))
            ((= vertical_alignment 1) (setq vertical_code "B"))
            ((= vertical_alignment 2) (setq vertical_code "M"))
            ((= vertical_alignment 3) (setq vertical_code "T"))
      )
      (if (= horizontal_alignment vertical_alignment 0)                            ; left justification uses dxf 10, all others use dxf 11
        (setq insertion_point (cdr (assoc 10 selected_text_data)))                 ; set the insertion point
        (setq insertion_point (cdr (assoc 11 selected_text_data)))
      )
      (setq justification (strcat vertical_code horizontal_code))                  ; assemble justification string
      (cond ((= text_color nil) (setvar "cecolor" "BYLAYER"))
            ((= text_color 256) (setvar "cecolor" "BYLAYER"))
            ((= text_color 0) (setvar "cecolor" "BYBLOCK"))
            ((and (> text_color 0)
                  (< text_color 255)
             ) (setvar "cecolor" (itoa text_color))
            )
            (t nil)
      )
      (setq insertion_point (polar insertion_point
                                   (+ text_rotation (* 3.0 (/ pi 2.0)))
                                   (line_space selected_text_data)
                            )
      )
      (setvar "textstyle" text_style)
      (setvar "textsize" text_height)
      (prompt "\n\nText: ")
      (if (= justification "L")
        (dyntext (list "s" text_style
                       insertion_point
                       text_height
                       (angtos text_rotation 3 8)
                 )
        )
        (dyntext (list "s" text_style
                       "j" justification
                       insertion_point
                       text_height
                       (angtos text_rotation 3 8)
                 )
        )
      )
      (princ)
      (setvar "cecolor" saved_cecolor)
      (setvar "clayer" saved_layer)
      (setvar "textstyle" saved_text_style)
      (setvar "textsize" saved_text_size)
      (setvar "osmode" saved_osmode)
      (command "._undo" "end")
      (setvar "cmdecho" 1)
      (setq *ERROR* old-error)
    )

    [/code]
This discussion has been closed.