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: 

Dynamic model update causing infinite loop

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
Anonymous
1386 Views, 7 Replies

Dynamic model update causing infinite loop

I am working on a utility that monitors viewports on sheets and adjust the viewport detail number as it is moved around the sheet. I first tried to accomplish this by starting from the  ChangesMonitor project in the SDK samples.  This worked well for identifying when a viewport was modified, but I couldn't modify the detail number.  I then started from The Building Coder's CmdElevationWatcherUpdater using the Dynamic Model Update. I am able to monitor the project for changes to viewports, and I can modify the detail number. The problem is, it get stuck in an infinite loop. I think that the modification to the detail number is triggering the updater to run again and again.

 

I modified the ElementCategoryFilter to filter Viewports, and the AddTrigger to Element.GetChangeTypeAny().

 

How can I make it so that I can modify the detail number without triggering the element being changed again?

 

Thanks

7 REPLIES 7
Message 2 of 8
jeremytammik
in reply to: Anonymous

Dear Michael,

 

Thank you for your query.

 

You seem to be doing interesting stuff  🙂

 

Congratulations on getting to where you are now.

 

First of all, I would recommend that you look at The Building Coder topic group on Dynamic Model Updaters in general:

 

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

 

Secondly, I always find the SDK samples the most reliable projects to use as a basis for your own development.

 

Therefore, the Associative Section View SDK Sample might help in particular:

 

http://thebuildingcoder.typepad.com/blog/2011/08/associative-section-view-fix.html#2

 

Third, the different change types have different priorities and occur at different times.

 

It would help if you could determine what change type is associated with the viewport movement, i.e., location, (geometry?) versus the viewport number (view, parameter, ...?).

 

Obviously, the geometry and location changes are at a more fundamental level that the numbering, so it should be pretty easy to pick a change type that only reacts to the fundamental location change and not to the numbering change.

 

I hope this helps.

 

Please let us know how it goes for you.

 

If you can keep your solution pretty generic, it sounds like it would be a great sample to share, to explain this problem, principles and solution.

 

Thank you!

 

Best regards,

 

Jeremy



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

Message 3 of 8
Anonymous
in reply to: jeremytammik

Thanks for the links Jeremy. I looked at the SDK version. It looks cleaner than mine, but the commands are basically the same. I will definitely reference it to clean up my code a bit.

 

As for the Change Type, I was initially hoping that the Geometry type would work for my purpose, but it doesn't. Is a change in position fo the viewport considered a change to geometry? It seems like it should be. However, moving a viewport doesn't trigger the updater if the change type is set to GetChangeTypeGeometry. It only is triggered with the type GetChangeTypeAny.  Also, there doesn't seem to be a way to tell what change triggered the event once the event is triggered. I am looking to only update the detail number if the viewport's location has changed on the sheet.  

 

The only thing I can think of to get around this is to store the last collection of ids that were updated and capture a timestamp of the last update time.  Then compare the previous id collection to the current, and if they are the same compare the the current time to the previous. if the difference is large enough for user input proceed with modifying the viewport.

 

Can you suggest a better way to get a change in location or to bail out if the viewport was just modified?

Message 4 of 8
matthew_taylor
in reply to: Anonymous

Hi Michael,
Perhaps you can skip/bail out of the updater if the changetype is of parameter?
I'll check my code tomorrow if you haven't found a solution by then.

Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
Message 5 of 8
Anonymous
in reply to: matthew_taylor

Matthew,

 

That sounds like it would work, but how do I query the changetype?  I have a trigger setup for changetypeany, and the execute command recieves the UpdaterData, but I can't pull what kind of change initiated the update.  Can the trigger push more than just the UpdaterData?

 

Thanks

Message 6 of 8
matthew_taylor
in reply to: Anonymous

Hi Michael,

Yes, you can add multiple triggers using (DB.UpdaterRegistry.AddTrigger), and query what type of change was triggered:

 

 

Public Sub Execute(ByVal data As DB.UpdaterData) Implements DB.IUpdater.Execute
  ...
For Each elemId As DB.ElementId In data.GetModifiedElementIds
   If data.IsChangeTriggered(elemId, DB.Element.GetChangeTypeGeometry)     Then
...

                     

Substitute GetChangeTypeGeometry with one of the other options as required.

 

 

Cheers,

 

-Matt


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
Message 7 of 8
Anonymous
in reply to: matthew_taylor

Thank you for the insight.  This definitely is much cleaner. Just to help anybody searching, I ended up using this as my check for the detail number being changed

foreach(ElementId id in data.GetModifiedElementIds())
{
    if (data.IsChangeTriggered(id, Element.GetChangeTypeParameter(new ElementId(BuiltInParameter.VIEWPORT_DETAIL_NUMBER))))
{
break;
}
else
{
//update detail number
}
}

 

Message 8 of 8
jamess166
in reply to: Anonymous

Excelente, logre solucionar un problema parecido que tenia con los updaters.

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

Post to forums  

Rail Community


Autodesk Design & Make Report