Enhance this Lisp please

Discussion in 'AutoCAD' started by Victor H. Becerra, Jun 15, 2004.

  1. Hi,

    I have this Lisp routine which gives me the command "CD" and "CU". What
    this does is it allows me to copy a single line text entity up or down
    (hence "CD" (down) "CU" (up)) using the same exact spacing as if one
    were typing and hitting return. I would like to modify this lisp
    routine to allow me to do this to a multiline text entity with a leader
    therefore this routine needs to be modified to allow a multiple
    selection as opposed to one, and the type of selections allowed, now
    being single line text, multiline text, and a leader. Any help is
    greatly appreciated. Thanks in advance.

    (defun c:CU ( / ent edata txtsz lnsp)
    (if
    (and
    (setq ent (car (entsel)))
    (= (cdr (assoc 0 (setq edata (entget ent)))) "TEXT")
    )
    (progn
    (setq
    txtsz (cdr (assoc 40 edata))
    lnsp (* txtsz (/ 34 21.0))
    edata (subst (cons 10 (polar (cdr (assoc 10 edata)) (+ (cdr (assoc 50
    edata)) (* pi -1.5)) lnsp)) (assoc 10 edata) edata)
    edata (subst (cons 11 (polar (cdr (assoc 11 edata)) (+ (cdr (assoc 50
    edata)) (* pi -1.5)) lnsp)) (assoc 11 edata) edata)
    )
    (entmake edata)
    )
    (princ "\nRequires text entity.")
    )
    (princ)
    )
    ;;-------------------------------------------------------------------------------------
    (defun c:CD ( / ent edata txtsz lnsp)
    (if
    (and
    (setq ent (car (entsel)))
    (= (cdr (assoc 0 (setq edata (entget ent)))) "TEXT")
    )
    (progn
    (setq
    txtsz (cdr (assoc 40 edata))
    lnsp (* txtsz (/ 34 21.0))
    edata (subst (cons 10 (polar (cdr (assoc 10 edata)) (+ (cdr (assoc 50
    edata)) (* pi 1.5)) lnsp)) (assoc 10 edata) edata)
    edata (subst (cons 11 (polar (cdr (assoc 11 edata)) (+ (cdr (assoc 50
    edata)) (* pi 1.5)) lnsp)) (assoc 11 edata) edata)
    )
    (entmake edata)
    )
    (princ "\nRequires text entity.")
    )
    (princ)
    )
     
    Victor H. Becerra, Jun 15, 2004
    #1
  2. Victor H. Becerra

    zeha Guest

    modifie line
    (=(cdr (assoc 0 (setq edata (entget ent)))) "TEXT") to
    (wcmatch (cdr (assoc 0 (setq edata (entget ent)))) "*TEXT")

    and it work but a multiple line text must above more then one space
    Use DXF 42 and 43 for position the new text
     
    zeha, Jun 16, 2004
    #2
  3. This worked fine with the mtext, but it did not work with the quick
    leader. Also, the selection is still a "one entity selection" method as
    opposed to a multiple object selection (being the mtext and the quick
    leader). Thanks.
     
    Victor H. Becerra, Jun 17, 2004
    #3
  4. Victor H. Becerra

    zeha Guest

    this works fine when i select the text from the leader
    I suppose that the propertie from the entity give's MTEXT or TEXT

    (defun c:CU ( / ent edata txtsz lnsp)
    (if
    (and
    (setq ent (car (entsel)))
    (wcmatch (cdr (assoc 0 (setq edata (entget ent)))) "*TEXT")
    )
    (progn
    (setq
    txtsz (cdr (assoc 40 edata))
    lnsp (* txtsz (/ 34 21.0))
    lnsp (if (= (cdr (assoc 0 edata)) "MTEXT")(* lnsp (1+ (fix (/ (cdr (assoc 43 edata)) lnsp)))) lnsp)
    edata (subst (cons 10 (polar (cdr (assoc 10 edata)) (+ (cdr (assoc 50
    edata)) (* pi -1.5)) lnsp)) (assoc 10 edata) edata)
    edata (subst (cons 11 (polar (cdr (assoc 11 edata)) (+ (cdr (assoc 50
    edata)) (* pi -1.5)) lnsp)) (assoc 11 edata) edata)
    )
    (entmake edata)
    )
    (princ "\nRequires text entity.")
    )
    (princ)
    )

    good luck,

    Harrie
     
    zeha, Jun 18, 2004
    #4
  5. I want to copy the leader also.
     
    Victor H. Becerra, Jun 18, 2004
    #5
  6. Victor H. Becerra

    zeha Guest

    If you want to copy text or mtext or leader this is more complicator with entmake I used copy command see below

    (defun c:CU ( / ent edata entn txtsz lnsp ldr sss)
    (if
    (and
    (setq ent (car (entsel)))
    (wcmatch (cdr (assoc 0 (setq edata (entget ent)))) "*TEXT")
    )
    (progn
    (setq entn (cdr (assoc 0 edata))
    txtsz (cdr (assoc 40 edata))
    lnsp (* txtsz (/ 34 21.0))
    lnsp (if (= entn "MTEXT")(* lnsp (1+ (fix (/ (cdr (assoc 43 edata)) lnsp)))) lnsp)
    edata (subst (cons 10 (polar (cdr (assoc 10 edata)) (+ (cdr (assoc 50
    edata)) (* pi -1.5)) lnsp)) (assoc 10 edata) edata)
    edata (subst (cons 11 (polar (cdr (assoc 11 edata)) (+ (cdr (assoc 50
    edata)) (* pi -1.5)) lnsp)) (assoc 11 edata) edata)
    ldr (cdr (assoc 330 edata))
    sss (ssadd ent)
    sss (if (= entn "MTEXT")(ssadd ldr sss) sss)
    )
    (command ".copy" sss "" "_Non" pt10 "_Non"
    (polar pt10 (+ (cdr (assoc 50 edata)) (* pi -1.5)) lnsp))
    )
    (princ "\nRequires text entity.")
    )
    (princ)
    )
     
    zeha, Jun 19, 2004
    #6
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.