giskumar Posted June 18, 2012 Posted June 18, 2012 Hi All, Is there a way to set Mtext alignment to "BottomLeft" in Autocad VBA? Thanks, Kumar. Quote
Alex Moiceanu Posted June 18, 2012 Posted June 18, 2012 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. Quote
giskumar Posted June 18, 2012 Author Posted June 18, 2012 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. Quote
fixo Posted June 18, 2012 Posted June 18, 2012 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'~ Quote
giskumar Posted June 19, 2012 Author Posted June 19, 2012 Thanks Fixo. This will solve my problem. Quote
Recommended Posts
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.