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

Problem with brute force AttSync with XRefs

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Paulio
568 Views, 2 Replies

Problem with brute force AttSync with XRefs

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

2 REPLIES 2
Message 2 of 3
Virupaksha_aithal
in reply to: Paulio

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

Message 3 of 3
Paulio
in reply to: Virupaksha_aithal

Thanks Virupaksha,

 

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

 

That's fixed it.

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report