This doesn't seem to turn on the background mask for a multiline attribute in a block. Anyone know what will?
BlockReference blkRef = (BlockReference)tr.GetObject(blkId, OpenMode.ForRead); BlockTableRecord btr = (BlockTableRecord)tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead); AttributeCollection attCol = blkRef.AttributeCollection; foreach (ObjectId attId in attCol) { AttributeReference attRef = (AttributeReference)tr.GetObject(attId, OpenMode.ForRead); if (attRef.IsMTextAttribute) { btr.UpgradeOpen(); attRef.UpgradeOpen(); attRef.MTextAttribute.BackgroundFillColor = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.None, 198); attRef.MTextAttribute.UseBackgroundColor = false; attRef.UpdateMTextAttribute(); blkRef.RecordGraphicsModified(true);
Solved! Go to Solution.
Solved by ActivistInvestor. Go to Solution.
@friendfromarea51 wrote:
This doesn't seem to turn on the background mask for a multiline attribute in a block. Anyone know what will?
BlockReference blkRef = (BlockReference)tr.GetObject(blkId, OpenMode.ForRead); BlockTableRecord btr = (BlockTableRecord)tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead); AttributeCollection attCol = blkRef.AttributeCollection; foreach (ObjectId attId in attCol) { AttributeReference attRef = (AttributeReference)tr.GetObject(attId, OpenMode.ForRead); if (attRef.IsMTextAttribute) { btr.UpgradeOpen(); attRef.UpgradeOpen(); attRef.MTextAttribute.BackgroundFillColor = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.None, 198); attRef.MTextAttribute.UseBackgroundColor = false; attRef.UpdateMTextAttribute(); blkRef.RecordGraphicsModified(true);
Just having a quick look at your code, did you try with true instead?
attRef.MTextAttribute.UseBackgroundColor = true;
Thanks Gile, I did 😕 Appears to not work either.
Here is the source for the AttributeReference.MTextAttribute property:
// Autodesk.AutoCAD.DatabaseServices.AttributeReference public MText MTextAttribute { get { IntPtr unmanagedObjPtr = new IntPtr(<Module>.AcDbAttribute.getMTextAttribute(this.GetImpObj())); return new MText(unmanagedObjPtr, false); } set { int num = (int)<Module>.AcDbAttribute.setMTextAttribute(this.GetImpObj(), value.GetImpObj()); if (num != 0) { throw new Autodesk.AutoCAD.Runtime.Exception((ErrorStatus)num); } } }
Each use of that property produces a new MText managed wrapper. The wrapper is not stored by the AtttribueReference, and it doesn't know or care what you do with it, other than that it must be disposed.
When you do this:
attRef.MTextAttribute.BackgroundFillColor = Autodesk.AutoCAD.Colors... blah blah blah attRef.MTextAttribute.UseBackgroundColor = false;
you are assigning the value of one property to each of two different MText objects.
You instead have to do this:
MText mtext = attRef.MtextAttribute; mtext.BackgroundFillColor = Autodesk.AutoCAD.Colors... blah blah blah mtext.UseBackgroundColor = true; attRef.MtextAttribute = mtext;
@friendfromarea51 wrote:This doesn't seem to turn on the background mask for a multiline attribute in a block. Anyone know what will?
BlockReference blkRef = (BlockReference)tr.GetObject(blkId, OpenMode.ForRead); BlockTableRecord btr = (BlockTableRecord)tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead); AttributeCollection attCol = blkRef.AttributeCollection; foreach (ObjectId attId in attCol) { AttributeReference attRef = (AttributeReference)tr.GetObject(attId, OpenMode.ForRead); if (attRef.IsMTextAttribute) { btr.UpgradeOpen(); attRef.UpgradeOpen(); attRef.MTextAttribute.BackgroundFillColor = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.None, 198); attRef.MTextAttribute.UseBackgroundColor = false; attRef.UpdateMTextAttribute(); blkRef.RecordGraphicsModified(true);