Skip to content

Commit

Permalink
fix: better build optimization and bug fix (#1560)
Browse files Browse the repository at this point in the history
* switched to avalonia dispatcher

* add missing import

* fix: updating objects breaks when the og object doesn't import correctly

* change the way that the UI "refreshes"

Co-authored-by: Connor Ivy <[email protected]>
  • Loading branch information
connorivy and Connor Ivy authored Aug 30, 2022
1 parent d8e782b commit e9d6a30
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Avalonia.Threading;
using ConnectorRevit.Revit;
using DesktopUI2.Models;
using DesktopUI2.Models.Settings;
Expand Down Expand Up @@ -167,7 +169,7 @@ private void DeleteObjects(List<ApplicationObject> previouslyReceiveObjects, Lis
{
foreach (var obj in previouslyReceiveObjects)
{
if (newPlaceholderObjects.Any(x => x.applicationId == obj.applicationId))
if (obj.CreatedIds.Count == 0 || newPlaceholderObjects.Any(x => x.applicationId == obj.applicationId))
continue;

var element = CurrentDoc.Document.GetElement(obj.CreatedIds.FirstOrDefault());
Expand Down Expand Up @@ -198,10 +200,11 @@ private List<ApplicationObject> ConvertReceivedObjects(ISpeckleConverter convert
try
{
conversionProgressDict["Conversion"]++;
System.Windows.Threading.Dispatcher.CurrentDispatcher.Invoke(() =>
{
progress.Update(conversionProgressDict);
}, System.Windows.Threading.DispatcherPriority.Background);
progress.Update(conversionProgressDict);

var s = new CancellationTokenSource();
DispatcherTimer.RunOnce(() => s.Cancel(), TimeSpan.FromMilliseconds(10));
Dispatcher.UIThread.MainLoop(s.Token);

//skip element if is from a linked file and setting is off
if (!receiveLinkedModels && @base["isRevitLinkedModel"] != null && bool.Parse(@base["isRevitLinkedModel"].ToString()))
Expand All @@ -216,11 +219,8 @@ private List<ApplicationObject> ConvertReceivedObjects(ISpeckleConverter convert
var view = CurrentDoc.ActiveGraphicalView ?? CurrentDoc.Document.ActiveView;
var uiView = CurrentDoc.GetOpenUIViews().FirstOrDefault(uv => uv.ViewId.Equals(view.Id));

//So as not to bother the user by changing the zoom
var zc = uiView.GetZoomCorners().ToList();

// "refresh" the active view
uiView.ZoomAndCenterRectangle(zc.ElementAt(0), zc.ElementAt(1));
uiView.Zoom(1);

switch (convRes)
{
Expand Down

0 comments on commit e9d6a30

Please sign in to comment.