Can't set MTextAttributeDefinition.Width

Can't set MTextAttributeDefinition.Width

Anonymous
Not applicable
420 Views
1 Reply
Message 1 of 2

Can't set MTextAttributeDefinition.Width

Anonymous
Not applicable

Hello!

 

I want to change the MTextAttributeDefinition.Width by code, but it does not work, the code is here:

 

 

public static void UpdateMTextAttribute(this Database db, string blockName, string attName, ObjectId textStyleId, double height, double widthFactor, double width)
        {
            BlockTable bt = (BlockTable)db.BlockTableId.GetObject(OpenMode.ForRead);
            ObjectId btrID = bt[blockName];
            BlockTableRecord btr = (BlockTableRecord)btrID.GetObject(OpenMode.ForRead);
            foreach (ObjectId id in btr)
            {
                AttributeDefinition attDef = id.GetObject(OpenMode.ForRead) as AttributeDefinition;
                if (attDef != null && attDef.Tag == attName)
                {
                    attDef.UpgradeOpen();
                    attDef.TextStyleId = textStyleId;
                    attDef.Height = height;
                    attDef.WidthFactor = widthFactor;
                    attDef.MTextAttributeDefinition.Width = width;
                    attDef.DowngradeOpen();
                }
            }
        }

During debugging I can see the TextStyleId, Height and WidthFactor all changed, but MTextAttributeDefinition.Width still has the original value.

 

How can I change it by code? Thanks very much?

 

0 Likes
421 Views
1 Reply
Reply (1)
Message 2 of 2

dylanswan3dvrs
Explorer
Explorer

MText mText = attDef.MTextAttributeDefinition;
mText.Width = width;
attDef.MTextAttributeDefinition = mText;

0 Likes