Jump to content

Recommended Posts

Posted

hi all, i have a lisp routine i've been trying to set up to quickly update the line space factors of selected text to 0.8.

 

now i've got it working ok for multiline text but i want it to also include multileaders. after running its picking the multileaders and then telling me the change to 0.8 has been completed but in reality the multileaders havent been updated. they are still 1. any ideas how i can get them to update?


 

(defun c:LSFsel ( / ss i ent obj acLineSpacingStyleAtLeast mtextObj newText)
  (vl-load-com)
  (setq acLineSpacingStyleAtLeast 1)

  (if (setq ss (ssget))
    (progn
      (setq i 0)
      (while (< i (sslength ss))
        (setq ent (vlax-ename->vla-object (ssname ss i)))

        (cond
          ;; MText: apply directly
          ((= (vla-get-objectname ent) "AcDbMText")
            (vla-put-LineSpacingStyle ent acLineSpacingStyleAtLeast)
            (vla-put-LineSpacingFactor ent 0.8)
          )
          ;; MLeader: rebuild MText
          ((= (vla-get-objectname ent) "AcDbMLeader")
            (vl-catch-all-apply
              (function
                (lambda ()
                  (setq mtextObj (vlax-invoke ent 'GetMText))
                  (if mtextObj
                    (progn
                      (setq newText
                        (vla-AddMText
                          (vla-get-ModelSpace
                            (vla-get-ActiveDocument (vlax-get-acad-object)))
                          (vla-get-insertionpoint mtextObj)
                          (vla-get-width mtextObj)
                          (vla-get-TextString mtextObj)
                        )
                      )
                      (vla-put-LineSpacingStyle newText acLineSpacingStyleAtLeast)
                      (vla-put-LineSpacingFactor newText 0.8)
                      (vlax-invoke ent 'SetMText newText)
                      (vla-delete newText) ; cleanup temp MText
                    )
                  )
                )
              )
            )
          )
        )
        (setq i (1+ i))
      )
      (princ "\n✅ Line spacing factor set to 0.8 for selected items.")
    )
    (princ "\n⚠️ No objects selected.")
  )
  (princ)
)

 

Posted

Hi @masterfal,

 

I don't know what do you want to achieve with this:

 

(vl-catch-all-apply
              (function
                (lambda ()
                  (setq mtextObj (vlax-invoke ent 'GetMText))
                  (if mtextObj
                    (progn
                      (setq newText
                        (vla-AddMText
                          (vla-get-ModelSpace
                            (vla-get-ActiveDocument (vlax-get-acad-object)))
                          (vla-get-insertionpoint mtextObj)
                          (vla-get-width mtextObj)
                          (vla-get-TextString mtextObj)
                        )
                      )

 

but there is several issues in this code, like: 'GetMText doesn't exist as Method, you can't use "acLineSpacingStyleAtLeast" as variable to store the value, etc.

 

You can try with this:

 

(defun c:LSFsel ( / ss i ent obj acLineSpacingStyleAtLeast mtextObj newText)
  (vl-load-com)

  (if (setq ss (ssget))
    (progn
      (setq i 0)
      (while (< i (sslength ss))
        (setq ent (vlax-ename->vla-object (ssname ss i)))

        (cond
          ;; MText: apply directly
          ((= (vla-get-objectname ent) "AcDbMText")
            (vla-put-LineSpacingStyle ent 1)
            (vla-put-LineSpacingFactor ent 0.8)
          )
          ;; MLeader: rebuild MText
          ((= (vla-get-objectname ent) "AcDbMLeader")
            (vla-put-TextLineSpacingStyle ent acLineSpacingStyleAtLeast)
            (vla-put-TextLineSpacingFactor ent 0.80)
          )
        )
        (setq i (1+ i))
      )
      (princ "\n? Line spacing factor set to 0.8 for selected items.")
    )
    (princ "\n?? No objects selected.")
  )
  (princ)
)

 

Try it, and see if it's helpful.

  • Agree 1
Posted
23 minutes ago, Saxlle said:

Hi @masterfal,

 

I don't know what do you want to achieve with this:

 

(vl-catch-all-apply
              (function
                (lambda ()
                  (setq mtextObj (vlax-invoke ent 'GetMText))
                  (if mtextObj
                    (progn
                      (setq newText
                        (vla-AddMText
                          (vla-get-ModelSpace
                            (vla-get-ActiveDocument (vlax-get-acad-object)))
                          (vla-get-insertionpoint mtextObj)
                          (vla-get-width mtextObj)
                          (vla-get-TextString mtextObj)
                        )
                      )

 

but there is several issues in this code, like: 'GetMText doesn't exist as Method, you can't use "acLineSpacingStyleAtLeast" as variable to store the value, etc.

 

You can try with this:

 

(defun c:LSFsel ( / ss i ent obj acLineSpacingStyleAtLeast mtextObj newText)
  (vl-load-com)

  (if (setq ss (ssget))
    (progn
      (setq i 0)
      (while (< i (sslength ss))
        (setq ent (vlax-ename->vla-object (ssname ss i)))

        (cond
          ;; MText: apply directly
          ((= (vla-get-objectname ent) "AcDbMText")
            (vla-put-LineSpacingStyle ent 1)
            (vla-put-LineSpacingFactor ent 0.8)
          )
          ;; MLeader: rebuild MText
          ((= (vla-get-objectname ent) "AcDbMLeader")
            (vla-put-TextLineSpacingStyle ent acLineSpacingStyleAtLeast)
            (vla-put-TextLineSpacingFactor ent 0.80)
          )
        )
        (setq i (1+ i))
      )
      (princ "\n? Line spacing factor set to 0.8 for selected items.")
    )
    (princ "\n?? No objects selected.")
  )
  (princ)
)

 

Try it, and see if it's helpful.

Just one detail: it might be necessary to replace 'acLineSpacingStyleAtLeast' with 1 for MLEADERs as well.

  • Like 1
Posted

@GLAVCVS, I tryed with "acLineSpacingStyleAtLeast", where the default value is 1 (acLineSpacingStyleAtLeast = 1). But, if you want different number than "1", definetly need to change "acLineSpacingStyleAtLeast" with desired value. As always, you're the man, thanks! 😉

  • Like 1
Posted (edited)

No 'man': Ro'man'  

SPQR.gif.924d4d27975073d056862cc48f6e3c59.gif

🙂

 

Edited by GLAVCVS
  • Funny 1
Posted

Yes, correct, I meant on that 🫡

  • Funny 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...