示例#1
0
        private void updateDocumentList(Document selectedDocument)
        {
            // fill the documents to the comboxbox _cbDocuments.
            DBDocumentItem activeItem = null;

            _cbDocuments.Items.Clear();
            DocumentSetIterator docIter = _application.Documents.ForwardIterator();

            docIter.Reset();
            while (docIter.MoveNext())
            {
                Document       dbDoc        = docIter.Current as Document;
                String         documentName = null;
                DBDocumentItem item         = null;
                if (dbDoc != null)
                {
                    if (dbDoc.IsFamilyDocument)
                    {
                        item = new DBDocumentItem(dbDoc.PathName, dbDoc);
                    }
                    else
                    {
                        String projName = dbDoc.ProjectInformation.Name;
                        if (String.IsNullOrEmpty(projName) || projName.ToLower().CompareTo("project name") == 0)
                        {
                            if (String.IsNullOrEmpty(dbDoc.PathName))
                            {
                                documentName = projName;
                            }
                            else
                            {
                                documentName = new System.IO.FileInfo(dbDoc.PathName).Name;
                            }
                        }
                        else
                        {
                            documentName = projName;
                        }

                        item = new DBDocumentItem(documentName, dbDoc);
                    }
                    if (dbDoc.Equals(selectedDocument))
                    {
                        _dbDocument = selectedDocument;
                        activeItem  = item;
                    }
                    _cbDocuments.Items.Add(item);
                }
            }
            _cbDocuments.Items.Add(new DBDocumentItem());
            _cbDocuments.SelectedItem = activeItem;
        }
示例#2
0
        private void cbDocs_SelIdxChanged(object sender, EventArgs e)
        {
            DBDocumentItem documentItem = _cbDocuments.SelectedItem as DBDocumentItem;

            if (documentItem.Document == _dbDocument)
            {
                return;
            }

            if (documentItem.IsNull)
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.DefaultExt = "rvt";
                ofd.Filter     = "Revit project files (*.rvt)|*.rvt|Revit family files (*.rfa)|*.rfa|Revit family template files (*.rft)|*.rft";
                if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    try
                    {
                        _dbDocument = _application.OpenDocumentFile(ofd.FileName);
                    }
                    catch (System.Exception)
                    {
                    }
                    if (_dbDocument != null)
                    {
                        updateDocumentList(_dbDocument);
                        updateViewsList(null);
                    }
                }
                else
                {
                    // the combobox should show the current document item.
                    String documentName;
                    String projName = _dbDocument.ProjectInformation.Name;
                    if (String.IsNullOrEmpty(projName) || projName.ToLower().CompareTo("project name") == 0)
                    {
                        if (String.IsNullOrEmpty(_dbDocument.PathName))
                        {
                            documentName = projName;
                        }
                        else
                        {
                            documentName = new System.IO.FileInfo(_dbDocument.PathName).Name;
                        }
                    }
                    else
                    {
                        documentName = projName;
                    }

                    foreach (DBDocumentItem dbItem in _cbDocuments.Items)
                    {
                        if (dbItem.Name.ToLower().CompareTo(documentName.ToLower()) == 0)
                        {
                            _cbDocuments.SelectedItem = dbItem;
                            break;
                        }
                    }
                }
            }
            else
            {
                _dbDocument = documentItem.Document;
                updateViewsList(null);
            }
        }