2017-06-30 61 views
0

我有以下代碼。它創建文本到多行文本而無需在autocad中移動文本塊。我想要這個腳本,但將文本行合併到一個區域內的一個塊中。就像在某個圖層的文本塊的南北方向5個單位內創建一個mtext塊一樣。區域內文字多行文字 - autocad

(defun C:T1MJ ; = Text or Attribute Definition to 1-line Mtext, retaining Justification 
    (/ *error* cmde doc tss inc tent tobj tins tjust) 

    (defun *error* (errmsg) 
    (if (not (wcmatch errmsg "Function cancelled,quit/exit abort,console break")) 
     (princ (strcat "\nError: " errmsg)) 
    ); if 
    (vla-endundomark doc) 
    (setvar 'cmdecho cmde) 
    (princ) 
); defun - *error* 

    (setq 
    cmde (getvar 'cmdecho) 
    doc (vla-get-activedocument (vlax-get-acad-object)) 
); setq 
    (vla-startundomark doc) 
    (setvar 'cmdecho 0) 
    (prompt "\nTo change Text/Attribute to 1-line Mtext, preserving Justification,") 
    (if (setq tss (ssget "_:L" '((0 . "TEXT,ATTDEF")))) 
    (repeat (setq inc (sslength tss)) 
     (setq 
     tent (ssname tss (setq inc (1- inc))) 
     tobj (vlax-ename->vla-object tent) 
     tins (vlax-get tobj 'TextAlignmentPoint) 
     tjust (vla-get-Alignment tobj) 
    ); setq 
     (cond 
     ((= tjust 0) (setq tjust 7 tins (vlax-get tobj 'InsertionPoint))); Left 
     ((< tjust 3) (setq tjust (+ tjust 7))); 1/2 [Center/Right] to 8/9 
     ((= tjust 4) (setq tjust 5)); Middle to Middle-Center 
     ((member tjust '(3 5)); Aligned/Fit 
      (setq 
      tjust 8 ; to Bottom-Center 
      tins (mapcar '/ (mapcar '+ (vlax-get tobj 'InsertionPoint) tins) '(2 2 2)) 
       ; with new insertion point 
     ); setq 
     ); Aligned/Fit 
     ((setq tjust (- tjust 5))); all vertical-horizontal pair justifications 
    ); cond 
     (if (= (vla-get-TextString tobj) "") (vla-put-TextString tobj (vla-get-TagString tobj))) 
     ;; if no default content, disappears after TXT2MTXT: impose Tag value for it 
     ;; [to use Prompt value instead, change end to (vla-get-PromptString tobj).] 
     (command "_.txt2mtxt" tent ""); convert, then 
     (setq tobj (vlax-ename->vla-object (entlast))); replace Text as object with new Mtext 
     (vla-put-AttachmentPoint tobj tjust); original Text's justification [or equiv.] 
     (vlax-put tobj 'InsertionPoint tins); original Text's insertion 
    ); repeat 
); if 
    (setvar 'cmdecho cmde) 
    (vla-endundomark doc) 
    (princ) 
); defun -- T1MJ 
(vl-load-com) 
(prompt "\nType T1MJ to change Text/Attribute-Definitions to 1-line Mtext, preserving Justification.") 

回答

0

我不是一個lisp程序員,所以我不能給你一個直接的答案,但我正在向你描述一個概念,你應該能夠複製。

如果你看這裏吧討論快捷工具之一這個網絡資源:TXT2MTXT

TXT2MTXT

現在,這是一個命令行程序,它需要一個選擇集並轉換TEXTMTEX​​T對象:

MTEXT

所以,我看不出爲什麼你不能使用lisp來創建文本對象的本地化選擇集,然後將此選擇集傳遞給TXT2MTXT命令。我知道可以用lisp來做這種事情。我只是不知道機制。我知道VBA。

我希望這有助於你解決你的問題。它不顯示代碼,但它描述瞭如何做你想要的概念。