Explode Line Type, lisp modification (text should not get mirrored)

Explode Line Type, lisp modification (text should not get mirrored)

Anonymous
Not applicable
2,441 Views
7 Replies
Message 1 of 8

Explode Line Type, lisp modification (text should not get mirrored)

Anonymous
Not applicable

Dear Helpers,

 

I gota lisp code that can explode selected line types, But the output text is getting mirroring. Please see attachments.

I need the exploded text as it is by using the new lisp code. Thank you in advance.

(defun c:linexp (/ grplst getgname blknm FLTR GLST GDICT SS VIEW UPLFT TMPFIL TBX
                   TMPFIL CNT PT1 PT2 ENT TXT TXTYP PTLST ZM LOCKED GNAM vpna vplocked)
  (acet-error-init
        (list
         (list   "cmdecho" 0
                 "highlight" 1
                 "osmode" 0
                 "Mirrtext" 1
                 "limcheck" 0
         )
         T
        )
  )
 
; --------------------- GROUP LIST FUNCTION ----------------------
;   This function will return a list of all the group names in the
;   drawing and their entity names in the form:
;   ((<ename1> . <name1>) ... (<enamex> . <namex>))
; ----------------------------------------------------------------
 
  (defun acet-txtexp-grplst (/ GRP ITM NAM ENT GLST)
 
    (setq GRP  (dictsearch (namedobjdict) "ACAD_GROUP"))
    (while (setq ITM (car GRP))       ; While edata item is available
      (if (= (car ITM) 3)             ; if the item is a group name
        (setq NAM (cdr ITM)           ; get the name
              GRP (cdr GRP)           ; shorten the edata
              ITM (car GRP)           ; get the next item
              ENT (cdr ITM)           ; which is the ename
              GRP (cdr GRP)           ; shorten the edata
              GLST                    ; store the ename and name
                  (if GLST
                    (append GLST (list (cons ENT NAM)))
                    (list (cons ENT NAM))
                  )
        )
        (setq GRP (cdr GRP))          ; else shorten the edata
      )
    )
    GLST                              ; return the list
  )
 
; ------------------- GET GROUP NAME FUNCTION --------------------
;   This function returns a list of all the group names in GLST
;   where ENT is a member. The list has the same form as GLST
; ----------------------------------------------------------------
 
  (defun acet-txtexp-getgname (ENT GLST / GRP GDATA NAM NLST)
    (if (and GLST (listp GLST))
      (progn
        (foreach GRP GLST
          (setq GDATA (entget (car GRP)))
          (foreach ITM GDATA                   ; step through the edata
            (if (and
                  (= (car ITM) 340)            ; if the item is a entity name
                  (eq (setq NAM (cdr ITM)) ENT) ; and the ename being looked for
                )
              (setq NLST                       ; store the ename and name
                      (if NLST
                        (append NLST (list (cons (car GRP) (cdr GRP))))
                        (list (cons (car GRP) (cdr GRP)))
                      )
              )
            )
          )
        )
      )
    )
    NLST
  )
 
; ----------------------------------------------------------------
;                          MAIN PROGRAM
; ----------------------------------------------------------------
 
  (if (and                                                ; Are we in plan view?
        (equal (car (getvar "viewdir")) 0 0.00001)
        (equal (cadr (getvar "viewdir")) 0 0.00001)
        (> (caddr (getvar "viewdir")) 0)
      )
 
    (progn
 
      (prompt "\nSelect lines to be EXPLODED: ")
 
      (Setq FLTR    '((-4 . "<AND")
                        (-4 . "<OR")                      ; filter for mtext and text
                          (0 . "MTEXT")
                          (0 . "TEXT")
                        (-4 . "OR>")
                        (-4 . "<NOT")
                          (102 . "{ACAD_REACTORS")        ; and not leader text
                        (-4 . "NOT>")
                      (-4 . "AND>")
                     )
            GLST     (acet-txtexp-grplst)                             ; Get all the groups in drawing
            GDICT    (if GLST
                       (dictsearch (namedobjdict) "ACAD_GROUP")
                     )
            SS       (ssget);  FLTR)
            CNT      0
      )
      ;; filter out the locked layers
      (if SS
        (setq SS (car (bns_ss_mod SS 1 T)))
      ) ;if
 
      ;; if we have anything left
      (if SS
        (progn
          (setq CNT 0)                                 ; Reset counter
          (while (setq ENT (ssname SS CNT))            ; step through each object in set
 
            (and
              GLST                                     ; if groups are present in the drawing
              (setq GNAM (acet-txtexp-getgname ENT GLST))          ; and the text item is in one or more
              (foreach GRP GNAM                        ; step through those groups
                (command "_.-group" "_r"               ; and remove the text item
                  (cdr GRP) ENT ""
                )
              )
            )
 
            (setq TBX (acet-geom-textbox (entget ENT) 0))   ; get textbox points
 
            (setq TBX (mapcar '(lambda (x)
                                 (trans x 1 0)         ; convert the points to WCS
                               )
                        TBX
                      )
            )
 
            (setq PTLST (append PTLST TBX))            ; Build list of bounding box
                                                       ; points for text items selected
 
            (setq CNT (1+ CNT))                        ; get the next text item
          ); while
 
          (setq PTLST (mapcar '(lambda (x)
                                 (trans x 0 1)         ; convert all the points
                               )                       ; to the current ucs
                      PTLST
                    )
          )
 
          (if (setq ZM (acet-geom-zoom-for-select PTLST))          ; If current view does not contain
            (progn                                     ; all bounding box points
              (setq ZM
                (list
                  (list (- (caar ZM) (acet-geom-pixel-unit))     ; increase zoom area by
                        (- (cadar ZM) (acet-geom-pixel-unit))    ; one pixel width to
                        (caddar ZM)                    ; sure nothing will be lost
                  )
                  (list (+ (caadr ZM) (acet-geom-pixel-unit))
                        (+ (cadadr ZM) (acet-geom-pixel-unit))
                        (caddr (cadr zm))
                  )
                )
              )
              (if (setq vpna (acet-currentviewport-ename))
                  (setq vplocked (acet-viewport-lock-set vpna nil))
              );if
              (command "_.zoom" "_w" (car ZM) (cadr ZM))  ; zoom to include text objects
            )
          )
 
          (setq VIEW     (acet-geom-view-points)
                TMPFIL   (strcat (getvar "tempprefix") "txtexp.wmf")
                PT1      (acet-geom-midpoint (car view) (cadr view))
                PT2      (list (car PT1) (cadadr VIEW))
          )
 
          (if (acet-layer-locked (getvar "clayer"))       ; if current layer is locked
            (progn
              (command "_.layer" "_unl" (getvar "clayer") "")  ; unlock it
              (setq LOCKED T)
            )
          )
 
          (command "_.mirror" SS "" PT1 PT2 "_y"
                   "_.WMFOUT" TMPFIL SS "")
 
          (if (findfile tmpfil)                           ; Does WMF file exist?
            (progn
              (command "_.ERASE" SS "")                   ; erase the orignal text
              (setq ss (acet-wmfin TMPFIL))               ; insert the WMF file
              (command "_.mirror" ss "" PT1 PT2 "_y")
            ) ;progn
          ) ;if
 
 
          (if LOCKED
            (command "_.layer" "_lock" (getvar "clayer") "") ; relock if needed
          ) ;if
 
          (if ZM (command "_.zoom" "_p"))              ; Restore original view if needed
          (if vplocked 
              (acet-viewport-lock-set vpna T) ;re-lock the viewport if needed.
          );if
          (prompt (acet-str-format "\n%1 object(s) have been exploded to lines."  CNT))
          (prompt "\nThe line objects have been placed on layer 0.")
        )
      )
    )
    (prompt "\nView needs to be in plan (0 0 1).")
  );if equal
  (acet-error-restore)                                  ; Retsore values
  (princ)
)


(princ)
0 Likes
Accepted solutions (1)
2,442 Views
7 Replies
Replies (7)
Message 2 of 8

roland.r71
Collaborator
Collaborator

This is a (modified version of ?) ExpressTool TXTEXP.

 

Ment for "exploding" TEXT entities to polylines. the mirroring is needed for exporting it to wmf data as lines, not text. (if text(style) width is set to 1, it exports as text, not lines)

 

After importing the wmf data, the text-lines are mirrored back.

 

This code was written specifically to explode text to lines, nothing else.

To explode linetypes, I would suggest using something completely different.

 

So, I'm not going to burn my fingers on this. (but maybe somebody else will)

 

edit:

reading and rereading your post, I'm not sure what exactly you wish to do, but if it's to explode text entities, just use the (original) txtexp expresstool.

Message 3 of 8

Anonymous
Not applicable

sIR,

txtexp will work only for text explode, not for "line type explodes". Please see attached dwg and snapshot. I hope you understood my requirement.

 

0 Likes
Message 4 of 8

dbhunia
Advisor
Advisor
Accepted solution

Hi

 

change this......

 

.................
.................
(command "_.mirror" SS "" PT1 PT2 "_y" "_.WMFOUT" TMPFIL SS "") (if (findfile tmpfil) ; Does WMF file exist? (progn (command "_.ERASE" SS "") ; erase the orignal text (setq ss (acet-wmfin TMPFIL)) ; insert the WMF file (command "_.mirror" ss "" PT1 PT2 "_y") ) ;progn ) ;if
.................
.................

to

 

.....................
....................
        ;(command "_.mirror" SS "" PT1 PT2 "_y")
(command "_.WMFOUT" TMPFIL SS "")

(if (findfile tmpfil) ; Does WMF file exist?
(progn
(command "_.ERASE" SS "") ; erase the orignal text
(setq ss (acet-wmfin TMPFIL)) ; insert the WMF file
;(command "_.mirror" ss "" PT1 PT2 "_y")
) ;progn
) ;if .................... .....................

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 5 of 8

Anonymous
Not applicable

Hi Sir,

 

It's almost reached except moving of all lines to other location and text rotation is falling at 180 degrees.

 

Please have look on attached image and dwg.

0 Likes
Message 6 of 8

roland.r71
Collaborator
Collaborator

@Anonymous wrote:

sIR,

txtexp will work only for text explode, not for "line type explodes". Please see attached dwg and snapshot. I hope you understood my requirement.

 


 

Yep. & this goes the other way around. txtexp is not suited for exploding linetypes.

sure you can modify it, but that's not what you should do. (& i won't)

 

BUT, check this code (as example):

(defun c:ltExp ()
   (if (setq ss (ssget "_I"))                                  ; Get active selection
      (progn
         (setq wmf (strcat (getvar "tempprefix") "ltExp.wmf")) ; set filename for wmf export
         (command "_.WMFOUT" wmf ss ""                         ; export to wmf
                  "_.ERASE" ss ""                              ; erase the selection
         )
         (setq ss (acet-wmfin wmf))                            ; insert the WMF file
         (command "_.convertpoly" "_light" ss "")              ; fix polyline results
      )
   )
)

This is almost all you need. (compare that to the txtExp Smiley Wink )

The only thing missing, & i'm still slightly at a loss to the exact solution is the position & scale.

 

I used an almost exact same method for my txtHalo, except that that's for text and it uses the mirroring to explode the text to lines (instead of it remaining text) but it that case the wmf import has the same position and scale, but with the code above it pops up at a different location and way smaller in scale.

 

But, the linetypes get converted and the text is normal.

 

edit:

the fix for the polylines turns the "2D Polyline" form the WMF import into "polyline"

0 Likes
Message 7 of 8

Anonymous
Not applicable

But not working with the attached file. Please check.

0 Likes
Message 8 of 8

TomBeauford
Advisor
Advisor

This is what I've used for years for linetypes in block definitions: https://forums.augi.com/showthread.php?168975-Explode-Linetypes

64bit AutoCAD Map & Civil 3D 2023
Architecture Engineering & Construction Collection
2023
Windows 10 Dell i7-12850HX 2.1 Ghz 12GB NVIDIA RTX A3000 12GB Graphics Adapter
0 Likes