Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Register Updater Multiple Documents

3 REPLIES 3
Reply
Message 1 of 4
blro.
732 Views, 3 Replies

Register Updater Multiple Documents

Hi Folks,

 

I'm really stuck here and can't figure out what I'm doing wrong. I've just figured out the source code I was using (Dynamic Model Update in the SDK) to update my application does not work as I expected it to. 

 

Essentially, I need my application to register in more than one active document at a time. But it seems that even though I include the overload of document at the updaterRegistry, it throws an error saying the application has already been registered in the application.

 

So am I missing something that will make register to the document level and not the application level? 

 

Thanks in advanced to all.

 

 

 

    [Transaction(TransactionMode.Manual)]
    //[Regeneration(RegenerationOption.Manual)]
    public class AussparungUpdaterApplication : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiApp = commandData.Application;
            Document doc = uiApp.ActiveUIDocument.Document;

            //get "ElementZuordnung" parameter(Guid from shared parameters file)
            Guid elemZuordId = new Guid("guid here");
            

            //Rule out older or external projects that don't contain identifying parameter for trigger
            //Collect generic model types
            FilteredElementCollector genModelCollector = new FilteredElementCollector(doc).WhereElementIsElementType().OfCategory(BuiltInCategory.OST_GenericModel);

            if (null != genModelCollector)
            {
                //Check to see if there are any generic model elements in current model
                Element eCheck = genModelCollector.ToElements().First() as Element;

                if (null != eCheck)
                {
                    if (null != eCheck.get_Parameter(elemZuordId))
                    {
                        AussparungUpdater updater = new AussparungUpdater(uiApp.ActiveAddInId, doc);
                        UpdaterRegistry.RegisterUpdater(updater);

                        //code here

                    }
                }
            }


            return Result.Succeeded;
        }
    }

 

 

3 REPLIES 3
Message 2 of 4
jeremytammik
in reply to: blro.

The updater registry is global across the entire application and shared by all documents.

 

Therefore, there is no need to register the updater multiple times for different documents.

 

Look at the very early structural dynamic model update sample:

 

https://thebuildingcoder.typepad.com/blog/2010/08/structural-dynamic-model-update-sample.html

 

All the registration happens globally in OnStartup and OnShutdown.

 

Look at all the other examples in The Building Coder topic group on DMU and I am sure you will see the light:

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.31

   



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

Message 3 of 4
blro.
in reply to: jeremytammik

Hi @jeremytammik 

 

Thank you for your response. I'm star struck 😉

 

The main issue with not being able to register the updater on startup, and a need to do it on a document basis, is that the triggers use shared parameters, which means they need to be present and I need to be able to look them up first before registering them.

 

Ultimately I would like to implement the program as an external application so that it can just run in the background from startup and registered on document open without the users needing to click any buttons, but I wanted to get the external command part working first. Not sure if this is a wise approach, but it's where I'm at.

 

As of right now the program works well with one document, but if I open a second document nothing gets triggered and if I click the command again I get error about it being registered already:

        //     Updater with the the same Id has already been registered on the application level.

 

 

I've looked through all of the examples in the SDK as well as the one you mentioned above and even borrowed a bit of it, but example code where the programs use non-BIP to trigger the updater are few and far between.

 

Alternatively, should the program just be able to work everywhere i.e. all documents once the parameters have been looked up and registered the first time? Because I've not had any success with that.

 

Out of curiosity - what would the document overload be fore, if not a scenario like this?

 

Here's a excerpt from the overload's meta data:

        // Remarks:
        //     An updater may be registered in more than one document, but an updater may not
        //     be registered for a document and also for the entire application at the same
        //     time. If an updater has already been registered application-wide, an attempt
        //     to register it for a document will cause an exception.

 

Maybe I'm just registering the updater incorrectly?

 

Thanks again in advanced for any guidance.

Message 4 of 4
jeremytammik
in reply to: blro.

Yes that sounds incorrect.

 

The updater registry is global, so you register it once only.

 

Therefore, the error on re-registering is sensible and you should desist from doing so.

 

Just grab one of the simplest existing samples, ensure that it works for you, and modify to adapt to your needs.

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.31

 

Why fight it the hard way?

 

Start from scratch and take it easy.

 



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

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

Post to forums  

Forma Design Contest


Rail Community