When I change an attributeReference textString property the position of my BlockReference changes?

667 views Asked by At

I have copied a blockReference that was in my first file dwg to an existing file with the method WblockCloneObjects method. I have set the position of this blockReference and it worked fine.

The problem is when I change the attributeReference textString property, My blockReference change the position and the value of the attribute isn't visible in the blockReference.

Here it is my code:

private bool SetIssueNumber(Transaction toTransaction, BlockReference deepClonedIssue, string identifier)
{
    //Get the attributeCollection
    Autodesk.AutoCAD.DatabaseServices.AttributeCollection attrCollection = deepClonedIssue.AttributeCollection;
    //Get the object
    foreach (ObjectId idAttrReference in attrCollection)
    {
        AttributeReference attributeReference =
            toTransaction.GetObject(idAttrReference, OpenMode.ForWrite) as AttributeReference;
        if (attributeReference == null)
            return false;
        if (attributeReference.Tag.Equals("ISSUENUMBER"))
        {
            attributeReference.TextString = identifier;
            return true;
        }
    }
    return false;
}

When I remove:

attributeReference.TextString = identifier;

The blockReference shows up in the expecting position but When it's executed, I observe that the position change and the value of attribute doesn't show up.

1

There are 1 answers

1
Augusto Goncalves On

Not sure how you're deepcloning the block reference, but you may also need to transform (move/rotate/scale) the attribute. Here is the method with notes from the help file.

AttributeReference.SetAttributeFromBlock Method (Matrix3d)

Applies blockTransform to the attribute's geometric data to transform the position, sizing, and obliquing as would be done by the INSERT command. The attribute's textual and entity properties data is left alone.