Example #1
0
        public static void makeSheets(Document curDoc, string[] tblockName, string vPortName, string CSVFile, string sheetType)
        {
            //arguments are: document, title block to use for new sheets, viewport type for views and path to CSV file with sheet names, numbers and views

            //check if title block exists
            FamilySymbol tblock = null;

            if (mFunctions.doesTblockExist(curDoc, tblockName) == true)
            {
                //get tblock
                tblock = mFunctions.getTitleblock(curDoc, tblockName);
            }
            else
            {
                TaskDialog.Show("alert", "Could not find titleblock");
                return;
            }

            //success and failures
            List <string> m_s = new List <string>();
            List <string> m_f = new List <string>();

            //check if CSV file exists
            if (System.IO.File.Exists(CSVFile) == false)
            {
                //file doesn't exist - abort
                TaskDialog.Show("Error", "The CSV file " + CSVFile + " cannot be found.");
                return;
            }

            //transaction
            using (Transaction t = new Transaction(curDoc, "Create Sheets")) {
                if (t.Start() == TransactionStatus.Started)
                {
                    //the sheet object
                    ViewSheet m_vs = null;

                    //read CSV file and create sheet based on info
                    IList <structSheet> sheetList = null;
                    sheetList = mFunctions.ReadCSV(CSVFile, true);

                    //create sheet for each sheet in list
                    foreach (structSheet curSheet in sheetList)
                    {
                        try {
                            //create sheets
                            if (sheetType == "Placeholder Sheet")
                            {
                                m_vs = ViewSheet.CreatePlaceholder(curDoc);
                            }
                            else
                            {
                                m_vs = ViewSheet.Create(curDoc, tblock.Id);
                            }

                            m_vs.Name        = curSheet.sheetName;
                            m_vs.SheetNumber = curSheet.sheetNum;

                            //record success
                            m_s.Add("Created sheet: " + m_vs.SheetNumber + " " + Constants.vbCr);

                            //loop through view string and add views to sheet
                            foreach (string tmpView in curSheet.viewName.Split(new char[] { ',' }))
                            {
                                //get current view
                                View curView = mFunctions.getView(tmpView.Trim(), curDoc);

                                Viewport curVP = null;
                                try {
                                    if (Viewport.CanAddViewToSheet(curDoc, m_vs.Id, curView.Id))
                                    {
                                        //add it
                                        curVP = Viewport.Create(curDoc, m_vs.Id, curView.Id, new XYZ(0, 0, 0));

                                        //center viewport on sheet
                                        mFunctions.centerViewOnSheet(curVP, curView, m_vs, curDoc);

                                        //change viewport type of plan view to no title
                                        ElementId vpTypeID = null;
                                        vpTypeID = mFunctions.getViewportTypeID(vPortName, curDoc);
                                        curVP.ChangeTypeId(vpTypeID);

                                        //record success
                                        m_s.Add("Added view: " + curView.Name + " " + Constants.vbCr);
                                    }
                                } catch (Exception ex1) {
                                    m_f.Add("Could not add view " + tmpView + " to sheet " + m_vs.SheetNumber + Constants.vbCr);
                                }
                            }
                        } catch (Exception ex2) {
                            //record failure
                            m_f.Add("sheet error: " + ex2.Message);
                        }
                    }

                    //commit
                    t.Commit();

                    //report sheets created
                    if (m_s.Count > 0)
                    {
                        using (TaskDialog m_td = new TaskDialog("Success!!")) {
                            m_td.MainInstruction = "Created Sheets:";
                            foreach (string x_loopVariable in m_s)
                            {
                                //x = x_loopVariable;
                                m_td.MainContent += x_loopVariable;
                            }

                            //show dialog
                            m_td.Show();
                        }
                    }

                    if (m_f.Count > 0)
                    {
                        using (TaskDialog m_td2 = new TaskDialog("Failures")) {
                            m_td2.MainInstruction = "Problems:";
                            foreach (string x_loopVariable in m_f)
                            {
                                //x = x_loopVariable;
                                m_td2.MainContent += x_loopVariable;
                            }

                            //show dialog
                            m_td2.Show();
                        }
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Submits request to create new sheet.
        /// </summary>
        /// <param name="app"></param>
        private void CreateSheet(UIApplication app)
        {
            var doc = app.ActiveUIDocument.Document;

            CentralPath = FileInfoUtil.GetCentralFilePath(doc);

            IsUpdatingSheet = true;
            app.Application.FailuresProcessing += FailureProcessing;

            using (var trans = new Transaction(doc, "CreateSheet"))
            {
                trans.Start();

                try
                {
                    ViewSheet sheet;
                    if (SheetTask.IsPlaceholder)
                    {
                        sheet = ViewSheet.CreatePlaceholder(doc);
                    }
                    else
                    {
                        // TODO: This should be exposed to user in Mission Control.
                        var titleblock = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).FirstOrDefault(x => x.Category.Name == "Title Blocks");
                        if (titleblock == null)
                        {
                            IsUpdatingSheet = false;
                            Messenger.Default.Send(new SheetTaskCompletedMessage
                            {
                                Completed   = false,
                                Message     = "Could not find a valid TitleBlock.",
                                CentralPath = CentralPath
                            });
                            return;
                        }
                        sheet = ViewSheet.Create(doc, titleblock.Id);
                    }

                    sheet.get_Parameter(BuiltInParameter.SHEET_NUMBER)?.Set(SheetTask.Number);
                    sheet.get_Parameter(BuiltInParameter.SHEET_NAME)?.Set(SheetTask.Name);

                    // (Konrad) We can set this here and pick up in the UI before sending off to MongoDB.
                    var newSheetItem = new SheetItem(sheet, CentralPath)
                    {
                        Tasks        = SheetItem.Tasks,
                        CollectionId = SheetItem.CollectionId,
                        Id           = SheetItem.Id,
                        IsNewSheet   = true // this was overriden to false by default constructor
                    };
                    SheetItem = newSheetItem;

                    trans.Commit();
                    IsUpdatingSheet = false;
                }
                catch (Exception e)
                {
                    trans.RollBack();
                    IsUpdatingSheet = false;

                    Log.AppendLog(LogMessageType.EXCEPTION, "Failed to create sheet.");
                    Messenger.Default.Send(new SheetTaskCompletedMessage
                    {
                        Completed   = false,
                        Message     = e.Message,
                        CentralPath = CentralPath
                    });
                }
            }

            // (Konrad) We don't want Revit to keep triggering this even when we are not processing updates.
            app.Application.FailuresProcessing -= FailureProcessing;
        }
Example #3
0
        public SheetsISFLRequest(UIApplication uiApp, String text)
        {
            MainUI     uiForm = BARevitTools.Application.thisApp.newMainUi;
            UIDocument uidoc  = uiApp.ActiveUIDocument;

            //Start a transaction
            Transaction t1 = new Transaction(uidoc.Document, "InsertSheetsFromLink");

            t1.Start();
            //Cycle through each row in the DataGridView
            foreach (DataGridViewRow row in uiForm.sheetsISFLDataGridView.Rows)
            {
                if (row.Cells["To Add"].Value != null)
                {
                    //If the checkbox to add the sheet is checked, and the sheet already exists
                    if (row.Cells["To Add"].Value.ToString() == "True" && row.Cells["Pre-exists"].Value.ToString() == "True")
                    {
                        //Get the sheet number of the old sheet
                        string sheetToDelete = row.Cells["Sheet Number"].Value.ToString();
                        //Collect the sheets in the project
                        IList <Element> sheetsCollector = new FilteredElementCollector(uidoc.Document).OfClass(typeof(ViewSheet)).ToElements();
                        foreach (Element elem in sheetsCollector)
                        {
                            ViewSheet viewSheet = elem as ViewSheet;
                            //If the sheet number of the sheet to delete matches the sheet being evaluated, and the sheet being evaluated is a placeholder, continue
                            //It is important that the sheet is placeholder and not a sheet that could potentially have views on it
                            if (viewSheet.SheetNumber == sheetToDelete && viewSheet.IsPlaceholder == true)
                            {
                                try
                                {
                                    //Use a subtransaction to delete the sheet view
                                    SubTransaction deleteTransaction = new SubTransaction(uidoc.Document);
                                    deleteTransaction.Start();
                                    uidoc.Document.Delete(viewSheet.Id);
                                    deleteTransaction.Commit();
                                }
                                catch { continue; }
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                    //Otherwise, if the sheet does not already exist, continue
                    if (row.Cells["To Add"].Value.ToString() == "True")
                    {
                        try
                        {
                            //Create a new placeholder sheet
                            ViewSheet newSheet = ViewSheet.CreatePlaceholder(uidoc.Document);
                            newSheet.SheetNumber = row.Cells["Sheet Number"].Value.ToString();
                            //Set the new placeholder sheet's name
                            if (row.Cells["Host Sheet Name"].Value.ToString() == "" || row.Cells["Host Sheet Name"].Value.ToString() == "Sheet")
                            {
                                newSheet.Name = row.Cells["Link Sheet Name"].Value.ToString();
                            }
                            else
                            {
                                newSheet.Name = row.Cells["Host Sheet Name"].Value.ToString();
                            }
                            //Get the list of sheet parameters and find the BA Sheet Discipline parameter
                            IList <Parameter> disciplineParameters = newSheet.GetParameters(Properties.Settings.Default.BASheetDisciplineParameter);
                            foreach (Parameter param in disciplineParameters)
                            {
                                try
                                {
                                    //Set the BA Sheet Discipline from the value in the DataGridView
                                    param.Set(row.Cells["Discipline"].Value.ToString());
                                }
                                catch { continue; }
                            }
                        }
                        catch { continue; }
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    continue;
                }
            }
            t1.Commit();
            //Update the DataGridView with fresh data using the inserted sheets and sheets from the link
            RVTDocument linkDoc = uiForm.SheetsISFLGetLinkDoc();

            uiForm.SheetsISFLUpdateDataGridView(linkDoc);
        }