.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Background mask for Multiline Attribute In Block

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
brianchapmandesign
625 Views, 4 Replies

Background mask for Multiline Attribute In Block

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.
4 REPLIES 4
Message 2 of 5
_gile
in reply to: brianchapmandesign


@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

Message 3 of 5
brianchapmandesign
in reply to: _gile

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


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

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

Thank you both


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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost