modify text height of AlignedDimension

modify text height of AlignedDimension

tom.zhengGNS4G
Contributor Contributor
604 Views
2 Replies
Message 1 of 3

modify text height of AlignedDimension

tom.zhengGNS4G
Contributor
Contributor

Hi! this might be pretty basic but I just can't find the way to do it. I'm trying to modify the text height of an AlignedDimension via C#.

In AutoCAD, I can modify it in the properties panel:

ezgif.com-video-to-gif-converter.gif

 

below is my code for aligned dimension creation : 

 

using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;

ObjectId drawAlignedDimension(Point3d line1Point, Point3d line2Point, Point3d dimLinePoint, string text)
{
    Document document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
    Editor editor = document.Editor;
    Database database = document.Database;

    ObjectId dimensionObjId = ObjectId.Null;

    using (var tr = database.TransactionManager.StartTransaction())
    {
        DimStyleTable dimStyleTbl = database.DimStyleTableId.GetObject(OpenMode.ForRead) as DimStyleTable;
        DimStyleTableRecord targetDimStyle = null;
        const string targetDimStyleName = "ISO-25";

        //find dimStyle
        foreach (ObjectId objId in dimStyleTbl)
        {
            DimStyleTableRecord dimStyleRec = objId.GetObject(OpenMode.ForRead) as DimStyleTableRecord;
            if (dimStyleRec.Name == targetDimStyleName)
            {
                targetDimStyle = dimStyleRec;
                break;
            }
        }

        //create dimension
        using (var dimension = new AlignedDimension(line1Point, line2Point, dimLinePoint, text, targetDimStyle.Id))
        {
            var blkTbl = database.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
            var modelSpace = blkTbl[BlockTableRecord.ModelSpace].GetObject(OpenMode.ForWrite) as BlockTableRecord;

            dimensionObjId = modelSpace.AppendEntity(dimension);
            tr.AddNewlyCreatedDBObject(dimension, true);
        }

        tr.Commit();
    }

    return dimensionObjId;
}

ObjectId dimId = drawAlignedDimension(new Point3d(0, 0, 0), new Point3d(30, 0, 0), new Point3d(5, 5, 0), "test text");

 

 

I've been searching and reading the document for several days but seem not able to find relative source or property. Can someone give me some suggestions? Any help is really appreciated!

0 Likes
Accepted solutions (1)
605 Views
2 Replies
Replies (2)
Message 2 of 3

hosneyalaa
Advisor
Advisor
Accepted solution
Message 3 of 3

tom.zhengGNS4G
Contributor
Contributor
Dimension.Dimtxt property is exactly what I'm looking for. Thanks for your help!
0 Likes