Author Topic: Move a line of text in a block (nested text)  (Read 1338 times)

0 Members and 1 Guest are viewing this topic.

bilançikur

  • Newt
  • Posts: 82
Move a line of text in a block (nested text)
« on: April 18, 2023, 09:54:32 AM »
Hello to all,

A little intro first:
This very block called "blk_01" contains 4 lines of (seperate) texts (not mtexts), the text is an adress, the adress of our company.
Besides that there are many attributes but lets skip those.

There is this lisp routine that reads out these four lines and if one of the lines contains an old adress it is automatically updated to the new one.
The routine may be found here: https://www.cadtutor.net/forum/topic/28813-change-text-inside-blocks/#comment-479967.
All credits go to Lee Mac.

An easy program to update adresses in a titleblock in case the company has moved.
Now everytime a drawing is opened the titleblocks update to the new adress.

Question:
Would it be possible to move these 4 lines to the left, like 7.5mm ??

Let me explain the problem I fear: everytime the drawing opens the lines moves 7.5mm to the left...
So the first time it is a success but the second time (and every time after that one) the lines move to the left and in the end they fall of the earths crust :-)

Any thoughts on this ??

And if so, what would be the best way? I know of nentsel properties and how to retrieve the insertionpoint(s) but I am not aware of how to push these data into the block to change the text-insertionpoints.

Thanks and have a nice day!

kozmos

  • Newt
  • Posts: 115
Re: Move a line of text in a block (nested text)
« Reply #1 on: April 18, 2023, 10:15:29 AM »
You can add a ldata to the block definition after the very first time move the lines, also update the progeam to check if the ldata exist and only move lines when the ldata is not there.
KozMos Inc.

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Move a line of text in a block (nested text)
« Reply #2 on: April 18, 2023, 06:09:04 PM »
Consider something like this -
Code - Auto/Visual Lisp: [Select]
  1. (defun c:txtmov ( / bln ent enx key vec xda )
  2.    
  3.     (setq bln "blk_01"         ;; Target block
  4.           vec '(-7.5 0.0 0.0)  ;; Displacement vector
  5.           xda "LMAC_txtmov"    ;; xData application
  6.     )
  7.     (cond
  8.         (   (not (setq ent (tblobjname "block" bln)))
  9.             (princ "\nBlock not found.")
  10.         )
  11.         (   (assoc -3 (entget ent (list xda)))
  12.             (princ "\nText already moved.")
  13.         )
  14.         (   t
  15.             (regapp xda)
  16.             (entmod (list (cons -1 ent) (list -3 (cons xda '((1002 . "{") (1070 . 1) (1002 . "}"))))))
  17.  
  18.             (while (setq ent (entnext ent))
  19.                 (if (= "TEXT" (cdr (assoc 0 (setq enx (entget ent)))))
  20.                     (progn
  21.                         (setq key (if (= 0 (cdr (assoc 72 enx)) (cdr (assoc 73 enx))) 10 11))
  22.                         (entmod
  23.                             (subst
  24.                                 (cons  key (mapcar '+ (cdr (assoc key enx)) vec))
  25.                                 (assoc key enx)
  26.                                 enx
  27.                             )
  28.                         )
  29.                     )
  30.                 )
  31.             )
  32.             (command "_.regenall")
  33.             (princ "\nBlock modified.")
  34.         )
  35.     )
  36.     (princ)
  37. )

(I prefer xdata over ldata; MP once advised the latter could lead to corrupted drawings)

bilançikur

  • Newt
  • Posts: 82
Re: Move a line of text in a block (nested text)
« Reply #3 on: April 19, 2023, 10:03:28 AM »
Thanks Kozmos and Lee Maac!

@Lee: this is a few steps above my skills, I cannot read your cody in full but it seems to me that this code checks weather the bloack has already gotten the xdata or not. I have no clue how to put things together, like how the line of text would be moved.

Maybe if you have an idea? But no obligations, hey the sun is shining  :-)

BIGAL

  • Swamp Rat
  • Posts: 1434
  • 40 + years of using Autocad
Re: Move a line of text in a block (nested text)
« Reply #4 on: April 19, 2023, 09:50:54 PM »
Just a question, as the move is say 7.5 to right, would not just get text xy of atts and check X value if not say xxx.0 then update to correct X value.

Maybe also add a ldata "yesblockupdated" "Fixed Date" so no need to actually check the block if done already.

Code: [Select]
(defun blktmove ( / ah:bmove bln)

(defun ah:bmove (bname / ss ent entpt ptx pty)
(command "-bedit" bname)
(setq ss (ssget "X" '((0 . "TEXT"))))
(repeat (setq x (sslength ss))
  (setq ent (entget (ssname ss (setq x (1- x)))))
  (setq entpt (cdr (assoc 10 ent)))
  (setq ptx (car entpt))
  (setq pty (cadr entpt))
  (if (/= ptx 7.5)
    (entmod (subst (cons 10 (list 7.5 pty 0.0))(assoc 10 ent) ent))
  )
)
(command "bclose" "save")
(vlax-ldata-put "BLK_01" "Date" "April23")
(command "regen")
(princ "\nBlock blk_01 updated ")
(princ)
)


(setq bln "blk_01")
(cond
   ( (not (setq entb (tblobjname "block" bln))) (princ "\nBlock not found."))
   ( (not (vlax-ldata-get "BLK_01" "Date")) (aH:bmove bln))
   ( (princ "\nText already moved."))
)

(princ)
)
(blktmove)
« Last Edit: April 19, 2023, 10:49:30 PM by BIGAL »
A man who never made a mistake never made anything

Lee Mac

  • Seagull
  • Posts: 12928
  • London, England
Re: Move a line of text in a block (nested text)
« Reply #5 on: April 20, 2023, 01:06:54 PM »
@Lee: this is a few steps above my skills, I cannot read your cody in full but it seems to me that this code checks weather the bloack has already gotten the xdata or not. I have no clue how to put things together, like how the line of text would be moved.

The example I posted does everything you require: it checks whether the target block definition already contains the xdata flag; if so, the program exits; else, it iterates over the block components and moves all single-line text objects by the given displacement vector [currently (-7.5 0.0 0.0)], and adds the xdata flag to the block definition.

bilançikur

  • Newt
  • Posts: 82
Re: Move a line of text in a block (nested text)
« Reply #6 on: May 02, 2023, 04:19:30 AM »
Thank you Lee for the information provided.