Help with this routine

Discussion in 'AutoCAD' started by MKE, Aug 10, 2004.

  1. MKE

    MKE Guest

    I need a little help here. The following routine will do what it should,
    combine two MTEXT strings, the first time I run it. But, when I try to run
    it again to combine another MTEXT string with the previously combined MTEXT
    a portion of the second MTEXT gets deleted.

    Thanks,

    (defun c:mmt (/ first delete second delete1 mtx1 mtx2 mtx ed)
    (prompt "\nTo merge two MTEXT entities")
    (setq first (entget (car(entsel"\nSelect first MTEXT entity: "))))
    (if (= first nil)(exit))
    (setq delete1(cdr(assoc -1 first)))
    (redraw delete1 3)
    (setq second (entget (car(entsel"\nSelect second MTEXT entity: "))))
    (if (= second nil)(exit))
    (setq delete (cdr(assoc -1 second)))
    (redraw delete 3)
    (setq mtx1 (cdr (assoc 1 first)))
    (setq mtx2 (cdr (assoc 1 second)))
    (setq mtx (strcat mtx1 "\\P" mtx2))
    (command "erase" delete delete1 "")
    (setq ed first)
    (setq ed
    (subst (cons 1 mtx)
    (assoc 1 ed)
    ed
    )
    )
    (entmake ed)
    (princ)
    )
     
    MKE, Aug 10, 2004
    #1
  2. If the mtext string is greater than 250 characters, some of the string gets pushed into the dxf
    field 3. You'll need to check for the existance of any text contained in the dxf 3 fields and
    incorporate it too.

    I seem to remember someone (Jason Piercey, I think) wrote some code to handle this situation.

    From DXF Help:

    1
    Text string. If the text string is less than 250 characters, all characters appear in group 1.
    If the text string is greater than 250 characters, the string is divided into 250-character chunks,
    which appear in one or more group 3 codes. If group 3 codes are used, the last group is a group 1
    and has fewer than 250 characters



    3
    Additional text (always in 250-character chunks) (optional)
     
    Allen Johnson, Aug 10, 2004
    #2
  3. MKE

    MP Guest

    review the help on mtext objects

    1
    Text string. If the text string is less than 250 characters, all
    characters appear in group 1. If the text string is greater than 250
    characters, the string is divided into 250-character chunks, which appear in
    one or more group 3 codes. If group 3 codes are used, the last group is a
    group 1 and has fewer than 250 characters
     
    MP, Aug 10, 2004
    #3
  4. This is a case where vlisp (ActiveX) methods might work better:

    (defun c:mmt (/ l1 l2)
    (setq l1 (ssget "+.:E:S" (list (cons 0 "MTEXT")))
    l2 (ssget "+.:E:S" (list (cons 0 "MTEXT")))
    )
    (apptext (ssname l1 0) (ssname l2 0))
    )

    (defun apptext (t1 t2 / o1 o2 a1 a2)
    (vl-load-com)
    (setq
    o1 (vlax-EName->vla-Object t1)
    o2 (vlax-EName->vla-Object t2)
    )

    (if (and (= (vla-Get-ObjectName o1) "AcDbMText")
    (= (vla-Get-ObjectName o2) "AcDbMText")
    )

    (progn
    (setq ts1 (vla-get-textstring o1)
    ts2 (vla-get-textstring o2)
    )
    (vla-put-textstring o1 (strcat ts1 "\\P" ts2))
    (entdel t2)

    )

    )

    )
     
    Allen Johnson, Aug 10, 2004
    #4
  5. I corrected the local variable list:

    (defun apptext (t1 t2 / o1 o2 ts1 ts2)
    (vl-load-com)
    (setq
    o1 (vlax-EName->vla-Object t1)
    o2 (vlax-EName->vla-Object t2)
    )

    (if (and (= (vla-Get-ObjectName o1) "AcDbMText")
    (= (vla-Get-ObjectName o2) "AcDbMText")
    )

    (progn
    (setq ts1 (vla-get-textstring o1)
    ts2 (vla-get-textstring o2)
    )
    (vla-put-textstring o1 (strcat ts1 "\\P" ts2))
    (entdel t2)

    )

    )

    )
     
    Allen Johnson, Aug 10, 2004
    #5
  6. MKE

    MKE Guest

    Where do I find these DXF fields?
    Thanks,
     
    MKE, Aug 10, 2004
    #6
  7. In Help > Developer Help > DXF Reference > Entities Section > MTEXT
     
    Allen Johnson, Aug 10, 2004
    #7
  8. MKE

    MKE Guest

    Got it! Thank you very much.

     
    MKE, Aug 10, 2004
    #8
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.