63 lines
2.5 KiB
C#
63 lines
2.5 KiB
C#
|
|
using Autodesk.Revit.DB;
|
|
|
|
using Microsoft.Win32;
|
|
|
|
using Nice3point.Revit.Toolkit.External;
|
|
|
|
using System;
|
|
|
|
using System.Data;
|
|
|
|
using Szmedi.RvKits.Assists;
|
|
|
|
namespace Szmedi.RvKits.ModelManager;
|
|
|
|
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
|
|
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
|
|
public class GetBasePointInfoCmd : ExternalCommand
|
|
{
|
|
public override void Execute()
|
|
{
|
|
OpenFileDialog fileOpenDialog =
|
|
new() { Filter = "Revt项目文件(*.RVT,*.rvt)|*.RVT;*.rvt", Title = "选择Revit项目文件", Multiselect = true };
|
|
if (fileOpenDialog.ShowDialog() == true)
|
|
{
|
|
using DataTable dt = new();
|
|
dt.Columns.Add("项目完整路径", typeof(string));
|
|
dt.Columns.Add("北/南", typeof(string));
|
|
dt.Columns.Add("东/西", typeof(string));
|
|
dt.Columns.Add("到正北的角度", typeof(string));
|
|
dt.Columns.Add("高程", typeof(string));
|
|
var fileNames = fileOpenDialog.FileNames;
|
|
//var path = ModelPathUtils.ConvertModelPathToUserVisiblePath(fileNames);
|
|
|
|
foreach (var path in fileNames)
|
|
{
|
|
var doc = Application.OpenDocumentFile(path);
|
|
var bp = new FilteredElementCollector(doc)
|
|
.OfClass(typeof(BasePoint))
|
|
.OfCategory(BuiltInCategory.OST_ProjectBasePoint)
|
|
.FirstElement();
|
|
if (bp.Category.Id == Category.GetCategory(doc, BuiltInCategory.OST_ProjectBasePoint).Id)
|
|
{
|
|
dt.Rows.Add(dt.NewRow());
|
|
dt.Rows[0][0] = doc.PathName;
|
|
|
|
dt.Rows[1][1] = bp.get_Parameter(BuiltInParameter.BASEPOINT_NORTHSOUTH_PARAM).AsDouble() * 304.8 / 1000; //"北/南"
|
|
dt.Rows[1][2] = bp.get_Parameter(BuiltInParameter.BASEPOINT_EASTWEST_PARAM).AsDouble() * 304.8 / 1000; //"东/西"
|
|
dt.Rows[1][3] = bp.get_Parameter(BuiltInParameter.BASEPOINT_ANGLETON_PARAM).AsDouble(); //"到正北的角度"
|
|
dt.Rows[1][4] = bp.get_Parameter(BuiltInParameter.BASEPOINT_ELEVATION_PARAM).AsDouble() * 304.8; //"高程"
|
|
}
|
|
|
|
doc.Close(false);
|
|
}
|
|
EPPlusHelpers.DataTableToExcel(
|
|
dt,
|
|
Path.Combine(
|
|
Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
|
|
$"项目基点坐标{DateTime.Now:yyyy-MM-dd}"));
|
|
}
|
|
}
|
|
}
|