Updater Register Error

Updater Register Error

AGGilliam
Collaborator Collaborator
1,231 Views
2 Replies
Message 1 of 3

Updater Register Error

AGGilliam
Collaborator
Collaborator

I'm currently working on an updater that will place walls along model lines upon their creation. However, I only want this to happen after a DWG has been imported and exploded. I've tested the updater itself, and it seems to work, but I'm having issues getting it to register inside an EventHandler. I started off registering inside a FileImportedEvent, and when that didn't work, I tried implementing an IdlingEvent as a workaround. The only information I can get out of the exception is "External Component has thrown an exception". Does anybody have any thoughts?

 

I don't want to overwhelm anyone with code, so here's the idling event and the register method:

private void RegisterUpdater(object sender, IdlingEventArgs args)
        {
            _uiConApp.Idling -= RegisterUpdater;
            if (dwgWalls == null)
            {
                try
                {
                    using (Transaction t = new Transaction(doc, "Register"))
                    {
                        t.Start();
                        dwgWalls = new DWGWalls(thisAppId);
                        dwgWalls.Register(doc); //Need to implement an Idling event to handle the registration
                        t.Commit();
                    }
                }
                catch (Exception ex)
                { }
            }
            ElementFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_Lines);
            UpdaterRegistry.RemoveAllTriggers(dwgWalls.GetUpdaterId());
            dwgWalls.AddTrigger(doc, filter);
        }

class DWGWalls : IUpdater
    {
        UpdaterId updaterId = null;
        internal DWGWalls(AddInId thisAppId)
        {
            updaterId = new UpdaterId(thisAppId, new Guid());
        }

        internal void Register(Document doc)
        {
            try
            {
                if (!UpdaterRegistry.IsUpdaterRegistered(updaterId))
                {
                    UpdaterRegistry.RegisterUpdater(this, doc, true);
                }
            }
            catch (Exception ex)
            { }
        }

// The rest of the Updater...

}
0 Likes
Accepted solutions (1)
1,232 Views
2 Replies
Replies (2)
Message 2 of 3

jeremytammik
Autodesk
Autodesk
Accepted solution

Maybe you can add a switch inside the updater Execute that turns it on and off appropriately instead of registering and unregistering the whole thing.

 

Then you could control the behaviour simply by toggling your switch.

 

That should be possible from any and all possible contexts.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 3

AGGilliam
Collaborator
Collaborator

Thanks for the idea! Upon testing it out, I came across a couple other errors that may have been the actual issue to begin with (such as forgetting to swap out my null UpdaterId placeholder for an actual value). Once I cleared those up, it works great!

 

For anyone interested in how it works:

Now it registers the updater and subscribes to the FileImport event on startup. The FileImport event adds a trigger to the updater and sets a boolean to true (I ran into an issue trying to clear the trigger within the updater, so I used this boolean as the switch). Within the Execute method I set the boolean back to false and subscribe to an Idling event to change the WallType and pin each of the walls.

 

The only issue would be in an edge-case scenario where someone imported the DWG and then drew a line before exploding the import. Although, I'm not really worried about that happening.

0 Likes