Ejemplo n.º 1
0
        public static List <TreeViewModel> SetTreeBySheet(string docName, Dictionary <int, ViewProperties> selectedViews, List <string> sheetNumbers)
        {
            List <TreeViewModel> treeView = new List <TreeViewModel>();

            try
            {
                TreeViewModel tv = new TreeViewModel("Sheets (" + docName + ")");
                tv.Tag = docName;
                treeView.Add(tv);

                foreach (string sheetNumber in sheetNumbers)
                {
                    var viewItems = from viewItem in selectedViews.Values where viewItem.SheetNumber == sheetNumber select viewItem;
                    if (viewItems.Count() > 0)
                    {
                        ViewProperties firstProperties = viewItems.First();
                        string         sheetName       = firstProperties.SheetName;

                        TreeViewModel sheetItem = new TreeViewModel(sheetNumber + " - " + sheetName);
                        sheetItem.Tag = sheetNumber;
                        tv.Children.Add(sheetItem);

                        foreach (ViewProperties vp in viewItems)
                        {
                            TreeViewModel viewItem = new TreeViewModel(vp.ViewName, vp.Status);
                            viewItem.Tag = vp.ViewId;
                            switch (vp.Status)
                            {
                            case LinkStatus.Linked:
                                if (null != vp.LinkedView)
                                {
                                    viewItem.ToolTip = "Linked Id: " + vp.LinkedView.ViewId.ToString() + " Name: " + vp.LinkedView.ViewName;
                                }
                                break;

                            case LinkStatus.MissingFromRecipient:
                                viewItem.ToolTip = "Missing From Recipient";
                                break;

                            case LinkStatus.MissingFromSource:
                                viewItem.ToolTip = "Missing From Source";
                                break;

                            case LinkStatus.None:
                                viewItem.ToolTip = "New Item";
                                break;
                            }
                            sheetItem.Children.Add(viewItem);
                        }
                        sheetItem.Children.OrderBy(child => child.Name).ToList();
                    }
                }
                tv.Initialize();
            }
            catch (Exception ex)
            {
                MessageBox.Show(docName + ": Failed to initialize the treview.\n" + ex.Message, "SetTreeBySheet", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(treeView);
        }
Ejemplo n.º 2
0
        private void buttonAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (null != listViewSource.SelectedItem && null != listViewRecipient.SelectedItem)
                {
                    if (listViewSource.SelectedItems.Count > 1)
                    {
                        MessageBox.Show("Please select only one item from the list of the source view.", "Multiple Source View Selected", MessageBoxButton.OK, MessageBoxImage.Warning);
                        return;
                    }

                    ListViewItem   sItem = (ListViewItem)listViewSource.SelectedItem;
                    ViewProperties sView = (ViewProperties)sItem.Tag;

                    ListViewItem   rItem = (ListViewItem)listViewRecipient.SelectedItem;
                    ViewProperties rview = (ViewProperties)rItem.Tag;

                    sView.LinkedView = rview;
                    rview.LinkedView = sView;

                    if (sourceViews.ContainsKey(sView.ViewId))
                    {
                        sourceViews.Remove(sView.ViewId);
                        sourceViews.Add(sView.ViewId, sView);
                    }
                    if (recipientViews.ContainsKey(rview.ViewId))
                    {
                        recipientViews.Remove(rview.ViewId);
                        recipientViews.Add(rview.ViewId, rview);
                    }

                    LinkInfo linkInfo = new LinkInfo();
                    linkInfo.ItemType        = LinkItemType.DraftingView;
                    linkInfo.SourceModelName = sourceInfo.DocTitle;
                    linkInfo.SourceModelPath = sourceInfo.DocCentralPath;
                    linkInfo.SourceModelId   = sourceInfo.RevitDocumentID;
                    linkInfo.SourceItemId    = sView.ViewId;
                    linkInfo.SourceItemName  = sView.ViewName;
                    linkInfo.DestModelName   = recipientInfo.DocTitle;
                    linkInfo.DestModelPath   = recipientInfo.DocCentralPath;
                    linkInfo.DestItemId      = rview.ViewId;
                    linkInfo.DestItemName    = rview.ViewName;

                    linkInfo.ItemStatus = LinkItemStatus.Added;
                    listLinkInfo.Add(linkInfo);

                    DisplayViews();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to add linked items.\n" + ex.Message, "Add View Links", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Ejemplo n.º 3
0
        private bool CreateLinksByNames()
        {
            bool createdLinks = false;

            try
            {
                foreach (ViewProperties sView in sourceViews.Values)
                {
                    //create links
                    string viewName = sView.ViewName;
                    var    views    = from view in recipientViews.Values where view.ViewName == viewName select view;
                    if (views.Count() > 0)
                    {
                        ViewProperties rView = views.First();

                        LinkInfo li = new LinkInfo();
                        li.ItemType        = LinkItemType.DraftingView;
                        li.SourceModelName = sourceInfo.DocTitle;
                        li.SourceModelPath = sourceInfo.DocCentralPath;
                        li.SourceModelId   = sourceInfo.RevitDocumentID;
                        li.DestModelName   = recipientInfo.DocTitle;
                        li.DestModelPath   = recipientInfo.DocCentralPath;

                        li.SourceItemId   = sView.ViewId;
                        li.SourceItemName = sView.ViewName;
                        li.DestItemId     = rView.ViewId;
                        li.DestItemName   = rView.ViewName;

                        li.LinkModified   = DateTime.Now.ToString("G");
                        li.LinkModifiedBy = Environment.UserName;

                        li.ItemStatus = LinkItemStatus.Added;
                        int index = linkInfoList.FindIndex(info => info.SourceItemId == sView.ViewId);
                        if (index > -1)
                        {
                            li.ItemStatus = LinkItemStatus.Updated;
                            //duplicate list
                            linkInfoList.RemoveAt(index);
                        }

                        linkInfoList.Add(li);
                    }
                }
                createdLinks = true;

                //update model info
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create links by view names.\n" + ex.Message, "Create Links By Names", MessageBoxButton.OK, MessageBoxImage.Warning);
                createdLinks = false;
            }
            return(createdLinks);
        }
Ejemplo n.º 4
0
        private void SetLinkStatus()
        {
            try
            {
                foreach (LinkInfo info in linkInfoList)
                {
                    if (info.ItemStatus == LinkItemStatus.Deleted)
                    {
                        continue;
                    }
                    int sourceId = info.SourceItemId;
                    int destId   = info.DestItemId;
                    if (sourceViews.ContainsKey(sourceId) && recipientViews.ContainsKey(destId))
                    {
                        ViewProperties sView = sourceViews[sourceId];
                        ViewProperties rView = recipientViews[destId];
                        sView.Status     = LinkStatus.Linked;
                        rView.Status     = LinkStatus.Linked;
                        sView.LinkedView = rView;
                        rView.LinkedView = sView;

                        sourceViews.Remove(sourceId);
                        sourceViews.Add(sourceId, sView);

                        recipientViews.Remove(destId);
                        recipientViews.Add(destId, rView);
                    }
                    else if (sourceViews.ContainsKey(sourceId) && !recipientViews.ContainsKey(destId))
                    {
                        ViewProperties sView = sourceViews[sourceId];
                        sView.Status = LinkStatus.MissingFromRecipient;

                        sourceViews.Remove(sourceId);
                        sourceViews.Add(sourceId, sView);
                    }
                    else if (!sourceViews.ContainsKey(sourceId) && recipientViews.ContainsKey(destId))
                    {
                        ViewProperties rView = recipientViews[destId];
                        rView.Status = LinkStatus.MissingFromSource;

                        recipientViews.Remove(destId);
                        recipientViews.Add(destId, rView);
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
        }
Ejemplo n.º 5
0
        private Dictionary <int, ViewProperties> GetDraftingViewInfo(Document doc)
        {
            Dictionary <int, ViewProperties> viewDictionary = new Dictionary <int, ViewProperties>();

            try
            {
                FilteredElementCollector collector        = new FilteredElementCollector(doc);
                List <ViewDrafting>      viewDraftingList = collector.OfClass(typeof(ViewDrafting)).WhereElementIsNotElementType().ToElements().Cast <ViewDrafting>().ToList();

                foreach (ViewDrafting view in viewDraftingList)
                {
                    if (view.ViewType != ViewType.DraftingView)
                    {
                        continue;
                    }
                    if (!viewDictionary.ContainsKey(view.Id.IntegerValue))
                    {
                        ViewProperties vp = new ViewProperties(doc, view);
                        viewDictionary.Add(vp.ViewId, vp);
                        if (!viewTypeNames.Contains(vp.ViewTypeName))
                        {
                            viewTypeNames.Add(vp.ViewTypeName);
                        }
                        if (vp.IsOnSheet && !string.IsNullOrEmpty(vp.SheetNumber))
                        {
                            if (!sheetNumbers.Contains(vp.SheetNumber))
                            {
                                sheetNumbers.Add(vp.SheetNumber);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to get the information of drafting views.\n" + ex.Message, "Get Drafting Views", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(viewDictionary);
        }
Ejemplo n.º 6
0
        private void buttonDelete_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (null != listViewMap.SelectedItems)
                {
                    for (int i = listViewMap.SelectedItems.Count - 1; i > -1; i--)
                    {
                        LinkInfo link  = (LinkInfo)listViewMap.SelectedItems[i];
                        int      index = listLinkInfo.IndexOf(link);
                        listLinkInfo.RemoveAt(index);
                        link.ItemStatus = LinkItemStatus.Deleted;
                        listLinkInfo.Add(link);

                        if (sourceViews.ContainsKey(link.SourceItemId))
                        {
                            ViewProperties vp = sourceViews[link.SourceItemId];
                            vp.LinkedView = null;
                            sourceViews.Remove(vp.ViewId);
                            sourceViews.Add(vp.ViewId, vp);
                        }

                        if (recipientViews.ContainsKey(link.DestItemId))
                        {
                            ViewProperties vp = recipientViews[link.DestItemId];
                            vp.LinkedView = null;
                            recipientViews.Remove(vp.ViewId);
                            recipientViews.Add(vp.ViewId, vp);
                        }
                    }
                    DisplayViews();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to delete linked items.\n" + ex.Message, "Delete View Links", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Ejemplo n.º 7
0
        private void buttonForget_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //Remove the record of the links from Google spreadsheet
                if (null != listViewSource.SelectedItems)
                {
                    for (int i = 0; i < listViewSource.SelectedItems.Count; i++)
                    {
                        ListViewItem   item = listViewSource.SelectedItems[i] as ListViewItem;
                        ViewProperties vp   = (ViewProperties)item.Tag;
                        if (sourceViews.ContainsKey(vp.ViewId))
                        {
                            vp.Status = LinkStatus.None;
                            sourceViews.Remove(vp.ViewId);
                            sourceViews.Add(vp.ViewId, vp);
                        }


                        var linkItems = from litem in listLinkInfo where litem.SourceItemId == vp.ViewId select litem;
                        if (linkItems.Count() > 0)
                        {
                            LinkInfo linkInfo = linkItems.First();
                            int      index    = listLinkInfo.IndexOf(linkInfo);
                            listLinkInfo.RemoveAt(index);
                            linkInfo.ItemStatus = LinkItemStatus.Deleted;
                            listLinkInfo.Add(linkInfo);
                        }
                    }
                    DisplayViews();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to remove records of the links.\n" + ex.Message, "Remove Links Records", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Ejemplo n.º 8
0
        public void GetInfo()
        {
            try
            {
                docName    = m_doc.Title;
                uniqueId   = m_view.UniqueId;
                viewId     = m_view.Id.IntegerValue;
                viewName   = m_view.Name;
                viewTypeID = m_view.GetTypeId().IntegerValue;
                ViewFamilyType viewType = m_doc.GetElement(m_view.GetTypeId()) as ViewFamilyType;
                if (null != viewType)
                {
                    viewTypeName = viewType.Name;
                }

                Parameter sheetNumberParam = m_view.get_Parameter(BuiltInParameter.VIEWPORT_SHEET_NUMBER);
                Parameter sheetNameParam   = m_view.get_Parameter(BuiltInParameter.VIEWPORT_SHEET_NAME);
                if (null != sheetNumberParam && null != sheetNameParam)
                {
                    if (!string.IsNullOrEmpty(sheetNumberParam.AsString()) && !string.IsNullOrEmpty(sheetNameParam.AsString()))
                    {
                        sheetNumber  = sheetNumberParam.AsString();
                        sheetName    = sheetNameParam.AsString();
                        isOnSheet    = true;
                        sheetObj     = FindSheet(sheetNumber, sheetName);
                        viewLocation = FindViewLocation(sheetObj);
                    }
                }

                ICollection <ElementId> referenceCalloutIds = m_view.GetReferenceCallouts();
                if (referenceCalloutIds.Count > 0)
                {
                    foreach (ElementId eId in referenceCalloutIds)
                    {
                        Element callout = m_doc.GetElement(eId);
                        if (null != callout)
                        {
                            Parameter param = callout.get_Parameter(BuiltInParameter.ID_PARAM);
                            if (null != param)
                            {
                                ElementId    referenceViewId = param.AsElementId();
                                ViewDrafting referenceView   = m_doc.GetElement(referenceViewId) as ViewDrafting;
                                if (null != referenceView)
                                {
                                    ViewProperties vp = new ViewProperties(m_doc, referenceView);
                                    if (!dependantViews.ContainsKey(vp.ViewId))
                                    {
                                        dependantViews.Add(vp.ViewId, vp);
                                    }
                                }
                            }
                        }
                    }
                }

                ICollection <ElementId> referenceSectionIds = m_view.GetReferenceSections();
                if (referenceSectionIds.Count > 0)
                {
                    foreach (ElementId eId in referenceSectionIds)
                    {
                        Element marker = m_doc.GetElement(eId);
                        if (null != marker)
                        {
                            Parameter param = marker.get_Parameter(BuiltInParameter.ID_PARAM);
                            if (null != param)
                            {
                                ElementId    referenceViewId = param.AsElementId();
                                ViewDrafting referenceView   = m_doc.GetElement(referenceViewId) as ViewDrafting;
                                if (null != referenceView)
                                {
                                    ViewProperties vp = new ViewProperties(m_doc, referenceView);
                                    if (!dependantViews.ContainsKey(vp.ViewId))
                                    {
                                        dependantViews.Add(vp.ViewId, vp);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
        }
Ejemplo n.º 9
0
        private bool UpdateRecipientViewDictionary(ModelInfo recipientInfo, List <PreviewMap> mapList)
        {
            bool updated = false;

            try
            {
                //update link info
                ObservableCollection <LinkInfo>  linkInfoCollection = recipientInfo.LinkInfoCollection;
                Dictionary <int, ViewProperties> viewDictionary     = recipientInfo.ViewDictionary;
                foreach (PreviewMap map in mapList)
                {
                    LinkInfo info = map.ViewLinkInfo;
                    if (info.DestItemId == -1)
                    {
                        continue;
                    }                                        //skipped items
                    var foundLink = linkInfoCollection.Where(x => x.SourceModelId == info.SourceModelId && x.SourceItemId == info.SourceItemId);
                    if (foundLink.Count() > 0)
                    {
                        int index = linkInfoCollection.IndexOf(foundLink.First());
                        if (linkInfoCollection[index].ItemStatus == LinkItemStatus.None) //existing in the spreadsheet
                        {
                            linkInfoCollection[index]            = info;
                            linkInfoCollection[index].ItemStatus = LinkItemStatus.Updated;
                        }
                    }
                    else if (info.ItemStatus == LinkItemStatus.None)
                    {
                        info.ItemStatus = LinkItemStatus.Added;
                        linkInfoCollection.Add(info);
                    }

                    ViewProperties vp = map.RecipientViewProperties;
                    if (null != vp)
                    {
                        if (viewDictionary.ContainsKey(vp.ViewId))
                        {
                            viewDictionary.Remove(vp.ViewId);
                        }
                        viewDictionary.Add(vp.ViewId, vp);
                    }
                }

                //update dictionary
                recipientInfo.LinkInfoCollection = linkInfoCollection;
                recipientInfo.ViewDictionary     = viewDictionary;

                if (modelInfoDictionary.ContainsKey(recipientInfo.RevitDocumentID))
                {
                    modelInfoDictionary.Remove(recipientInfo.RevitDocumentID);
                }

                modelInfoDictionary.Add(recipientInfo.RevitDocumentID, recipientInfo);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to update the recipient model info.\n" + ex.Message, "Update Recipient Model Info", MessageBoxButton.OK, MessageBoxImage.Warning);
                updated = false;
            }
            return(updated);
        }
Ejemplo n.º 10
0
        public bool UpdateDraftingViews(ModelInfo sourceInfo, ModelInfo recipientInfo, TreeView treeViewSource, TreeView treeViewRecipient, bool createSheet, bool createLinks, TextBlock statusLable, ProgressBar progressBar)
        {
            bool result = false;

            try
            {
                List <int>        sourceViewIds  = new List <int>();
                List <PreviewMap> previewMapList = new List <PreviewMap>();

                ViewMapClass vmc = new ViewMapClass(sourceInfo, recipientInfo, createLinks);
                Dictionary <int, ViewProperties> sourceViews    = vmc.SourceViews;
                Dictionary <int, ViewProperties> recipientViews = vmc.RecipientViews;

                List <TreeViewModel> treeviewModels = treeViewSource.ItemsSource as List <TreeViewModel>;
                foreach (TreeViewModel rootNode in treeviewModels)
                {
                    foreach (TreeViewModel secondNode in rootNode.Children)
                    {
                        foreach (TreeViewModel viewNode in secondNode.Children)
                        {
                            if (viewNode.IsChecked == true)
                            {
                                int viewId = 0;
                                if (int.TryParse(viewNode.Tag.ToString(), out viewId))
                                {
                                    if (sourceViews.ContainsKey(viewId) && !sourceViewIds.Contains(viewId))
                                    {
                                        ViewProperties viewSource = sourceViews[viewId];
                                        if (viewSource.DependantViews.Count > 0)
                                        {
                                            foreach (int dependentId in viewSource.DependantViews.Keys)
                                            {
                                                if (!sourceViewIds.Contains(dependentId))
                                                {
                                                    ViewProperties dependentSource    = viewSource.DependantViews[dependentId];
                                                    ViewProperties dependentRecipient = null;
                                                    LinkInfo       dependantlinkInfo  = new LinkInfo();
                                                    if (null != dependentSource.LinkedView)
                                                    {
                                                        dependentRecipient = dependentSource.LinkedView;
                                                        var linkInfoList = from info in vmc.LinkInfoList where info.SourceItemId == dependentId && info.DestItemId == dependentRecipient.ViewId select info;
                                                        if (linkInfoList.Count() > 0)
                                                        {
                                                            dependantlinkInfo = linkInfoList.First();
                                                        }
                                                    }

                                                    PreviewMap dependantView = new PreviewMap();
                                                    dependantView.SourceModelInfo         = sourceInfo;
                                                    dependantView.RecipientModelInfo      = recipientInfo;
                                                    dependantView.SourceViewProperties    = dependentSource;
                                                    dependantView.RecipientViewProperties = dependentRecipient;
                                                    dependantView.ViewLinkInfo            = dependantlinkInfo;
                                                    dependantView.IsEnabled = true;

                                                    sourceViewIds.Add(dependentId);
                                                    previewMapList.Add(dependantView);
                                                }
                                            }
                                        }

                                        ViewProperties viewRecipient = null;
                                        LinkInfo       linkInfo      = new LinkInfo();
                                        if (null != viewSource.LinkedView)
                                        {
                                            viewRecipient = viewSource.LinkedView;
                                            var linkInfoList = from info in vmc.LinkInfoList where info.SourceItemId == viewId && info.DestItemId == viewRecipient.ViewId && info.ItemStatus != LinkItemStatus.Deleted select info;
                                            if (linkInfoList.Count() > 0)
                                            {
                                                linkInfo = linkInfoList.First();
                                            }
                                        }

                                        PreviewMap preview = new PreviewMap();
                                        preview.SourceModelInfo         = sourceInfo;
                                        preview.RecipientModelInfo      = recipientInfo;
                                        preview.SourceViewProperties    = viewSource;
                                        preview.RecipientViewProperties = viewRecipient;
                                        preview.ViewLinkInfo            = linkInfo;
                                        preview.IsEnabled = true;

                                        sourceViewIds.Add(viewId);
                                        previewMapList.Add(preview);
                                    }
                                }
                            }
                        }
                    }
                }

                if (previewMapList.Count > 0)
                {
                    PreviewWindow pWindow = new PreviewWindow(previewMapList, createSheet);
                    if (true == pWindow.ShowDialog())
                    {
                        previewMapList = pWindow.PreviewMapList;

                        progressBar.Visibility = System.Windows.Visibility.Visible;
                        statusLable.Visibility = System.Windows.Visibility.Visible;

                        bool updatedDictionary  = UpdateRecipientViewDictionary(recipientInfo, previewMapList);
                        bool updatedGoogleSheet = GoogleSheetUtil.WriteLinkIfo(recipientInfo.GoogleSheetID, recipientInfo.LinkInfoCollection);
                        bool updatedLinkStatus  = UpdateLinkStatus(recipientInfo);

                        progressBar.Visibility = System.Windows.Visibility.Hidden;
                        statusLable.Visibility = System.Windows.Visibility.Hidden;
                    }
                }
                else
                {
                    MessageBox.Show("Please select at least one source item to duplicate views.", "Select a Source Item", MessageBoxButton.OK, MessageBoxImage.Information);
                    result = false;
                }
                result = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to update drafting views.\n" + ex.Message, "Update Drafting Views", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(result);
        }