public static string Activate() { string assemblyName = System.Reflection.Assembly.GetExecutingAssembly().Location; string assemblyFolder = System.IO.Path.GetDirectoryName(assemblyName); string appdataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); string bimstarterFolder = System.IO.Path.Combine(appdataFolder, "bim-starter"); if (!System.IO.Directory.Exists(bimstarterFolder)) { Debug.WriteLine("Create folder: " + bimstarterFolder); System.IO.Directory.CreateDirectory(bimstarterFolder); } configFilePath = Path.Combine(bimstarterFolder, "config.ini"); string weandrevitPath = ""; if (File.Exists(configFilePath)) { Debug.WriteLine("Read file: " + configFilePath); weandrevitPath = File.ReadAllLines(configFilePath)[0]; } else { Debug.WriteLine("First start, show dialog window and select config folder"); string configDefaultFolder = Path.Combine(appdataFolder, @"Autodesk\Revit\Addins\20xx\BimStarter"); FormSelectPath form = new FormSelectPath(configFilePath, configDefaultFolder); if (form.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return("Cancelled"); } if (form.UseServerPath) { weandrevitPath = form.ServerPath; } else { weandrevitPath = configDefaultFolder; } Debug.WriteLine("Selected user path: " + weandrevitPath); File.WriteAllText(configFilePath, weandrevitPath); Debug.WriteLine("Written to file: " + configFilePath); } libraryPath = Path.Combine(weandrevitPath, "RebarSketch", "library"); Debug.WriteLine("Library path: " + libraryPath); if (!Directory.Exists(libraryPath)) { return("Library directory not exists: " + libraryPath); } string settingsFile = Path.Combine(weandrevitPath, "RebarSketch", "settings.txt"); Debug.WriteLine("Settings path: " + settingsFile); if (!File.Exists(settingsFile)) { Debug.WriteLine("File not found: " + settingsFile); throw new Exception("File not found: " + settingsFile); } string[] settings = FileSupport.ReadFileWithAnyDecoding(settingsFile); fontName = settings[0].Split('#').Last(); fontSize = float.Parse(settings[1].Split('#').Last()); string textStyle = settings[2].Split('#').Last(); fontStyle = FileSupport.GetFontStyle(textStyle); lengthAccuracy = double.Parse(settings[3].Split('#').Last()); tempPath = settings[4].Split('#').Last(); imageParamName = settings[5].Split('#').Last(); FileSupport.CheckAndDeleteFolder(tempPath); Debug.WriteLine("Settings activate success"); return(string.Empty); }
private ScetchTemplate CreateTemplate(string nameFolder, bool AsSubtype) { string name = nameFolder.Split('\\').Last(); ScetchTemplate st = new ScetchTemplate(); st.formName = name; if (AsSubtype) { st.IsSubtype = true; string subtypeNumberString = name.Split('_').Last(); int subtypeNumber = int.Parse(subtypeNumberString); st.SubtypeNumber = subtypeNumber; } string familiesNamesFile = Path.Combine(nameFolder, "families.txt"); string fileCheck = CheckFileExists(familiesNamesFile); if (fileCheck != "") { Autodesk.Revit.UI.TaskDialog.Show("Ошибка", fileCheck); return(null); } string[] familiesNames = FileSupport.ReadFileWithAnyDecoding(familiesNamesFile); st.familyNames = familiesNames.ToList(); string imageFile = Path.Combine(nameFolder, "scetch.png"); fileCheck = CheckFileExists(imageFile); if (fileCheck != "") { Autodesk.Revit.UI.TaskDialog.Show("Ошибка", fileCheck); return(null); } st.templateImagePath = imageFile; string paramsFile = Path.Combine(nameFolder, "parameters.txt"); fileCheck = CheckFileExists(paramsFile); if (fileCheck != "") { Autodesk.Revit.UI.TaskDialog.Show("Ошибка", fileCheck); return(null); } string[] paramsArray = FileSupport.ReadFileWithAnyDecoding(paramsFile); st.parameters = new List <ScetchParameter>(); for (int i = 0; i < paramsArray.Length; i++) { string p = paramsArray[i]; if (p.StartsWith("#")) { continue; } ScetchParameter sp = new ScetchParameter(); string[] paramInfo = p.Split(','); if (paramInfo.Length < 4) { continue; } sp.Name = paramInfo[0]; bool checkParseX = float.TryParse(paramInfo[1], out sp.PositionX); bool checkParseY = float.TryParse(paramInfo[2], out sp.PositionY); bool checkParseR = float.TryParse(paramInfo[3], out sp.Rotation); if (!checkParseX || !checkParseY || !checkParseR) { throw new ArgumentException("Incorrect syntax in file " + paramsFile.Replace("\\", " \\") + ", line " + i); } sp.NeedsWrap = false; if (paramInfo.Length > 4) { if (paramInfo[4] == "1") { sp.NeedsWrap = true; } } st.parameters.Add(sp); } Debug.WriteLine("ScetchTemplate is created"); return(st); }
private void btnLoadTemplate_Click(object sender, EventArgs e) { bool checkDialog = this.LoadAndActivatePicture(); if (!checkDialog) { return; } dataGridView1.Rows.Clear(); string paramsFile = System.IO.Path.Combine(executionFolder, "parameters.txt"); bool check = System.IO.File.Exists(paramsFile); if (!check) { throw new Exception("Файл параметров не найден в папке с картинкой"); } ScetchTemplate st = new ScetchTemplate(); string[] paramsArray = FileSupport.ReadFileWithAnyDecoding(paramsFile); st.parameters = new List <ScetchParameter>(); for (int i = 0; i < paramsArray.Length; i++) { string p = paramsArray[i]; if (p.StartsWith("#")) { continue; } if (p.Length < 1) { continue; } string[] paramInfo = p.Split(','); if (paramInfo.Length < 4) { throw new Exception("Incorrect syntax in file " + paramsFile + ", line " + i); } string paramName = paramInfo[0]; string posX = paramInfo[1]; string posY = paramInfo[2]; string r = paramInfo[3]; bool needsWrap = false; if (paramInfo.Length > 4) { if (paramInfo[4] == "1") { needsWrap = true; } } dataGridView1.Rows.Add(paramName, paramName, posX, posY, r, needsWrap); } this.RefreshImage(); btnDeleteRow.Enabled = true; }