Set Line Spacing in Multi-line text, text styles, or attribute definitions OR modify dozens of inserts w/vlisp

Set Line Spacing in Multi-line text, text styles, or attribute definitions OR modify dozens of inserts w/vlisp

RandyBenson
Advocate Advocate
919 Views
12 Replies
Message 1 of 13

Set Line Spacing in Multi-line text, text styles, or attribute definitions OR modify dozens of inserts w/vlisp

RandyBenson
Advocate
Advocate
Hi all, 
 
I was looking for a way either to set the line spacing in a multiline attribute definition or 
define a text style with an exact line spacing. When I list the attribute definition, one of the lines I can see reads: "Line spacing: Multiple (1x = 0.133)", and I can manually change the spacing in individual block inserts with the mtext editor, but there are too many instances for that to be a solution. Anyone have a way to modify the line spacing of selection sets of block inserts programmatically?
 
 
I spotted this post about the same issue with multiline text from 2001 that got zero replies, so it looks like it's still not possible to define at the style or attdef level with a setting...
<quote>:
Line Spacing in Multi-line text editor
Is it possible to change the default line spacing for the multiline text
editor?

The current default of 1x is 1.66 times the height of the text characters
which is, in my opinion, too much space between lines in a paragraph.

Every time I place text using the multiline text editor I have to change the
spacing to .8x to get it to look good for me. It seems that there should be
a way to change the default so that I don't have to do this every time.
<end quote>
0 Likes
Accepted solutions (2)
920 Views
12 Replies
Replies (12)
Message 2 of 13

Kent1Cooper
Consultant
Consultant

Have you tried [I haven't] BEDITing a Block definition, giving the Attribute the line spacing you want there, and [after Saving changes] ATTSYNCing to apply that to all Insertions of that Block?

Kent Cooper, AIA
0 Likes
Message 3 of 13

RandyBenson
Advocate
Advocate

Hi Kent,

Yep, that's the first thing I tried, but I don't see Line Spacing when I look at the attribute's properties dialog. What am I missing?

0 Likes
Message 4 of 13

ВeekeeCZ
Consultant
Consultant

Did a little bit of digging.

 

Line spacing is a property that belongs only to MTEXT. There are two ways to apply them. Either by setting the text property (there are even two properties LS Factor and LS Distance, somehow bounded), or by using formatting characters inserted directly in the text content. Both ways only afterward, after it was created.

 

Line spacing is not supported by a text style.

 

Rather out of curiosity, formatting characters can be programmatically inserted into a text of multi-line attributes. They will be applied (and printed), but will be deleted by any later manual content editing.

 

 

(defun c:MtextLineSpacing ( / s i)
(if (setq s (ssget "_:L" '((0 . "MTEXT")))) (repeat (setq i (sslength s)) (setpropertyvalue (ssname s (setq i (1- i))) "LineSpacingFactor" 0.8))) (princ) )

 

0 Likes
Message 5 of 13

RandyBenson
Advocate
Advocate

"Line spacing is a property that belongs only to MTEXT. "

 

It also belongs to multiline text in block attributes, and can be individually modified one-at-a-time with the mtext editor.

 

"Rather out of curiosity, formatting characters can be programmatically inserted into a text of multi-line attributes. They will be applied (and printed), but will be deleted by any later manual content editing."

 

That would be acceptable -- how can I do that?

 

 

0 Likes
Message 6 of 13

ВeekeeCZ
Consultant
Consultant
Accepted solution

Ok, try this one.

 

(vl-load-com)

(defun c:BALineSpacing ( / ls s i o c n be ed)

  (setq ls "0.8")
  
  (if (setq s (ssget "_:L" '((0 . "INSERT") (66 . 1))))
    (repeat (setq i (sslength s))
      (foreach o (vlax-invoke (vlax-ename->vla-object (ssname s (setq i (1- i)))) 'getattributes)
	(and (= :vlax-true (vla-get-MTextAttribute o))
	     (setq c (vla-get-TextString o))
	     (setq n (if (and (setq be (vl-string-search "pxsm" c))
			      (setq ed (vl-string-search ";" c be))
			      )
		       (strcat (substr c 1 (1- be)) "\\pxsm" ls ";" (substr c (+ 2 ed)))
		       (strcat "\\pxsm" ls ";" c)))
	     (vla-put-TextString o n)))))
  (princ)
  )

 


@RandyBenson wrote:

... It also belongs to multiline text in block attributes, and can be individually modified one-at-a-time with the mtext editor.


Honestly, I have no idea how to do that.

 

0 Likes
Message 7 of 13

RandyBenson
Advocate
Advocate

Thanks! We're definitely on a track now, but I fear it may not be the right one.

That code sprung a 'Malformed list' error, so I started fooling around with it, but in the multiple-line attributes I'm applying the spacing to (vl-string-search "pxsm" c) returns "GR W 571.9\\PGR E 570.7", so this test always fails: (setq be (vl-string-search "pxsm" c)). So, it runs fine but doesn't change anything yet. I'm worried that the line spacing is not exposed for attributes, and that a reg hack is needed, but I hope you can prove me wrong:

(vl-load-com)

(defun c:BALineSpacing ( / ls s i o c n be ed)

  (setq ls "0.6")

  (if (setq s (ssget "x" '((0 . "INSERT")(8 . "*PTS*") (66 . 1))))
      (repeat (setq i (sslength s))
        (foreach o (vlax-invoke (vlax-ename->vla-object (ssname s (setq i (1- i)))) 'getattributes)
          (and (= :vlax-true (vla-get-MTextAttribute o))
          (setq c (vla-get-TextString o))
          (setq n
            (if
              (and
                (setq be (vl-string-search "pxsm" c))
                (setq ed (vl-string-search ";" c be))
              )
              (strcat (substr c 1 (1- be)) "\\pxsm" ls ";" (substr c (+ 2 ed))
                (strcat "\\pxsm" ls ";") c
              )
            )
          )
          (vla-put-TextString o n)
         )
       )
     )
  )
  (princ)
)

"GR W 

0 Likes
Message 8 of 13

ВeekeeCZ
Consultant
Consultant

Use updated code. It seems that there was one parent misplaced but can't test it right now.

If still not working, you need to post some dwg samples.

0 Likes
Message 9 of 13

RandyBenson
Advocate
Advocate

I should've uploaded a .dwg to begin with -- here you go. As I mentioned, the updated code loads and runs without error, but doesn't do anything...

0 Likes
Message 10 of 13

ВeekeeCZ
Consultant
Consultant

Well, just tried your drawing and it seems that it dose its job as is just fain.

0 Likes
Message 11 of 13

RandyBenson
Advocate
Advocate

I'm confused. The attributes in the inserts in the drawing I attached have no formatting string "pxsm" in the multiline text, so when I run your code (vl-string-search "pxsm" c) returns nil and nothing gets done. How did the formatting code get into the drawing you attached?

So I changed the "if" statement to a "cond" statement and tested for "\\P" in the string instead, and it works, BUT both procedures append the new string to the attribute instead of replacing the old string. What am I doing wrong?

(vl-load-com)
; BlockAttributeLineSpacing
(defun c:BALS () ; ( / ls s i o c n be ed)

  (setq ls "0.80")

  (if (setq s (ssget "x" '((0 . "INSERT")(8 . "*PTS*") (66 . 1))))
      (repeat (setq i (sslength s))
        (foreach o (vlax-invoke (vlax-ename->vla-object (ssname s (setq i (1- i)))) 'getattributes)
          (and (= :vlax-true (vla-get-MTextAttribute o))
          (setq c (vla-get-TextString o))
          (setq n
            (cond
              ( (and
                  (setq be (vl-string-search "pxsm" c))
                  (setq ed (vl-string-search ";" c be))
                )
                (strcat
                  (substr c 1 (1- be))
                  "\\pxsm" ls ";"
                  (substr c (+ 2 ed))
                  (strcat "\\pxsm" ls ";") c
                )
              )
              ( (and (setq ed (vl-string-search "\P" c 0)))
                (strcat
                  (substr c 1 (1- ed))
                  "\\pxsm" ls ";"
                  (substr c (+ 2 ed))
                  (strcat "\\pxsm" ls ";") c
                )
              )
            )
          )
          (vla-put-TextString o n)
         )
       )
     )
  )
  (princ)
)

 

0 Likes
Message 12 of 13

ВeekeeCZ
Consultant
Consultant
Accepted solution

Randy,

Get back to my reply and copy-paste my code again. You are still using the unfixed version.

When you dig into the logic remember that IF also can have ELSE condition, not just THEN.

Message 13 of 13

RandyBenson
Advocate
Advocate

You are CORRECT, sir! Thank you! Works really well. I owe you a frosty adult beverage!

0 Likes