Aller au contenu

Recherche LISP pour convertir Text en textmultiligne


chrisbric

Messages recommandés

Tiens en voilà un qui est vieux mais qui marche toujours du moins dans le sens texte to mtext dans l'autre sens je me souviens plus et d'où je suis maintenant je ne peux pas essayer.

Sinon pourquoi veux -tu un lisp (vieux) ?

 

;;;    t2mt.lsp and mt2t.lsp
;;;    
;;;    Copyright (C) 1996 by Frank J. Hessler, THP Limited
;;;    MODIFIE POUR AUTOCAD 14   usegomme
;;;
;;;    Permission to use, copy, modify, and distribute this software
;;;    for any purpose and without fee is hereby granted, provided
;;;    that the above copyright notice appears in all copies and
;;;    that both that copyright notice and the limited warranty and
;;;    restricted rights notice below appear in all supporting
;;;    documentation.
;;;
;;;    THP LIMITED PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
;;;    THP LIMITED SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
;;;    MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  THP LIMITED
;;;    DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
;;;    UNINTERRUPTED OR ERROR FREE.
;;;
;;;----------------------------------------------------------------------------
;;;    DESCRIPTION
;;;
;;;    C:T2MT
;;;    Converts multiple lines of TEXT objects to an MTEXT object using
;;;    the current text height while maintaining overall string width.
;;;
;;;    C:MT2T
;;;    Converts MTEXT object into text object.  Works best for single-line
;;;    objects since it puts the entire MText string on one line.
;;;
;;;----------------------------------------------------------------------------
 (defun C:T2MT ( / sset)
   (princ "\nText -> MText Conversion\nSelect Text objects in order...")
   (if (setq sset (ssget)) (t2mt sset))
 ) ; end defun C:T2MT

 (defun t2mt (sset / num c ent ed clay ipt wid wid1 val)
   (command "._undo" "_g")
   (setq num (sslength sset)
         c -1
         ent (ssname sset (setq c (1+ c)))
         ed (entget ent)
         clay (getvar "clayer")
   ) ; end setq
   (if (= "TEXT" (cdr (assoc 0 ed)))
     (progn
       (setq val (cdr (assoc 1 ed))
             rot (cdr (assoc 50 ed))
             ipt (polar (cdr (assoc 10 ed)) (+ rot (* 0.5 pi)) (cdr (assoc 40 ed)))
             wid (car (cadr (textbox (list (cons 1 (strcat val " "))))))
       ) ; end setq
       (repeat (1- num)
         (setq ent (ssname sset (setq c (1+ c)))
               ed (entget ent)
               wid1 (car (cadr (textbox (list (cons 1 (strcat (cdr (assoc 1 ed)) " "))))))
               val (strcat val " " (cdr (assoc 1 ed)))
         ) ; end setq
         (if (> wid1 wid) (setq wid wid1))
       ) ; end repeat
       (setvar "clayer" (cdr (assoc 8 ed)))
       (command "._erase" sset ""
                "_.-mtext" ipt "_r" (* 180 (/ rot pi)) "_w" (1+ wid) val ""
                "._undo" "_e"
       ) ; end command
       (setvar "clayer" clay)
     ) ; end progn
   ) ; end if
   (princ)
 ) ; end defun t2mt

;;;----------------------------------------------------------------------------

 (defun C:MT2T ( / sset)
   (princ "\nMText -> Text Conversion")
   (if (setq sset (ssget)) (mt2t sset))
 ) ; end defun

 (defun mt2t (sset / ent ed tmp c10 c11 c72 c73 width c num)
   (command "._undo" "_g")
   (setq num (sslength sset) c -1)
   (repeat num
     (setq ent (ssname sset (setq c (1+ c)))
           ed (entget ent)
     ) ; end setq
     (if (= "MTEXT" (cdr (assoc 0 ed)))
       (progn
         (cond
           ((= 1 (cdr (assoc 71 ed))) (setq c72 0 c73 3))     ; TL
           ((= 2 (cdr (assoc 71 ed))) (setq c72 1 c73 3))     ; TC
           ((= 3 (cdr (assoc 71 ed))) (setq c72 2 c73 3))     ; TR
           ((= 4 (cdr (assoc 71 ed))) (setq c72 0 c73 2))     ; ML
           ((= 5 (cdr (assoc 71 ed))) (setq c72 1 c73 2))     ; MC
           ((= 6 (cdr (assoc 71 ed))) (setq c72 2 c73 2))     ; MR
           ((= 7 (cdr (assoc 71 ed))) (setq c72 0 c73 1))     ; BL
           ((= 8 (cdr (assoc 71 ed))) (setq c72 1 c73 1))     ; BC
           ((= 9 (cdr (assoc 71 ed))) (setq c72 2 c73 1))     ; BR
         ) ; end cond
         (setq width (cdr (assoc 41 (tblsearch "style" (cdr (assoc 7 ed))))))
         (if (= 7 (cdr (assoc 71 ed)))
           (setq c10 (cdr (assoc 10 ed)) c11 '(0 0 0) c73 0)
           (setq c10 '(0 0 0) c11 (cdr (assoc 10 ed)))
         ) ; end if
         (entdel ent)
         (entmake
           (setq tmp (list
             '(0 . "TEXT")
             (cons 1  (cdr (assoc  1 ed)))     ; text value
             (cons 7  (cdr (assoc  7 ed)))     ; text style
             (cons 8  (cdr (assoc  8 ed)))     ; layer
             (cons 10 c10)
             (cons 11 c11)
             (cons 40 (cdr (assoc 40 ed)))     ; text height
             (cons 41 width)                   ; text relative width
             (cons 72 c72)                     ; horiz alignment
             (cons 73 c73)                     ; vert alignment
           )) ; end list and setq
         ) ; end entmake
       ) ; end progn
     ) ; end if
   ) ; end repeat
   (command "._undo" "_e")
   (princ)
 ) ; end defun

 (princ "\nMTEXT conversion routines loaded.  Type T2MT or MT2T or execute.")

Lien vers le commentaire
Partager sur d’autres sites

Créer un compte ou se connecter pour commenter

Vous devez être membre afin de pouvoir déposer un commentaire

Créer un compte

Créez un compte sur notre communauté. C’est facile !

Créer un nouveau compte

Se connecter

Vous avez déjà un compte ? Connectez-vous ici.

Connectez-vous maintenant
×
×
  • Créer...

Information importante

Nous avons placé des cookies sur votre appareil pour aider à améliorer ce site. Vous pouvez choisir d’ajuster vos paramètres de cookie, sinon nous supposerons que vous êtes d’accord pour continuer. Politique de confidentialité