1. ;;
    2. ;;;
    3. ;;; By Dominic Panholzer
    4. ;;;
    5. ;;; TXTEXP.LSP
    6. ;;; Copyright ?1999 by Autodesk, Inc.
    7. ;;;
    8. ;;; Your use of this software is governed by the terms and conditions of the
    9. ;;; License Agreement you accepted prior to installation of this software.
    10. ;;; Please note that pursuant to the License Agreement for this software,
    11. ;;; "[c]opying of this computer program or its documentation except as
    12. ;;; permitted by this License is copyright infringement under the laws of
    13. ;;; your country. If you copy this computer program without permission of
    14. ;;; Autodesk, you are violating the law."
    15. ;;;
    16. ;;; AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
    17. ;;; AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
    18. ;;; MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
    19. ;;; DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
    20. ;;; UNINTERRUPTED OR ERROR FREE.
    21. ;;;
    22. ;;; Use, duplication, or disclosure by the U.S. ** is subject to
    23. ;;; restrictions set forth in FAR 52.227-19 (Commercial Computer
    24. ;;; Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
    25. ;;; (Rights in Technical Data and Computer Software), as applicable.
    26. ;;;
    27. ;;; ----------------------------------------------------------------
    28. ;;;
    29. ;;; External Functions:
    30. ;;;
    31. ;;; ACET-ERROR-INIT --> ACETUTIL.FAS Intializes bonus error routine
    32. ;;; ACET-ERROR-RESTORE --> ACETUTIL.FAS Restores old error routine
    33. ;;; ACET-GEOM-ZOOM-FOR-SELECT --> ACETUTIL.FAS Zoom boundry to include points given
    34. ;;; ACET-LAYER-LOCKED --> ACETUTIL.FAS Checks to see if layer is locked
    35. ;;; ACET-GEOM-PIXEL-UNIT --> ACETUTIL.FAS Size of pixel in drawing units
    36. ;;; ACET-GEOM-TEXTBOX --> ACETUTIL.FAS Returns the textbox for any text
    37. ;;; ACET-GEOM-MIDPOINT --> ACETUTIL.FAS Returns midpoint between two points
    38. ;;; ACET-GEOM-VIEW-POINTS --> ACETUTIL.FAS Returns corner points of screen or viewport
    39. ;;; ACET-STR-FORMAT --> ACETUTIL.ARX String builder
    40. ;;; ACET-WMFIN --> ACETUTIL.FAS Brings in WMF file
    41. ;;;
    42. (defun c:txtexp (/ grplst getgname blknm FLTR GLST GDICT SS VIEW UPLFT TMPFIL TBX
    43. TMPFIL CNT PT1 PT2 ENT TXT TXTYP PTLST ZM LOCKED GNAM vpna vplocked)
    44. (acet-error-init
    45. (list
    46. (list "cmdecho" 0
    47. "highlight" 1
    48. "osmode" 0
    49. "Mirrtext" 1
    50. "limcheck" 0
    51. )
    52. T
    53. )
    54. )
    55. ; --------------------- GROUP LIST FUNCTION ----------------------
    56. ; This function will return a list of all the group names in the
    57. ; drawing and their entity names in the form:
    58. ; ((<ename1> . <name1>) ... (<enamex> . <namex>))
    59. ; ----------------------------------------------------------------
    60. (defun acet-txtexp-grplst (/ GRP ITM NAM ENT GLST)
    61. (setq GRP (dictsearch (namedobjdict) "ACAD_GROUP"))
    62. (while (setq ITM (car GRP)) ; While edata item is available
    63. (if (= (car ITM) 3) ; if the item is a group name
    64. (setq NAM (cdr ITM) ; get the name
    65. GRP (cdr GRP) ; shorten the edata
    66. ITM (car GRP) ; get the next item
    67. ENT (cdr ITM) ; which is the ename
    68. GRP (cdr GRP) ; shorten the edata
    69. GLST ; store the ename and name
    70. (if GLST
    71. (append GLST (list (cons ENT NAM)))
    72. (list (cons ENT NAM))
    73. )
    74. )
    75. (setq GRP (cdr GRP)) ; else shorten the edata
    76. )
    77. )
    78. GLST ; return the list
    79. )
    80. ; ------------------- GET GROUP NAME FUNCTION --------------------
    81. ; This function returns a list of all the group names in GLST
    82. ; where ENT is a member. The list has the same form as GLST
    83. ; ----------------------------------------------------------------
    84. (defun acet-txtexp-getgname (ENT GLST / GRP GDATA NAM NLST)
    85. (if (and GLST (listp GLST))
    86. (progn
    87. (foreach GRP GLST
    88. (setq GDATA (entget (car GRP)))
    89. (foreach ITM GDATA ; step through the edata
    90. (if (and
    91. (= (car ITM) 340) ; if the item is a entity name
    92. (eq (setq NAM (cdr ITM)) ENT) ; and the ename being looked for
    93. )
    94. (setq NLST ; store the ename and name
    95. (if NLST
    96. (append NLST (list (cons (car GRP) (cdr GRP))))
    97. (list (cons (car GRP) (cdr GRP)))
    98. )
    99. )
    100. )
    101. )
    102. )
    103. )
    104. )
    105. NLST
    106. )
    107. ; ----------------------------------------------------------------
    108. ; MAIN PROGRAM
    109. ; ----------------------------------------------------------------
    110. (if (and ; Are we in plan view?
    111. (equal (car (getvar "viewdir")) 0 0.00001)
    112. (equal (cadr (getvar "viewdir")) 0 0.00001)
    113. (> (caddr (getvar "viewdir")) 0)
    114. )
    115. (progn
    116. (prompt "\nSelect text to be EXPLODED: ")
    117. (Setq FLTR '((-4 . "<AND")
    118. (-4 . "<OR") ; filter for mtext and text
    119. (0 . "MTEXT")
    120. (0 . "TEXT")
    121. (-4 . "OR>")
    122. (-4 . "<NOT")
    123. (102 . "{ACAD_REACTORS") ; and not leader text
    124. (-4 . "NOT>")
    125. (-4 . "AND>")
    126. )
    127. GLST (acet-txtexp-grplst) ; Get all the groups in drawing
    128. GDICT (if GLST
    129. (dictsearch (namedobjdict) "ACAD_GROUP")
    130. )
    131. SS (ssget FLTR)
    132. CNT 0
    133. )
    134. ;; filter out the locked layers
    135. (if SS
    136. (setq SS (car (bns_ss_mod SS 1 T)))
    137. ) ;if
    138. ;; if we have anything left
    139. (if SS
    140. (progn
    141. (setq CNT 0) ; Reset counter
    142. (while (setq ENT (ssname SS CNT)) ; step through each object in set
    143. (and
    144. GLST ; if groups are present in the drawing
    145. (setq GNAM (acet-txtexp-getgname ENT GLST)) ; and the text item is in one or more
    146. (foreach GRP GNAM ; step through those groups
    147. (command "_.-group" "_r" ; and remove the text item
    148. (cdr GRP) ENT ""
    149. )
    150. )
    151. )
    152. (setq TBX (acet-geom-textbox (entget ENT) 0)) ; get textbox points
    153. (setq TBX (mapcar '(lambda (x)
    154. (trans x 1 0) ; convert the points to WCS
    155. )
    156. TBX
    157. )
    158. )
    159. (setq PTLST (append PTLST TBX)) ; Build list of bounding box
    160. ; points for text items selected
    161. (setq CNT (1+ CNT)) ; get the next text item
    162. ); while
    163. (setq PTLST (mapcar '(lambda (x)
    164. (trans x 0 1) ; convert all the points
    165. ) ; to the current ucs
    166. PTLST
    167. )
    168. )
    169. (if (setq ZM (acet-geom-zoom-for-select PTLST)) ; If current view does not contain
    170. (progn ; all bounding box points
    171. (setq ZM
    172. (list
    173. (list (- (caar ZM) (acet-geom-pixel-unit)) ; increase zoom area by
    174. (- (cadar ZM) (acet-geom-pixel-unit)) ; one pixel width to
    175. (caddar ZM) ; sure nothing will be lost
    176. )
    177. (list (+ (caadr ZM) (acet-geom-pixel-unit))
    178. (+ (cadadr ZM) (acet-geom-pixel-unit))
    179. (caddr (cadr zm))
    180. )
    181. )
    182. )
    183. (if (setq vpna (acet-currentviewport-ename))
    184. (setq vplocked (acet-viewport-lock-set vpna nil))
    185. );if
    186. (command "_.zoom" "_w" (car ZM) (cadr ZM)) ; zoom to include text objects
    187. )
    188. )
    189. (setq VIEW (acet-geom-view-points)
    190. TMPFIL (strcat (getvar "tempprefix") "txtexp.wmf")
    191. PT1 (acet-geom-midpoint (car view) (cadr view))
    192. PT2 (list (car PT1) (cadadr VIEW))
    193. )
    194. (if (acet-layer-locked (getvar "clayer")) ; if current layer is locked
    195. (progn
    196. (command "_.layer" "_unl" (getvar "clayer") "") ; unlock it
    197. (setq LOCKED T)
    198. )
    199. )
    200. (command "_.mirror" SS "" PT1 PT2 "_y"
    201. "_.WMFOUT" TMPFIL SS "")
    202. (if (findfile tmpfil) ; Does WMF file exist?
    203. (progn
    204. (command "_.ERASE" SS "") ; erase the orignal text
    205. (setq ss (acet-wmfin TMPFIL)) ; insert the WMF file
    206. (command "_.mirror" ss "" PT1 PT2 "_y")
    207. ) ;progn
    208. ) ;if
    209. (if LOCKED
    210. (command "_.layer" "_lock" (getvar "clayer") "") ; relock if needed
    211. ) ;if
    212. (if ZM (command "_.zoom" "_p")) ; Restore original view if needed
    213. (if vplocked
    214. (acet-viewport-lock-set vpna T) ;re-lock the viewport if needed.
    215. );if
    216. (prompt (acet-str-format "\n%1 text object(s) have been exploded to lines." CNT))
    217. (prompt "\nThe line objects have been placed on layer 0.")
    218. )
    219. )
    220. )
    221. (prompt "\nView needs to be in plan (0 0 1).")
    222. );if equal
    223. (acet-error-restore) ; Retsore values
    224. (princ)
    225. )
    226. (princ "txtexp")
    227. (princ)