Problem with brute force AttSync with XRefs

Problem with brute force AttSync with XRefs

Paulio
Advocate Advocate
718 Views
2 Replies
Message 1 of 3

Problem with brute force AttSync with XRefs

Paulio
Advocate
Advocate

I'm using a slightly modified version of Gile's Brute Force AttSync code from here. The reason it's modified is in that post but this is a different issue.

 

It works a treat in the current drawing but it seems to move the attributes in blocks in XRefs.

The attribute in the block is justified middle centre but after running the AttSync, the attribute seems to "forget" that it's justified and moves the text to the location of the attribute in the definition.

 

BeforeBeforeAfterAfter 

 

 

 

 

 

 

 

 

 

It's weird because if you edit the XRef in place, it snaps back to the correct place but then snaps back to being wrong when the XRef is closed without saving.

I'm attaching a sample project and a couple of drawings to show what's going on. 

There are a couple of commands in the project showing the two different approaches I've tried. I've also tried all kinds of other ways to get it to refresh itself but the only thing that seems to correct it is if i programmatically set the value of the attribute to its current value; I can't do that on a drawing with hundreds of blocks though.

 

This is in ACAD 2018 but I believe it's the same in 17.

 

Any advice would be greatly appreciated.

 

Thanks

 

Paul

0 Likes
Accepted solutions (1)
719 Views
2 Replies
Replies (2)
Message 2 of 3

Virupaksha_aithal
Autodesk Support
Autodesk Support
Accepted solution

Hi,

 

try making the editing database as working database.

 

private void SyncAttsInDB(Database db)
{
    Database workingDb = HostApplicationServices.WorkingDatabase;

    try
    {
        HostApplicationServices.WorkingDatabase = db;
        using (Transaction trans = db.TransactionManager.StartTransaction())
        {
            BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);

            foreach (ObjectId id in bt.Cast<ObjectId>().ToList())
            {
                BlockTableRecord btr = (BlockTableRecord)trans.GetObject(id, OpenMode.ForRead);
                if (btr.IsLayout || btr.IsFromExternalReference || btr.GetBlockReferenceIds(true, true).Count == 0)
                {
                    continue;
                }
                using (Transaction innerTrans = db.TransactionManager.StartTransaction())
                {
                    btr.UpgradeOpen();
                    btr.SynchronizeAttributes();
                    innerTrans.Commit();
                }
            }
            trans.Commit();
        }
    }
    catch
    {

    }
    finally
    {
        HostApplicationServices.WorkingDatabase = workingDb;
    }
            
}


Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 3

Paulio
Advocate
Advocate

Thanks Virupaksha,

 

That's about the only thing I didn't try.

 

That's fixed it.

0 Likes