Author Topic: Repeating the (entupd + entmod + subst ) two or three times in a routine  (Read 3884 times)

0 Members and 1 Guest are viewing this topic.

Coder

  • Swamp Rat
  • Posts: 827
Hello .

Why the following codes in RED are not working well ? and what is the best way to do it ?

Code: [Select]
(setq ss (ssget '((0 . "TEXT,Mtext"))))
     ((lambda ( n / *ss entities )
(while
  (setq *ss (ssname ss (setq n (1+ n))))
   (setq entities (entget *ss))
         [color=red]  (entupd (cdr (assoc -1 (entmod (subst (cons 8 "Texts")(assoc 8 entities) entities )))))
  (entupd (cdr (assoc -1 (entmod (subst (cons 71 1) (assoc 71 entities) entities )))))[/color]
            )
      )
       -1
       )
         

Thanks

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Repeating the (entupd + entmod + subst ) two or three times in a routine
« Reply #1 on: February 09, 2011, 10:09:29 AM »
After updating the Layer value [DXF 8] in the 'entities' DXF List, you are using the original list containing the old Layer value when updating the Text Generation Flag (in Text) or the Attachment Point (in MText) - Note that DXF 71 means different things for Text & MText!

Hence, since the original DXF Data is used, the Layer value is updated back to its original value.
« Last Edit: February 09, 2011, 10:14:56 AM by Lee Mac »

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Repeating the (entupd + entmod + subst ) two or three times in a routine
« Reply #2 on: February 09, 2011, 10:13:54 AM »
Consider this code as an example:

Code: [Select]
(if (setq ss (ssget "_:L" '((0 . "MTEXT"))))

  (repeat (setq i (sslength ss))
   
    (setq
      elist (entget (ssname ss (setq i (1- i))))
      elist (subst (cons 8 "Texts") (assoc 8 elist) elist)
      elist (subst (cons 71 1) (assoc 71 elist) elist)
    )

    (entupd (cdr (assoc -1 (entmod elist))))
  )
)

For clarity of my method, I have removed 'Text' from the ssget filter list. If you want to change the alignment of Text & MText you will need to include a conditional within the loop.

Lee
« Last Edit: February 09, 2011, 10:18:38 AM by Lee Mac »

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Repeating the (entupd + entmod + subst ) two or three times in a routine
« Reply #3 on: February 09, 2011, 10:36:49 AM »
Little sub help...

Code: [Select]
(defun _Subst (dottedpair entitylist)
  (subst dottedpair (assoc (car dottedpair) entitylist) entitylist)
)


(if (setq ss (ssget "_:L" '((0 . "MTEXT"))))
  (repeat (setq i (sslength ss))
    (entupd (cdr (assoc -1
                        (entmod
                          (_Subst '(8 . "Texts")
                                  (_Subst '(71 . 1)
                                          (entget (ssname ss (setq i (1- i))))
                                  )
                          )
                        )
                 )
            )
    )
  )
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Repeating the (entupd + entmod + subst ) two or three times in a routine
« Reply #4 on: February 09, 2011, 10:38:26 AM »
To account for the Text/MText issue..

Code: [Select]
(defun c:test ( / _subst ss i elist )

  (defun _subst ( code value elist )
    (subst (cons code value) (assoc code elist) elist)
  )

  (if (setq ss (ssget "_:L" '((0 . "TEXT,MTEXT"))))

    (repeat (setq i (sslength ss))
     
      (setq elist (entget (ssname ss (setq i (1- i))))
            elist (_subst 8 "Texts" elist)
      )
      (if (eq "TEXT" (cdr (assoc 0 elist)))
       
        (setq elist (if (and (= 0 (cdr (assoc 72 elist)))
                             (= 0 (cdr (assoc 73 elist)))
                        )
                      (_subst 11 (cdr (assoc 10 elist)) elist)
                      elist
                     )   
              elist (_subst 72 0 elist)
              elist (_subst 73 3 elist)
        )
        (setq elist (_subst 71 1 elist))
      )
      (entupd (cdr (assoc -1 (entmod elist))))
    )
  )
 
  (princ)
)

Coder

  • Swamp Rat
  • Posts: 827
Re: Repeating the (entupd + entmod + subst ) two or three times in a routine
« Reply #5 on: February 09, 2011, 01:44:22 PM »
Thank you Lee and Alanjt .

These examples are very helpful .

Appreciated.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Repeating the (entupd + entmod + subst ) two or three times in a routine
« Reply #6 on: February 09, 2011, 03:43:59 PM »
You're welcome Coder, happy I could be of help  :-)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Repeating the (entupd + entmod + subst ) two or three times in a routine
« Reply #7 on: February 09, 2011, 03:48:53 PM »
You're welcome Coder, happy I could be of help  :-)
x2
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox