Example #1
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;
            Document      doc   = uidoc.Document;

            Translate translation = new Translate();
            string    path        = @"W:\S\BIM\Z-LINKED EXCEL\SOM-Chinese Translation.xlsx";
            //used to debug.
            //string path = @"C:\SOM-Chinese Translation.xlsx";

            //Project file path and name to track sheets annotations and titles.
            string centralFilePath = ModelPathUtils.ConvertModelPathToUserVisiblePath(doc.GetWorksharingCentralModelPath());

            //Translation for Annotations, Title on Sheets and Sheet Names
            translation.StartTranslation(doc, app, path, centralFilePath);
            // Annotations which are not translated.
            List <string[]> UpdateExcelTranslationGenericAnno         = translation._UpdateExcelTranslationGenericAnno;
            Dictionary <string, string[]> Anno_IDandEnglishDictionary = new Dictionary <string, string[]>();

            // Title on sheets not translated
            List <string[]> NotTranslatedTitleOnSheet = translation._NotTranslatedTitleOnSheet;
            // Title on sheet which was on hold is found in Revit.
            List <string[]> HoldIsFoundInRevitTitleOnSheet = translation._HoldIsFoundInRevitTitleOnSheet;
            // Dictionary of Key and Values from Excel
            Dictionary <string, string[]> TitleOnSheet_IDEnglishChineseDict = translation._TitleOnSheet_IDEnglishChineseDict;
            // Sheet names not translated
            List <string[]> NotTranslatedSheets = translation._NotTranslatedSheets;
            // Sheet which is on hold is found in Revit.
            List <string[]> HoldIsFoundInRevitTSheets = translation._HoldIsFoundInRevitSheets;
            // Dictionary of Key and Values from Excel
            Dictionary <string, string[]> Sheet_IDEnglishChineseDict = translation._Sheet_IDEnglishChineseDict;
            string BuildingName = doc.ProjectInformation.BuildingName;

            // Get project paramter Author number to assign color.
            var BuildingColor = doc.ProjectInformation.Author;

            //Annotation Excel Sheet
            if (UpdateExcelTranslationGenericAnno.Count > 0)
            {
                ExcelSheet Excel = new ExcelSheet();
                Excel.Update(Anno_IDandEnglishDictionary, UpdateExcelTranslationGenericAnno, path, 1, "");
            }
            //Title on Sheet Excel Sheet
            if (NotTranslatedTitleOnSheet.Count > 0)
            {
                // combine dictionarys to update Excel file.
                HoldIsFoundInRevitTitleOnSheet.AddRange(NotTranslatedTitleOnSheet);
            }
            //Title on Sheet Hold was found
            if (HoldIsFoundInRevitTitleOnSheet.Count > 0)
            {
                ExcelSheet Excel = new ExcelSheet();
                Excel.Update(TitleOnSheet_IDEnglishChineseDict, HoldIsFoundInRevitTitleOnSheet, path, 2, BuildingColor);
            }
            //Sheet Name Excel Sheet
            if (NotTranslatedSheets.Count > 0)
            {
                // combine dictionarys to update Excel file.
                HoldIsFoundInRevitTSheets.AddRange(NotTranslatedSheets);
            }

            //Sheet Hold was found
            if (HoldIsFoundInRevitTSheets.Count > 0)
            {
                ExcelSheet Excel = new ExcelSheet();
                Excel.Update(Sheet_IDEnglishChineseDict, HoldIsFoundInRevitTSheets, path, 3, BuildingColor);
            }
            return(Result.Succeeded);
        }
Example #2
0
        //***********************************StartTranslation***********************************
        public void StartTranslation(Document doc, Application App, string path, string centralFilePath)
        {
            ExcelSheet Excel = new ExcelSheet();

            //Check Excel file for duplicate items to be deleted.
            Excel.Delete(path, 1, 2);
            // Collect data for annotation
            #region ANNOTATIONS

            //Dictionary of Annotations.  Key as English and value as Chinese.
            Dictionary <string, string> Excel_Anno_DictioinaryEnglishAndChinese = Excel.Read(path, 1);
            List <string> Excel_AnnotationCompareList = Excel.CompareList;

            //Dictionary of English words and Ids.
            Dictionary <string, string> _Anno_IDandEnglishDictionary = Excel._IDandEnglishDictionary;

            #endregion ANNOTATIONS

            // Collect data for title on sheets
            #region TITLE ON SHEETS

            //Dicationary of title on sheets. Key as English and value as Chinese.
            Dictionary <string, string> TitleOnSheetsDictionary = Excel.Read(path, 2);
            List <string> TitleOnSheetCompareList = Excel.CompareList;

            //Dictionary of English words and Ids.
            _TitleOnSheet_IDEnglishChineseDict = Excel._IDandArrayDictioinary;

            //Dictionary of English words and Ids.
            Dictionary <string, string[]> TitleOnSheet_HoldDict = Excel._HoldDictioinary;

            #endregion TITLE ON SHEETS

            // Collect data for sheets
            #region SHEET NUMBER

            //Dictionary of Sheet names. Key as English and value as Chinese.
            Dictionary <string, string> SheetsNameDictionary = Excel.Read(path, 3);
            List <string> SheetNameCompareList = Excel.CompareList;

            //Dictionary of English words and Ids.
            _Sheet_IDEnglishChineseDict = Excel._IDandArrayDictioinary;

            //Dictionary of English words and Ids.
            Dictionary <string, string[]> Sheet_HoldDict = Excel._HoldDictioinary;

            #endregion SHEET NUMBER

            //Update ANNOTATION
            TranslateGenericAnnotations TGA = new TranslateGenericAnnotations();
            if (_Anno_IDandEnglishDictionary != null)
            {
                TGA.SetEnglishAnnotationByID(doc, App,
                                             _Anno_IDandEnglishDictionary);
            }

            List <string[]> UpdateExcelTranslationGenericAnno = TGA.GenericAnnotationTranslation(doc, App,
                                                                                                 Excel_Anno_DictioinaryEnglishAndChinese,
                                                                                                 _Anno_IDandEnglishDictionary,
                                                                                                 Excel_AnnotationCompareList);

            //Update TITLE ON SHEETS
            TranslationTitleOnSheet TTOS = new TranslationTitleOnSheet();
            if (_TitleOnSheet_IDEnglishChineseDict != null)
            {
                _NotTranslatedTitleOnSheet = TTOS.SetEnglishTitleOnSheetByID(doc,
                                                                             _TitleOnSheet_IDEnglishChineseDict,
                                                                             TitleOnSheet_HoldDict,
                                                                             TitleOnSheetCompareList,
                                                                             Excel, path, centralFilePath);
            }

            //Update SHEET.
            TranslateSheets TS = new TranslateSheets();
            _NotTranslatedSheets = TS.SheetTranslation(doc,
                                                       _Sheet_IDEnglishChineseDict,
                                                       Sheet_HoldDict,
                                                       SheetNameCompareList,
                                                       path, centralFilePath);

            _HoldIsFoundInRevitSheets          = TS._HoldIsFoundInRevitSheets;
            _HoldIsFoundInRevitTitleOnSheet    = TTOS._HoldIsFoundInRevitTitleOnSheet;
            _UpdateExcelTranslationGenericAnno = UpdateExcelTranslationGenericAnno;
        }
Example #3
0
        //***********************************SetEnglishTitleOnSheetByID***********************************
        public List <string[]> SetEnglishTitleOnSheetByID(Document doc,
                                                          Dictionary <string, string[]> TitleOnSheet_IDEnglishChineseDict,
                                                          Dictionary <string, string[]> TitleOnSheet_HoldDict,
                                                          List <string> TitleOnSheetCompareList,
                                                          ExcelSheet Excel, string path, string centralFilePath)
        {
            RevitModelElements revit  = new RevitModelElements();
            List <ViewSheet>   sheets = revit.GetAllSheets(doc);
            //Filter to check only the views in current docuement.
            Dictionary <string, string[]> TitleOnSheetsToDeleteFromExcel = RemoveItemFromExcel(TitleOnSheet_IDEnglishChineseDict, centralFilePath);

            List <string[]> NotTranslated      = new List <string[]>();
            List <string[]> HoldIsFoundInRevit = new List <string[]>();

            foreach (ViewSheet vs in sheets)
            {
                try
                {
                    ICollection <ElementId> listViews = vs.GetAllViewports();
                    foreach (ElementId Elmids in listViews)
                    {
                        Element   elementViewports = doc.GetElement(Elmids);
                        Viewport  viewport         = elementViewports as Viewport;
                        ElementId viewId           = viewport.ViewId;
                        Element   elementView      = doc.GetElement(viewId);
                        Autodesk.Revit.DB.View v   = elementView as Autodesk.Revit.DB.View;

                        //Combine the sheet number and detail number to make a id
                        string sheetNumber  = viewport.get_Parameter(BuiltInParameter.VIEWPORT_SHEET_NUMBER).AsString();
                        string detailNumber = viewport.get_Parameter(BuiltInParameter.VIEWPORT_DETAIL_NUMBER).AsString();
                        string viewportID   = sheetNumber + "-" + detailNumber;

                        var       viewType                 = v.ViewType.ToString();
                        Parameter titleOnSheetParam        = v.LookupParameter("Title on Sheet");
                        Parameter titleOnSheetChineseParam = v.LookupParameter("Title on Sheet (Chinese)");
                        string    RvtChinese               = revit.GetParameterValue(titleOnSheetChineseParam);
                        string    RvtEnglish               = revit.GetParameterValue(titleOnSheetParam);

                        //Check if the viewport is on a Z sheet.
                        //If viewport is on Z sheet skip over it.
                        if (viewportID.StartsWith("z") || viewportID.StartsWith("Z"))
                        {
                            continue;
                        }

                        //Check if the title is in the database
                        if (TitleOnSheet_IDEnglishChineseDict.ContainsKey(viewportID))
                        {
                            string[] Values = TitleOnSheet_IDEnglishChineseDict[viewportID];
                            // If the Revit Chinese parameter is empty
                            // set the value from the database
                            if (RvtChinese == "" || RvtChinese == null)
                            {
                                // Set English note.
                                Transaction t = new Transaction(doc, "Translation by ID");
                                t.Start();
                                // Set english parameter.
                                titleOnSheetParam.Set(Values[0]);
                                titleOnSheetChineseParam.Set(Values[1]);
                                t.Commit();
                            }
                            //If view exists in Revit remove from list.
                            TitleOnSheetsToDeleteFromExcel.Remove(viewportID);
                        }

                        //Check if Project missing, but translation exists
                        //in Revit needs to be translated and project added to database.
                        if (TitleOnSheet_HoldDict.ContainsKey(viewportID))
                        {
                            string[] Values = TitleOnSheet_HoldDict[viewportID];

                            // Set English note.
                            Transaction t = new Transaction(doc, "Translation by ID");
                            t.Start();
                            // Set english parameter.
                            titleOnSheetParam.Set(Values[0]);
                            titleOnSheetChineseParam.Set(Values[1]);
                            t.Commit();
                            // add center file path to values.
                            // add to update excel from Revit model.
                            string[] array = new string[4];
                            array[0] = viewportID;
                            array[1] = Values[0];
                            array[2] = Values[1];
                            array[3] = centralFilePath;
                            HoldIsFoundInRevit.Add(array);
                            TitleOnSheetsToDeleteFromExcel.Add(viewportID, Values);
                        }

                        //if the dictionary doesn't have translation add to Excel.
                        if (TitleOnSheet_IDEnglishChineseDict.ContainsKey(viewportID) == false)
                        {
                            if (TitleOnSheet_HoldDict.ContainsKey(viewportID) == false)
                            {
                                if (!TitleOnSheetCompareList.Contains(viewportID))
                                {
                                    string[] array = new string[4];
                                    array[0] = viewportID;
                                    array[1] = RvtEnglish;
                                    array[2] = RvtChinese;
                                    array[3] = centralFilePath;
                                    NotTranslated.Add(array);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Set English Title On Sheet by ID Exception raised - " + ex.Message);
                }
            }

            //if dictionary has elements that need to be removed.
            if (TitleOnSheetsToDeleteFromExcel != null || TitleOnSheetsToDeleteFromExcel.Count > 0)
            {
                Excel.Delete(path, 2, 1, TitleOnSheetsToDeleteFromExcel);
            }

            _HoldIsFoundInRevitTitleOnSheet = HoldIsFoundInRevit;
            return(NotTranslated);
        }
        //***********************************SheetTranslation***********************************
        public List <string[]> SheetTranslation(Document doc,
                                                Dictionary <string, string[]> Sheet_IDEnglishChineseDict,
                                                Dictionary <string, string[]> Sheet_HoldDict,
                                                List <string> SheetNameCompareList,
                                                string path, string centralFilePath)
        {
            ExcelSheet         Excel = new ExcelSheet();
            RevitModelElements revit = new RevitModelElements();

            List <ViewSheet> sheets = revit.GetAllSheets(doc);
            //Filter to check only the sheets in current docuement.
            Dictionary <string, string[]> SheetsToDeleteFromExcel = RemoveItemFromExcel(Sheet_IDEnglishChineseDict, centralFilePath);

            List <string[]> NotTranslated      = new List <string[]>();
            List <string[]> HoldIsFoundInRevit = new List <string[]>();

            foreach (Element e in sheets)
            {
                Parameter Chinese_param = e.LookupParameter("Sheet Name (Alternate Language)");
                Parameter English_param = e.LookupParameter("Sheet Name");
                string    English       = revit.GetParameterValue(English_param);
                string    Chinese       = revit.GetParameterValue(Chinese_param);

                ViewSheet sheet       = e as ViewSheet;
                Parameter sheet_param = sheet.get_Parameter(BuiltInParameter.SHEET_NUMBER);
                string    sheetNumber = revit.GetParameterValue(sheet_param);

                //Check if the sheet is a Z sheet.
                if (sheetNumber.StartsWith("z") || sheetNumber.StartsWith("Z"))
                {
                    continue;
                }

                if (Sheet_IDEnglishChineseDict.ContainsKey(sheetNumber))
                {
                    if (Chinese == "" || Chinese == null)
                    {
                        string[] Values = Sheet_IDEnglishChineseDict[sheetNumber];
                        // Set English note.
                        Transaction t = new Transaction(doc, "Translation by ID");
                        t.Start();
                        // Set english parameter.
                        English_param.Set(Values[0]);
                        Chinese_param.Set(Values[1]);
                        t.Commit();
                    }
                    //If view exists in Revit remove from list.
                    SheetsToDeleteFromExcel.Remove(sheetNumber);
                }

                //Check if Project missing, but translation exists
                //in Revit needs to be translated and project added to database.
                if (Sheet_HoldDict.ContainsKey(sheetNumber))
                {
                    string[] Values = Sheet_HoldDict[sheetNumber];

                    // Set English note.
                    Transaction t = new Transaction(doc, "Translation by ID");
                    t.Start();
                    // Set english parameter.
                    English_param.Set(Values[0]);
                    Chinese_param.Set(Values[1]);
                    t.Commit();
                    //add center file path to values.
                    // add to update excel from Revit model.
                    string[] array = new string[4];
                    array[0] = sheetNumber;
                    array[1] = Values[0];
                    array[2] = Values[1];
                    array[3] = centralFilePath;
                    HoldIsFoundInRevit.Add(array);
                    SheetsToDeleteFromExcel.Add(sheetNumber, Values);
                }

                //if the dictionary doesn't have translation add to Excel.
                if (Sheet_IDEnglishChineseDict.ContainsKey(sheetNumber) == false)
                {
                    if (Sheet_HoldDict.ContainsKey(sheetNumber) == false)
                    {
                        if (!SheetNameCompareList.Contains(sheetNumber))
                        {
                            string[] array = new string[4];
                            array[0] = sheetNumber;
                            array[1] = English;
                            array[2] = Chinese;
                            array[3] = centralFilePath;
                            NotTranslated.Add(array);
                        }
                    }
                }
            }

            //if dictionary has elements that need to be removed.
            if (SheetsToDeleteFromExcel != null || SheetsToDeleteFromExcel.Count > 0)
            {
                Excel.Delete(path, 3, 1, SheetsToDeleteFromExcel);
            }

            _HoldIsFoundInRevitSheets = HoldIsFoundInRevit;

            return(NotTranslated);
        }