Print Page | Close Window

add mttext with color

Printed From: CAD Forum
Category: EN
Forum Name: AutoCAD
Forum Description: Discussion about AutoCAD and AutoCAD LT, viewers, DWG and DWF formats, Design Review, AutoCAD 360, add-ons
URL: https://www.cadforum.cz/forum_en/forum_posts.asp?TID=14667
Printed Date: 15.May.2025 at 09:05


Topic: add mttext with color
Posted By: katto01
Subject: add mttext with color
Date Posted: 20.Nov.2024 at 10:33
Hello,

I am trying to plot a few text objects with different colors.

Here is the code I have. the color is black rather than red.
Any suggestions?

Thanks


Sub AddMTextWithTrueColor()
    ' Declare variables
    Dim mTextObj As Object
    Dim insertionPoint(0 To 2) As Double
    Dim textContent As String
    Dim trueColor As Long

    ' Set the insertion point for the MText (e.g., 0,0,0)
    insertionPoint(0) = 0
    insertionPoint(1) = 0
    insertionPoint(2) = 0

    ' Set the text content
    textContent = "This is an example of MText with True Color."

    ' Set the True Color (e.g., RGB(255, 0, 0) = Red)
    trueColor = RGB(255, 0, 0) ' Red color

    ' Create MText object at the specified insertion point
    Set mTextObj = ThisDrawing.ModelSpace.AddMText(insertionPoint, 50, textContent)
    
    ' Set the True Color of the MText object
    mTextObj.Color = trueColor ' Use Color property to set the True Color

    ' Optionally, you can set the text height, width, rotation, etc.
    mTextObj.TextHeight = 2  ' Set the text height to 2 units

    ' Zoom to the new object for better visibility
    ThisDrawing.ActiveViewport.ZoomExtents
End Sub



-------------
Katto Ishimura



Print Page | Close Window