Jump to content

Recommended Posts

Posted

Hi All,

 

Is there a way to set Mtext alignment to "BottomLeft" in Autocad VBA?

 

Thanks,

Kumar.

:unsure:

Posted

Hi Giskumar,

 

I used this LISP code to set the MiddleCenter for MText.

 

; mtext with 0 width
(defun c:T (/ pt)
 (initdia)
 (command "_.mtext")
 (if (setq pt (getpoint "\nSpecify insertion point <First corner>: "))
   (command "_non" pt "_W" 0.)
 )
 (princ)
)


;mtext center justified, 0 width
(defun c:TY (/ pt)
(initdia)
(command "_.mtext")
(if (setq pt (getpoint "\nSpecify first corner: "))
  (command pt "_j" "_mc" "_w" 0)
)
(princ)
)

 

You can modify it to use for BottomLeft Justification.

Posted

Hi,

 

Thanks for the reply.

 

I want the same thing in VBA.

In VBA, we can set Alignment to text using textObj.Alignment property which is not found in Mtex properties list.

 

Is there any other way using VBA instead of lisp? Because all my code is in VBA.

 

 

Thanks,

Kumar.

Posted

Try code from the Help file, just slightly edited:

 
Option Explicit
Sub Example_AddMtext()
   ' This example creates an MText object in model space
   ' and align it to bottom center

   Dim MTextObj As AcadMText
   Dim pickPt
   Dim corner(0 To 2) As Double
   Dim width As Double
   Dim txtheight As Double
   Dim text As String
   pickPt = ThisDrawing.Utility.GetPoint(, vbCrLf & "Pick text position: ")
   corner(0) = pickPt(0): corner(1) = pickPt(1): corner(2) = 0#
   txtheight = ThisDrawing.GetVariable("textsize")

   text = "This is the text String\Pfor the mtext Object"
   width = Len(text) * txtheight * 0.875
   '' Creates the mtext Object
   Set MTextObj = ThisDrawing.ModelSpace.AddMText(corner, width, text)
   '' align to bottom center
   MTextObj.AttachmentPoint = acAttachmentPointBottomCenter
   '' reset position
   MTextObj.InsertionPoint = corner
   Dim minExt As Variant
   Dim maxExt As Variant

   ' Return the bounding box for the line and return the minimum
   ' and maximum extents of the box in the minExt and maxExt variables.
   MTextObj.GetBoundingBox minExt, maxExt
   width = maxExt(0) - minExt(0)
   MTextObj.width = width


End Sub

 

~'J'~

Posted

Thanks Fixo.

 

This will solve my problem.

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...