public void Execute(UIApplication app) { Document doc = app.ActiveUIDocument.Document; File.WriteAllText(xlsFilePathLog, string.Empty); //FileStream fs = new FileStream(xlsFilePathLog, FileMode.Append, FileAccess.Write); //StreamWriter sw = new StreamWriter(fs); //sw.Write("\n"); //sw.Close(); //fs.Close(); try { MyFamilyLoadOptions option = new MyFamilyLoadOptions(); for (int k = 0; k < familyFilePaths.Count(); k++) { Transaction openFamily = new Transaction(doc, "openFamily"); openFamily.Start(); //MessageBox.Show(familyFilePaths[k] ); Document rfadoc = app.Application.OpenDocumentFile(familyFilePaths[k]); //openFamily.Commit(); //settingFamilyParamenters(rfadoc, familyFilePaths[k], parameterFilePaths[k]); //获得族内参数保存为dataset XlsFilePath = Creating_Excel_From_DataTable(gettingFamilyParamenters(rfadoc), familyFilePaths[k]); rfadoc.Close(); openFamily.Commit(); //Family Family = rfadoc.LoadFamily(doc, option); } } catch (Exception eeffef) { MessageBox.Show(eeffef.ToString()); } }
public void Execute(UIApplication app) { Document doc = app.ActiveUIDocument.Document; try { MyFamilyLoadOptions option = new MyFamilyLoadOptions(); for (int k = 0; k < familyFilePaths.Count(); k++) { Transaction openFamily = new Transaction(doc, "openFamily"); openFamily.Start(); //MessageBox.Show(familyFilePaths[k] ); Document rfadoc = app.Application.OpenDocumentFile(familyFilePaths[k]); //openFamily.Commit(); //settingFamilyParamenters(rfadoc, familyFilePaths[k], parameterFilePaths[k]); //获得族内参数保存为dataset XlsFilePath = Creating_Excel_From_DataTable(gettingFamilyParamenters(rfadoc), familyFilePaths[k]); rfadoc.Close(); openFamily.Commit(); //Family Family = rfadoc.LoadFamily(doc, option); } } catch (Exception eeffef) { MessageBox.Show(eeffef.ToString()); } }
//public DataTable dtUB = DataUB.dataTempTable; public void Execute(UIApplication app) { Document doc = app.ActiveUIDocument.Document; File.WriteAllText(xlsFilePathLog, string.Empty); if (dtUB == null) { MessageBox.Show(" dtUB ==null "); } try { MyFamilyLoadOptions option = new MyFamilyLoadOptions(); for (int k = 0; k < dtUB.Rows.Count; k++) { Transaction openFamily = new Transaction(doc, "openFamily"); openFamily.Start(); //MessageBox.Show(familyFilePaths[k] ); Document rfadoc = app.Application.OpenDocumentFile(dtUB.Rows[k]["familyPathss"].ToString()); //openFamily.Commit(); //settingFamilyParamenters(rfadoc, familyFilePaths[k], parameterFilePaths[k]); //获得族内参数保存为dataset XlsFilePath = Creating_Excel_From_DataTable(gettingFamilyParamenters(rfadoc), dtUB.Rows[k]["familyPathss"].ToString()); dtUB.Rows[k]["familyParass"] = XlsFilePath; rfadoc.Close(); openFamily.Commit(); //Family Family = rfadoc.LoadFamily(doc, option); } //for (int k = 0; k < familyFilePaths.Count(); k++) //{ // Transaction openFamily = new Transaction(doc, "openFamily"); // openFamily.Start(); // //MessageBox.Show(familyFilePaths[k] ); // Document rfadoc = app.Application.OpenDocumentFile(familyFilePaths[k]); // //openFamily.Commit(); // //settingFamilyParamenters(rfadoc, familyFilePaths[k], parameterFilePaths[k]); // //获得族内参数保存为dataset // //DataUB.dataTempTable = ; // XlsFilePath = Creating_Excel_From_DataTable(gettingFamilyParamenters(rfadoc), familyFilePaths[k]); // rfadoc.Close(); // openFamily.Commit(); // //Family Family = rfadoc.LoadFamily(doc, option); //} } catch (Exception eeffef) { MessageBox.Show(eeffef.ToString()); } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { MyFamilyLoadOptions option = new MyFamilyLoadOptions(); Document Revit_Doc = commandData.Application.ActiveUIDocument.Document; RevitFamilyManagerFormSTF RevitFamilyManagerFormSTF = new RevitFamilyManagerFormSTF(); RevitFamilyManagerFormSTF.ShowDialog(); List <string> fPathList = new List <string>(); List <string> fNameList = new List <string>(); fPathList = RevitFamilyManagerFormSTF.fPathList; fNameList = RevitFamilyManagerFormSTF.fNameList; //Document rfadoc = app.Application.OpenDocumentFile(familyFilePaths[k]); List <Family> families = new List <Family>();; for (int i = 0; i < fPathList.Count(); i++) { try { Document rfadoc = commandData.Application.Application.OpenDocumentFile(fPathList[i]); Transaction openRFA = new Transaction(rfadoc, "openRFA"); openRFA.Start(); Settings documentSettings = rfadoc.Settings; Category categoryGM = documentSettings.Categories.get_Item(BuiltInCategory.OST_GenericModel); rfadoc.OwnerFamily.FamilyCategory = categoryGM; openRFA.Commit(); rfadoc.SaveAs(fPathList[i] + "_changedCat.rvt"); rfadoc.Close(); } catch (Exception defe) { MessageBox.Show(defe.ToString()); } } return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { DotNet.Utilities.LogHelper.LogMonitor("table_Log", "族属性批量修改功能"); //创建datatable DataTable dtListView = new DataTable("Table_Excel"); //提取属性 //RevitFamilyManagerFormIO RevitFamilyManagerFormIO = new RevitFamilyManagerFormIO(); //RevitFamilyManagerFormIO.Show(); Document Revit_Doc = commandData.Application.ActiveUIDocument.Document; Selection sel = commandData.Application.ActiveUIDocument.Selection; IList <Reference> listRef = new List <Reference>(); IList <Element> listEle = new List <Element>(); List <string> listElementNames = new List <string>();//选中的元素名字传递 List <string> listFamilyNames = new List <string>(); //选取需要检测的图元 MessageBox.Show("选取图元"); //将所选取的element转换为reference listRef = sel.PickObjects(ObjectType.Element); //将reference转换为element foreach (var Ref in listRef) { Element element = Revit_Doc.GetElement(Ref.ElementId); listEle.Add(element); //MessageBox.Show(element.Name); listElementNames.Add(element.Name.ToString()); listFamilyNames.Add((element as FamilyInstance).Symbol.Family.Name.ToString()); MessageBox.Show((element as FamilyInstance).Symbol.Family.Name.ToString()); } /*-------------------------------------------------------------------------------------------------------*/ RevitFamilyManagerFormEP RevitFamilyManagerFormEP = new RevitFamilyManagerFormEP(); RevitFamilyManagerFormEP.listElementNames = listElementNames; RevitFamilyManagerFormEP.listFamilyNames = listFamilyNames; RevitFamilyManagerFormEP.ShowDialog(); clearpara = RevitFamilyManagerFormEP.clearpara; clearsymbol = RevitFamilyManagerFormEP.clearsymbol; /*-------------------------------------------------------------------------------------------------------*/ MyFamilyLoadOptions option = new MyFamilyLoadOptions(); dtListView = RevitFamilyManagerFormEP.dtListView; for (int i = 0; i < dtListView.Rows.Count; i++) { foreach (Element ele in listEle) { if (ele.Name == dtListView.Rows[i]["eleName"].ToString()) { string eleName = dtListView.Rows[i]["eleName"].ToString(); string eleXPath = dtListView.Rows[i]["eleXPath"].ToString(); string elefName = dtListView.Rows[i]["elefName"].ToString(); if (eleXPath != "...") { Document familyDoc = null; //Transaction editFamily = new Transaction(Revit_Doc, "openFamily"); //editFamily.Commit(); familyDoc = settingParamenters(eleName, eleXPath, elefName, Revit_Doc); Family Family = familyDoc.LoadFamily(Revit_Doc, option); } } } } return(Result.Succeeded); }
public void Execute(UIApplication app) { Document doc = app.ActiveUIDocument.Document; if (LoadTag == "0") { try { MyFamilyLoadOptions option = new MyFamilyLoadOptions(); for (int k = 0; k < familyFilePaths.Count(); k++) { Transaction openFamily = new Transaction(doc, "openFamily"); openFamily.Start(); //MessageBox.Show(familyFilePaths[k] ); Document rfadoc = app.Application.OpenDocumentFile(familyFilePaths[k]); //openFamily.Commit(); settingFamilyParamenters(rfadoc, familyFilePaths[k], parameterFilePaths[k]); openFamily.Commit(); Family Family = rfadoc.LoadFamily(doc, option); } } catch (Exception eeffef) { MessageBox.Show(eeffef.ToString()); } #region 进程解放部分 (已经验证revit.exe进程占用,由于单线程原因,解除占用只能关闭revit) //Process.GetProcesses(); //foreach (var ffp in familyFilePaths) //{ // string fileName = ffp;//要检查被那个进程占用的文件 // Process tool = new Process(); // tool.StartInfo.FileName = @"C:\ProgramData\Autodesk\Revit\Addins\2016\handle.exe"; // tool.StartInfo.Arguments = fileName + " /accepteula"; // tool.StartInfo.UseShellExecute = false; // tool.StartInfo.RedirectStandardOutput = true; // tool.Start(); // tool.WaitForExit(); // string outputTool = tool.StandardOutput.ReadToEnd(); // string matchPattern = @"(?<=\s+pid:\s+)\b(\d+)\b(?=\s+)"; // foreach (Match match in Regex.Matches(outputTool, matchPattern)) // { // MessageBox.Show(int.Parse(match.Value).ToString()); // Process.GetProcessById(int.Parse(match.Value)).Kill(); // } //} #endregion try { foreach (var ffp in familyFilePaths) { if (ffp != null) { File.Delete(ffp); } } foreach (var pfp in parameterFilePaths) { if (pfp != null) { File.Delete(pfp); } } } catch (Exception defza) { MessageBox.Show("所选族已载入成功"); } } else if (LoadTag == "1")//载入并附条目 { try { MyFamilyLoadOptions option = new MyFamilyLoadOptions(); for (int k = 0; k < familyFilePaths.Count(); k++) { Transaction openFamily = new Transaction(doc, "openFamily"); openFamily.Start(); //MessageBox.Show(familyFilePaths[k]); Document rfadoc = app.Application.OpenDocumentFile(familyFilePaths[k]); //openFamily.Commit(); //settingFamilyParamenters(rfadoc, familyFilePaths[k], parameterFilePaths[k]); openFamily.Commit(); Family Family = rfadoc.LoadFamily(doc, option); } } catch (Exception eeffef) { MessageBox.Show(eeffef.ToString()); } try { foreach (var ffp in familyFilePaths) { if (ffp != null) { File.Delete(ffp); } } foreach (var pfp in parameterFilePaths) { if (pfp != null) { File.Delete(pfp); } } } catch (Exception defza) { MessageBox.Show("所选族已载入成功"); } } else if (LoadTag == "2")//载入附条目并填写值 { try { MyFamilyLoadOptions option = new MyFamilyLoadOptions(); for (int k = 0; k < familyFilePaths.Count(); k++) { Transaction openFamily = new Transaction(doc, "openFamily"); openFamily.Start(); //MessageBox.Show(familyFilePaths[k] ); Document rfadoc = app.Application.OpenDocumentFile(familyFilePaths[k]); //openFamily.Commit(); settingFamilyParamentersValue(rfadoc, familyFilePaths[k], parameterFilePaths[k]); openFamily.Commit(); Family Family = rfadoc.LoadFamily(doc, option); } } catch (Exception eeffef) { MessageBox.Show(eeffef.ToString()); } try { foreach (var ffp in familyFilePaths) { if (ffp != null) { File.Delete(ffp); } } foreach (var pfp in parameterFilePaths) { if (pfp != null) { File.Delete(pfp); } } } catch (Exception defza) { MessageBox.Show("所选族已载入成功"); } } //throw new NotImplementedException(); }
public void ModuleTestPart1(ExternalCommandData commandData) { Document doc = commandData.Application.ActiveUIDocument.Document; if (LoadTag == "0") { try { MyFamilyLoadOptions option = new MyFamilyLoadOptions(); for (int k = 0; k < familyFilePaths.Count(); k++) { Transaction openFamily = new Transaction(doc, "openFamily"); openFamily.Start(); //MessageBox.Show(familyFilePaths[k] ); Document rfadoc = commandData.Application.Application.OpenDocumentFile(familyFilePaths[k]); //openFamily.Commit(); settingFamilyParamenters(rfadoc, familyFilePaths[k], parameterFilePaths[k]); openFamily.Commit(); Family Family = rfadoc.LoadFamily(doc, option); } } catch (Exception eeffef) { MessageBox.Show(eeffef.ToString()); } try { foreach (var ffp in familyFilePaths) { if (ffp != null) { File.Delete(ffp); } } foreach (var pfp in parameterFilePaths) { if (pfp != null) { File.Delete(pfp); } } } catch (Exception defza) { MessageBox.Show("所选族已载入成功"); } } else if (LoadTag == "1")//载入并附条目 { try { MyFamilyLoadOptions option = new MyFamilyLoadOptions(); for (int k = 0; k < familyFilePaths.Count(); k++) { Transaction openFamily = new Transaction(doc, "openFamily"); openFamily.Start(); //MessageBox.Show(familyFilePaths[k]); Document rfadoc = commandData.Application.Application.OpenDocumentFile(familyFilePaths[k]); //openFamily.Commit(); //settingFamilyParamenters(rfadoc, familyFilePaths[k], parameterFilePaths[k]); openFamily.Commit(); Family Family = rfadoc.LoadFamily(doc, option); } } catch (Exception eeffef) { MessageBox.Show(eeffef.ToString()); } try { foreach (var ffp in familyFilePaths) { if (ffp != null) { File.Delete(ffp); } } foreach (var pfp in parameterFilePaths) { if (pfp != null) { File.Delete(pfp); } } } catch (Exception defza) { MessageBox.Show("所选族已载入成功"); } } else if (LoadTag == "2")//载入附条目并填写值 { try { MyFamilyLoadOptions option = new MyFamilyLoadOptions(); for (int k = 0; k < familyFilePaths.Count(); k++) { Transaction openFamily = new Transaction(doc, "openFamily"); openFamily.Start(); //MessageBox.Show(familyFilePaths[k] ); Document rfadoc = commandData.Application.Application.OpenDocumentFile(familyFilePaths[k]); //openFamily.Commit(); settingFamilyParamentersValue(rfadoc, familyFilePaths[k], parameterFilePaths[k]); openFamily.Commit(); Family Family = rfadoc.LoadFamily(doc, option); } } catch (Exception eeffef) { MessageBox.Show(eeffef.ToString()); } try { foreach (var ffp in familyFilePaths) { if (ffp != null) { File.Delete(ffp); } } foreach (var pfp in parameterFilePaths) { if (pfp != null) { File.Delete(pfp); } } } catch (Exception defza) { MessageBox.Show("所选族已载入成功"); } } //throw new NotImplementedException(); }