explode command and qaflags at 0 still does not work

explode command and qaflags at 0 still does not work

DGRL
Advisor Advisor
1,560 Views
13 Replies
Message 1 of 14

explode command and qaflags at 0 still does not work

DGRL
Advisor
Advisor

Deare Coders,

 

I have a small routine that select all entities in a block
Then filter out what is needed ( in this case MTEXT with field)

I end up with a (-1 . <Entity name: 7ffff921040>)  and want to explode this.
Though it does not work and I cant figure out why

Code below

 

ent11 is a list
(<Entity name: 7ffff920920> <Entity name: 7ffff920930> <Entity name: 7ffff920940> <Entity name: 7ffff920950> <Entity name: 7ffff920960> <Entity name: 7ffff920970> <Entity name: 7ffff920980> <Entity name: 7ffff920990> <Entity name: 7ffff9209a0> <Entity name: 7ffff9209b0> <Entity name: 7ffff9209c0> <Entity name: 7ffff9209d0> <Entity name: 7ffff9209e0> <Entity name: 7ffff9209f0> <Entity name: 7ffff920a00> <Entity name: 7ffff920a10> <Entity name: 7ffff920a20> <Entity name: 7ffff920a30> <Entity name: 7ffff920a40> <Entity name: 7ffff920a50> <Entity name: 7ffff920a60> <Entity name: 7ffff920a70> <Entity name: 7ffff920a80> <Entity name: 7ffff920a90> <Entity name: 7ffff920ae0> <Entity name: 7ffff920b30> <Entity name: 7ffff920b80> <Entity name: 7ffff920bd0> <Entity name: 7ffff920c20> <Entity name: 7ffff920c70> <Entity name: 7ffff920d10> <Entity name: 7ffff920d60> <Entity name: 7ffff920db0> <Entity name: 7ffff920dc0> <Entity name: 7ffff920e60> <Entity name: 7ffff920eb0> <Entity name: 7ffff920f00> <Entity name: 7ffff921030> <Entity name: 7ffff921040>)


 

 

(foreach ent1 ent11 

(setq a (cdadr (entget ent1)))
;(if (= a "MTEXT")(print "YES"))

(setq b ent1)
(setq c (entget b))
;(print c)

(if (= (cdr (assoc 102 c))"{ACAD_XDICTIONARY")
(progn 
(print c)
(setq d (cdr (assoc 330 c)))


(setvar "qaflags" 1)
      (command "_.explode" d "")
(setvar "qaflags" 0)

;(command "explode" c)
;(command "explode" d "")
;(vla-explode b)


(princ)
)
); end if



(princ)
); end foreach

 

I only want to explode text objects containing a field
So I filter them on assoc 102 and after that I want to explode the object

What QAFLAGS code do I need for this?
Or is it not possible?

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Accepted solutions (1)
1,561 Views
13 Replies
Replies (13)
Message 2 of 14

_gile
Consultant
Consultant

Hi,

 

To make things easier for you and those you ask for helping you, please, try to provide cleaner code by removing redundant assignations and useless commented lines, and also by formatting it with some indentation.

 

You should also use more self explanatory variable names so that you avoid trying to explode an extension dictionary....

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 14

DGRL
Advisor
Advisor

Hi

 

 

(foreach ent1 ent11 

(setq ENTITY (entget ent1))
(if (= (cdr (assoc 102 ENTITY ))"{ACAD_XDICTIONARY")

(progn CODE TO EXPLODE WILL NOT POST THE CODES THAT I TRIED );end progn ); end if
(princ) ); end foreach

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 4 of 14

_gile
Consultant
Consultant

Try the following one.

 

I improved the field checking.

It's more reliable to serch for a (102 . "{ACAD_XDICTIONARY") pair because the dxf list might contain other 102 groups as (102 . "{ACAD_REACTORS")

The presence of an extension dictionary is necessary but not sufficient, it is necessary that this dictionary contains an entry named "ACAD_FIELD".

 

(foreach ent1 ent11
  ;; check if the MTEXT contains a field
  (if (and
        ;; get the extension dictionary (if any)
        (setq xdict (cdr (assoc 360 (member '(102 . "{ACAD_XDICTIONARY") (entget ent1)))))
        ;; check if the extension dictionary contains an "ACAD_FIELD" entry
        (dictsearch xdict "ACAD_FIELD")
      )
    (command "_.explode" ent1)
  )
  (princ)
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 5 of 14

DGRL
Advisor
Advisor

@_gile

 

 

When running this I get back:"-->  error _.explode <Bad Entity name: FF93C040>

 

This is the code I use to het the entity name

 

(defun get-block-entities ( blk / ent lst ) 
   
 (if 
        (setq ent (tblobjname "block" blk)) 

        (while (setq ent (entnext ent))

            (setq lst (cons ent lst))

        ) ;; end WHILE
        
    ) ;; end IF
    
    (reverse lst) ;; Return the list
    
) ;; end DEFUN

(setq blk "Titelblok AFS11")
(setq ent11 (get-block-entities blk))

To explode the MTEXT I use yours

 

 

(foreach ent1 ent11

  (if (and

        (setq xdict (cdr (assoc 360 (member '(102 . "{ACAD_XDICTIONARY") (entget ent1)))))

        (dictsearch xdict "ACAD_FIELD")
      )
    (command "_.explode" ent1)
  )
  (princ)
)

 

Thanks for pointing out the other 102 assoc's

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 6 of 14

_gile
Consultant
Consultant

You cannot use command within a block definition.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 7 of 14

DGRL
Advisor
Advisor

@_gile

 

How can I explode the mtext then using LISP
I automatically process my dwg's so I cant open the blocks manually

 

Is it possible to remove pairs from the entity and then append new pairs to make it txt


Like

 

Remove pairs  0 and 102  ((0 . "MTEXT") and (102 . "{ACAD_XDICTIONARY")

Append pair 0 (0 . "TEXT")

 

ENTMAKE this and MTEXT should be TEXT

Might this be a solution?

 

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 8 of 14

_gile
Consultant
Consultant

Try this:

 

(foreach ent1 ent11
  (if (and
        (setq xdict (cdr (assoc 360 (member '(102 . "{ACAD_XDICTIONARY") (entget ent1)))))
        (dictsearch xdict "ACAD_FIELD")
      )
    (progn
      (setq text (vlax-ename->vla-object ent1)
            str  (vla-get-TextString text)
      )
      (vla-put-TextString text "")
      (vla-put-TextString text str)
      (vla-update text)
    )
  )
  (princ)
)

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 9 of 14

DGRL
Advisor
Advisor

@_gile

 

 

 

Thanks 🙂


This just removes the field and leaves it MTEXT

But I am thinking of making a routine that will replace MTEXT for TEXT

maybe I can ENTMAKE text based of cons 10 of the MTEXT

I don't know but I need TEXT instead of MTEXT and I cant process the block manually

 

Doing a (vlax-dump-object ENTITY T) of the mtext object shows me it cant be exploded

Method is not supported

 

; IAcadMText: AutoCAD MText Interface
; Property values:

;   Application (RO) = #<VLA-OBJECT IAcadApplication 000000013f7b3f10>

......

 

; Methods supported:
;   ArrayPolar (3)

......

 

 

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 10 of 14

_gile
Consultant
Consultant

Converting a mtext into a text is not so trivial, DXF groups aren't exactly the same and you have to deal with the text justification which doesn't work the same with texts and mtexts.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 11 of 14

DGRL
Advisor
Advisor

sadly enough I have to process my as build package manually

have more then  750 DWG's in it with over 15000 blocks

 

Wish me luck coz this is going to take a freaking long time

 

I really cant understand that a program like AutoCAD is not even able of doing simple tasks like this
Maybe there is a routine that can convert MTEXT in a BLOCK into ATTRIBUTES

My client accepts either TEXT or ATTRIBUTES and pls do not ask me why

already asked why not MTEXT and they simple say "because we don't want MTEXT to be used"

Seems to be company standard

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 12 of 14

_gile
Consultant
Consultant

You can try this one which should work with single line MTexts (not deeply tested).

 

(defun mtext2text (mtext / elst pt ht just dxf10 dxf11 dxf72 dxf73)
  (setq elst (entget mtext)
        pt   (cdr (assoc 10 elst))
        just (cdr (assoc 71 elst))
  )
  (cond
    ((= just 1)
     (setq dxf72 (cons 72 0)
           dxf73 (cons 73 3)
     )
    )
    ((= just 2)
     (setq dxf72 (cons 72 1)
           dxf73 (cons 73 3)
     )
    )
    ((= just 3)
     (setq dxf72 (cons 72 2)
           dxf73 (cons 73 3)
     )
    )
    ((= just 4)
     (setq dxf72 (cons 72 0)
           dxf73 (cons 73 2)
     )
    )
    ((= just 5)
     (setq dxf72 (cons 72 1)
           dxf73 (cons 73 2)
     )
    )
    ((= just 6)
     (setq dxf72 (cons 72 2)
           dxf73 (cons 73 2)
     )
    )
    ((= just 7)
     (setq dxf72 (cons 72 0)
           dxf73 (cons 73 0)
     )
    )
    ((= just 8)
     (setq dxf72 (cons 72 1)
           dxf73 (cons 73 0)
     )
    )
    ((= just 9)
     (setq dxf72 (cons 72 2)
           dxf73 (cons 73 0)
     )
    )
  )
  (if (= just 7)
    (setq dxf10 (cons 10 pt)
          dxf11 (list 11 0. 0. 0.)
    )
    (setq dxf10 (list 10 0. 0. 0.)
          dxf11 (cons 11 pt)
    )
  )
  (entmake
    (list
      (assoc 8 elst)
      (cons 0 "TEXT")
      dxf10
      (assoc 10 elst)
      (assoc 40 elst)
      (assoc 1 elst)
      (assoc 7 elst)
      (assoc 50 elst)
      dxf11
      dxf72
      (assoc 210 elst)
      dxf73
    )
  )
  (entdel mtext)
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 13 of 14

_gile
Consultant
Consultant
Accepted solution

Oopss...

The code in the previous message only works for mtext in the current space not in block definitions.

 

Use this instead

 

(defun mtext2text (mtext / text just)
  (vl-load-com)
  (or (= (type mtext) 'vla-object)
      (setq mtext (vlax-ename->vla-object mtext))
  )
  (if (= (vla-get-ObjectName mtext) "AcDbMText")
    (progn
      (setq text (vla-AddText
                   (vla-ObjectIdToObject
                     (vla-get-ActiveDocument (vlax-get-acad-object))
                     (vla-get-OwnerId mtext)
                   )
                   (vla-get-TextString mtext)
                   (vla-get-InsertionPoint mtext)
                   (vla-get-Height mtext)
                 )
            just (vla-get-AttachmentPoint mtext)
      )
      (cond
        ((= 1 just)
         (vla-put-Alignment text 6)
         (vla-put-TextAlignmentPoint text (vla-get-InsertionPoint mtext))
        )
        ((= 2 just)
         (vla-put-Alignment text 7)
         (vla-put-TextAlignmentPoint text (vla-get-InsertionPoint mtext))
        )
        ((= 3 just)
         (vla-put-Alignment text 8)
         (vla-put-TextAlignmentPoint text (vla-get-InsertionPoint mtext))
        )
        ((= 4 just)
         (vla-put-Alignment text 9)
         (vla-put-TextAlignmentPoint text (vla-get-InsertionPoint mtext))
        )
        ((= 5 just)
         (vla-put-Alignment text 10)
         (vla-put-TextAlignmentPoint text (vla-get-InsertionPoint mtext))
        )
        ((= 6 just)
         (vla-put-Alignment text 11)
         (vla-put-TextAlignmentPoint text (vla-get-InsertionPoint mtext))
        )
        ((= 7 just)
         (vla-put-Alignment text 0)
        )
        ((= 8 just)
         (vla-put-Alignment text 1)
         (vla-put-TextAlignmentPoint text (vla-get-InsertionPoint mtext))
        )
        ((= 9 just)
         (vla-put-Alignment text 2)
         (vla-put-TextAlignmentPoint text (vla-get-InsertionPoint mtext))
        )
      )
      (foreach prop '(Layer
                      Linetype
                      LinetypeScale
                      Lineweight
                      Material
                      Normal
                      Rotation
                      StyleName
                     )
        (vlax-put-property text prop (vlax-get-property mtext prop))
      )
      (vla-Delete mtext)
    )
  )
  text
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 14 of 14

DGRL
Advisor
Advisor

@_gile

 

 

Good morning

This does the job.

Many many thanks

 

Can I make a donation to you for your time helping and teaching me?

 

Kind regards,

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes