Author Topic: Dtext break mark  (Read 3272 times)

0 Members and 1 Guest are viewing this topic.

GDF

  • Water Moccasin
  • Posts: 2081
Dtext break mark
« on: June 27, 2019, 12:36:33 PM »
I'm looking to break a dtext string other than finding a (wcmatch TXTX "*`,*") marker. I would like to be able to break the inserted dtext string at every tenth word if possible.

(BTX-IT) is a break dtext routine. My routine reads a text file for selecting the dtext to place in the drawing.


(setq TXTX (cdr (assoc 1 (entget (entlast)))))
(if (wcmatch TXTX "*`,*")(BTX-IT))

Any thoughts?
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Dtext break mark
« Reply #1 on: June 27, 2019, 01:03:28 PM »
Search for every tenth (chr 160) blank space, for example?

How would I do a counter for every tenth space?
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Dtext break mark
« Reply #2 on: June 27, 2019, 01:06:09 PM »
Code - Auto/Visual Lisp: [Select]
  1. ;;  Breaks a string at spaces (if possible) into a list of    ;;
  2. ;;  substrings of a specified length or less.                 ;;
  3. ;;------------------------------------------------------------;;
  4. ;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
  5. ;;------------------------------------------------------------;;
  6. ;;  Arguments:                                                ;;
  7. ;;  str - String to wrap to a specific length                 ;;
  8. ;;  len - Maximum length of each substring                    ;;
  9. ;;------------------------------------------------------------;;
  10. ;;  Returns:  List of substrings of specified length or less  ;;
  11. ;;------------------------------------------------------------;;
  12.  
  13. (defun LM:StringWrap ( str len / pos )
  14.     (if (< len (strlen str))
  15.         (cons
  16.             (substr str 1
  17.                 (cond
  18.                     (   (setq pos (vl-string-position 32 (substr str 1 len) nil t)))
  19.                     (   (setq pos (1- len)) len)
  20.                 )
  21.             )
  22.             (LM:StringWrap (substr str (+ 2 pos)) len)
  23.         )
  24.         (list str)
  25.     )
  26. )
  27.  
  28.  
  29. (LM:StringWrap "This is a very long string which needs to be wrapped." 20)
  30.  
  31. ("This is a very long" "string which needs" "to be wrapped.")
« Last Edit: June 27, 2019, 03:25:26 PM by John Kaul (Se7en) »
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Dlanor

  • Bull Frog
  • Posts: 263
Re: Dtext break mark
« Reply #3 on: June 27, 2019, 01:11:55 PM »
Code - Auto/Visual Lisp: [Select]
  1. (defun strsplit10 (txt)
  2.   (while (> (strlen txt) 10)
  3.     (setq lst (cons (substr txt 1 10) lst)
  4.           txt (substr txt 11)
  5.     )
  6.   )
  7.   (setq lst (reverse (cons txt lst)))
  8. )


GDF

  • Water Moccasin
  • Posts: 2081
Re: Dtext break mark
« Reply #4 on: June 27, 2019, 01:41:41 PM »
Thank you sir!

Code - Auto/Visual Lisp: [Select]
  1. (defun strsplit40 (txt)
  2.   (while (> (strlen txt) 40)
  3.     (setq lst (cons (substr txt 1 40) lst)
  4.           txt (substr txt 41)
  5.     )
  6.   )
  7.   (setq lst (reverse (cons txt lst)))
  8. )
  9.  
  10.  
  11. (setq TXTX (cdr (assoc 1 (entget (entlast)))))
  12. (if (strsplit40 TXTX)(BTX-IT))

Thanks...now how do I break every 40th until the (setq TXTX (cdr (assoc 1 (entget (entlast)))))
has run it's cycle. For example, a very long dtext string?
« Last Edit: June 27, 2019, 03:25:42 PM by John Kaul (Se7en) »
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Dlanor

  • Bull Frog
  • Posts: 263
Re: Dtext break mark
« Reply #5 on: June 27, 2019, 02:16:06 PM »
It will continue to run until the string length is < 40, and then adds the remainer to the list. The returned list, is a list of the string split into chunks of 40 characters.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Dtext break mark
« Reply #6 on: June 27, 2019, 02:47:53 PM »
Got it...Thanks.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Dtext break mark
« Reply #7 on: June 28, 2019, 11:36:28 AM »
I'm trying another approach:
Using Lee's code above, how would I use the text command to place the text?


This example is for two strings: text string one and then on to the next line for text string two...and so on...

(command ".text" pause "" "" (car (LM:StringWrap (cdr (assoc 1 (entget (entlast)))) 40)) "" (cdr (LM:StringWrap (cdr (assoc 1 (entget (entlast)))) 40)))

And what if I don't know the number of text strings; and how would I test this?
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Dtext break mark
« Reply #8 on: June 28, 2019, 01:21:51 PM »
I would suggest using a foreach loop and entmake'ing the text objects, e.g.:

Code - Auto/Visual Lisp: [Select]
  1. (setq p '(0 0 0))
  2. (foreach s (LM:StringWrap (cdr (assoc 1 (entget (entlast)))) 40)
  3.     (entmake
  4.         (list
  5.            '(000 . "TEXT")
  6.             (cons 040 (getvar 'textsize))
  7.             (cons 010 p)
  8.             (cons 001 s)
  9.         )
  10.     )
  11.     (setq p (polar p (* 1.5 pi) (* 1.7 (getvar 'textsize))))
  12. )

GDF

  • Water Moccasin
  • Posts: 2081
Re: Dtext break mark
« Reply #9 on: June 28, 2019, 03:12:13 PM »
Thanks Lee

That is exactly what I needed. I Just did not know how to code it. My knowledge stopped at foreach...
« Last Edit: July 16, 2019, 11:13:15 AM by GDF »
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Dtext break mark
« Reply #10 on: June 29, 2019, 11:46:37 AM »
Now I can switch between using dtext or mtext for inserting a text string from the dialog list box. The dialog box routine reads the enclosed text file.
I no longer have to use the code:
    (setq TXTX (cdr (assoc 1 (entget (entlast)))))
    (if (wcmatch TXTX "*`,*")(BTX-IT))

The (BTX-IT) was a routine that breaks a text file by fing a comma for the break point within the string.
I have now removed all of the "*`,*" in the text file; so that the dtext and mtext can be used without the "*`,*" showing up in the inserted string.

;;;Break text (BTX-IT)
;;;written: Andrzej GUMULA     agumula@transprojekt.com.pl
;;;
;;;modified by Tim Willey
;;;What he did was put the whole (main) function in condition with the
;;;while function, so while you select something it will work

That you Lee for solving my problem.
ARCH#NOTE is the selected sting read from the text file: ARCH_ANNO-CUS.rem

Code: [Select]
(defun c:test (/ s pnt num)
  (setq pnt (getpoint "\n* Pick Text Insetion Point..."))
  (setq num (getreal "\n* Select Text String Length: [30 40 50]"))
  (if (= num nil)(setq num 30))
  ;;(setq pnt '(0 0 0)) 
  (foreach s (LM:StringWrap ARCH#NOTE num)
    (entmake
        (list
           '(000 . "TEXT")
            (cons 040 (getvar 'textsize))
            (cons 007 (getvar 'textstyle))
            ;(cons 041 0.7)
            (cons 010 pnt)
            (cons 001 s)
        )
    )
    (setq pnt (polar pnt (* 1.5 pi) (* 1.7 (getvar 'textsize))))
  )
  (princ)
)
« Last Edit: July 16, 2019, 11:14:15 AM by GDF »
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Dtext break mark
« Reply #11 on: July 16, 2019, 11:12:35 AM »
Modified the anno dialog box, adding the dtext spacing edit_box.


Thanks again for the help.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64