using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Autodesk.Revit.Attributes; using Autodesk.Revit.DB; using Autodesk.Revit.UI;
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Autodesk.Revit.Attributes; using Autodesk.Revit.DB; using Autodesk.Revit.UI;
namespacedemo { [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] publicclassApp : IExternalApplication { static AddInId appId = new AddInId( new Guid("356CDA5A-E6C5-4c2f-A9EF-B5222116B8D8"));
public Result OnStartup(UIControlledApplication application) { RibbonPanel ribbonPanel = application.CreateRibbonPanel("我的工具"); PulldownButtonData data = new PulldownButtonData("Options", "工具");
RibbonItem item = ribbonPanel.AddItem(data); PulldownButton optionsBtn = item as PulldownButton;
optionsBtn.AddPushButton( new PushButtonData("展示", "展示...", ExecutingAssemblyPath, "demo.Class1"));
return Result.Succeeded; } public Result OnShutdown(UIControlledApplication application) { return Result.Succeeded; } } }
public Result OnStartup(UIControlledApplication application) { RibbonPanel ribbonPanel = application.CreateRibbonPanel("我的工具"); PulldownButtonData data = new PulldownButtonData("Options", "工具");
RibbonItem item = ribbonPanel.AddItem(data); PulldownButton optionsBtn = item as PulldownButton;
publicvoidCreatePipingLine(ExternalCommandData commandData, Level level) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; using (Transaction transaction = new Transaction(doc)) { transaction.Start("开始绘图"); // 获取管道系统 FilteredElementCollector pipSytem = new FilteredElementCollector(doc); pipSytem.OfClass(typeof(PipingSystemType)); PipingSystemType pipingSystemType = pipSytem.ToList().First() as PipingSystemType;
// 获取管道类型 FilteredElementCollector pipetye = new FilteredElementCollector(doc); pipetye.OfClass(typeof(PipeType)); PipeType type = pipetye.ToList().First() as PipeType;
XYZ start = new XYZ(0,0,0); XYZ end = new XYZ(1,0,0);
publicvoidCreateNewPipingLine(ExternalCommandData commandData, Level level) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; using (Transaction transaction = new Transaction(doc)) { transaction.Start("开始绘图"); PipingSystemType pipingSystemType = PipingSystemType.Create(doc, MEPSystemClassification.SupplyHydronic, "testSystemType"); Color pipingSystemColor = new Color(255, 128, 255); pipingSystemType.FillColor = pipingSystemColor; pipingSystemType.LineColor = pipingSystemColor;
ElementId materialId = Material.Create(doc, "testMaterial"); Material material = doc.GetElement(materialId) as Material; material.Color = pipingSystemColor; material.CutPatternColor = pipingSystemColor; material.SurfacePatternColor = pipingSystemColor;
pipingSystemType.MaterialId = materialId;
FilteredElementCollector pipetye = new FilteredElementCollector(doc); pipetye.OfClass(typeof(PipeType)); PipeType type = pipetye.ToList().First() as PipeType;
Pipe pipe = Pipe.Create(doc, pipingSystemType.Id, type.Id, Level.Id, new XYZ(0,0,0), new XYZ(1,0,0) );
public OleDbDataReader ReadMdb() { string dbPath = ""; OpenFileDialog dialog = new OpenFileDialog(); dialog.Multiselect = true;//该值确定是否可以选择多个文件 dialog.Title = "请选择文件夹"; dialog.Filter = "所有文件(*.*)|*.*"; if (dialog.ShowDialog() == DialogResult.OK) { dbPath = dialog.FileName; } string connString = $"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={dbPath}"; using (conn = new OleDbConnection(connString)) { conn.Open();
using (OleDbCommand command = new OleDbCommand(sql, conn)) { using (OleDbDataReader reader = command.ExecuteReader()) { //构建结果字符串 string result = ""; while (reader.Read()) { for (int i = 0; i < reader.FieldCount; i++) { result += $"{reader.GetName(i)}: {reader[i]}\t"; //TaskDialog.Show("data", reader.GetName(i)+reader[i]+""); } result += "\n"; } return reader; } } } }
⚠️注意:在读取MDB数据库的时候,可能会在try-catch语句中出现未经处理的异常错误,即catch无法捕获的异常。这是因为没用安装AccessDatabaseEngine2010程序这时导致的,只要安装对应版本的AccessDatabaseEngine2010程序即可。可以通过 bool test = Environment.Is64BitProcess;来判断当前环境是否是64位处理器。