+ Reply to Thread
Results 1 to 6 of 6

Thread: Mtext Alignment

  1. #1
    Senior Member
    Using
    AutoCAD 2006
    Join Date
    Aug 2009
    Posts
    109

    Question Mtext Alignment

    Registered forum members do not see this ad.

    Hi All,

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

    Thanks,
    Kumar.

  2. #2
    Full Member Alex Moiceanu's Avatar
    Computer Details
    Alex Moiceanu's Computer Details
    Operating System:
    Windows 7
    Discipline
    Mechanical
    Alex Moiceanu's Discipline Details
    Occupation
    Engineer
    Discipline
    Mechanical
    Details
    Automotive & Aerospace
    Using
    AutoCAD 2012
    Join Date
    Feb 2011
    Location
    Romania
    Posts
    46

    Default

    Hi Giskumar,

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

    Code:
    ; 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.
    CAD-Systems.Think smart.Work less.

    http://www.cad-systems.org

    Find useful Tips & Tricks, free Tutorials and more...

  3. #3
    Senior Member
    Using
    AutoCAD 2006
    Join Date
    Aug 2009
    Posts
    109

    Default

    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.

  4. #4
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Pietari, Venäjä
    Posts
    1,596

    Default

    Try code from the Help file, just slightly edited:
    Code:
     
    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'~
    The soul is healed by being with children. - Fyodor Dostoyevsky, novelist (1821-1881)

  5. #5
    Senior Member
    Using
    AutoCAD 2006
    Join Date
    Aug 2009
    Posts
    109

    Default

    Thanks Fixo.

    This will solve my problem.

  6. #6
    Super Member fixo's Avatar
    Computer Details
    fixo's Computer Details
    Operating System:
    Windows 7
    Motherboard:
    E7500
    CPU:
    Intel(R)Core(TM)2 DUO CPU 2.93HGz
    RAM:
    4098 Gb
    Graphics:
    1024 Gb
    Using
    AutoCAD 2009
    Join Date
    Jul 2005
    Location
    Pietari, Venäjä
    Posts
    1,596

    Default

    Registered forum members do not see this ad.

    You're welcome,
    Cheers
    The soul is healed by being with children. - Fyodor Dostoyevsky, novelist (1821-1881)

Similar Threads

  1. Sum Numbers in Mtext Fields to Mtext Field
    By muurr in forum AutoLISP, Visual LISP & DCL
    Replies: 5
    Last Post: 5th Mar 2011, 08:31 pm
  2. Alignment
    By CAD<LIFE in forum AutoCAD 3D Modelling & Rendering
    Replies: 2
    Last Post: 20th Jun 2007, 09:29 pm
  3. Can Lisp use mtext to make multi string mtext editor?
    By muck in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 18th Dec 2006, 03:22 am
  4. Mtext Alignment
    By WannaBeCader in forum AutoCAD Drawing Management & Output
    Replies: 4
    Last Post: 1st Jul 2005, 03:57 am
  5. MTEXT created in same MTEXT editor on different layers?
    By hyposmurf in forum AutoCAD General
    Replies: 2
    Last Post: 5th Sep 2003, 12:54 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts