Background mask for Multiline Attribute In Block

Background mask for Multiline Attribute In Block

brianchapmandesign
Collaborator Collaborator
1,019 Views
4 Replies
Message 1 of 5

Background mask for Multiline Attribute In Block

brianchapmandesign
Collaborator
Collaborator

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);

"Very funny, Scotty. Now beam down my clothes.
0 Likes
Accepted solutions (1)
1,020 Views
4 Replies
Replies (4)
Message 2 of 5

_gile
Consultant
Consultant

@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;

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 5

brianchapmandesign
Collaborator
Collaborator

Thanks Gile, I did 😕 Appears to not work either.


"Very funny, Scotty. Now beam down my clothes.
0 Likes
Message 4 of 5

ActivistInvestor
Mentor
Mentor
Accepted solution

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);

 

Message 5 of 5

brianchapmandesign
Collaborator
Collaborator

Thank you both


"Very funny, Scotty. Now beam down my clothes.
0 Likes