添加项目文件。

This commit is contained in:
GG Z
2026-02-23 14:35:54 +08:00
parent de381a07f6
commit 196af6105f
54 changed files with 5698 additions and 0 deletions

View File

@@ -0,0 +1,205 @@
using CDM.Interop.Revit.CDMComponent;
using OfficeOpenXml;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
namespace CDM.Interop.Revit
{
class CDMComponent2Excel
{
//Math.Round(number, 2, MidpointRounding.AwayFromZero)四舍五入
public static void CDMFloorsToExcel(List<CDMFloor> floors, string sourceFileName, string destFolder)
{
foreach (var floor in floors)
{
string destFileName = destFolder + "\\" + floor.HcdmClass + "-" + floor.HcdmNumber + ".xlsx";
File.Copy(sourceFileName, destFileName, true);
FileInfo fi = new FileInfo(destFileName);
using (ExcelPackage package = new ExcelPackage(fi))
{
//var worksheet = package.Workbook.Worksheets["基本构件"];
var worksheet = package.Workbook.Worksheets[1];
//构件标准名称
worksheet.Cells["G2"].Value = floor.Name;
worksheet.Cells["G3"].Value = floor.HcdmClass;
worksheet.Cells["G4"].Value = floor.HcdmClass + "-" + floor.HcdmNumber;
worksheet.Cells["H14"].Value = floor.Xl;
worksheet.Cells["H15"].Value = floor.Yw;
worksheet.Cells["H16"].Value = floor.Zh;
worksheet.Cells["H17"].Value = 0;
worksheet.Cells["H18"].Value = floor.L;
worksheet.Cells["H19"].Value = floor.W;
worksheet.Cells["H20"].Value = floor.T;
var worksheet1 = package.Workbook.Worksheets["方形洞口"];
try
{
worksheet1.Cells["H7"].Value = floor.CDMopenings[0].Xl;
worksheet1.Cells["H8"].Value = floor.CDMopenings[0].Yw;
worksheet1.Cells["H9"].Value = floor.CDMopenings[0].Length;
worksheet1.Cells["H10"].Value = floor.CDMopenings[0].Width;
worksheet1.Cells["H11"].Value = floor.CDMopenings[1].Xl;
worksheet1.Cells["H12"].Value = floor.CDMopenings[1].Yw;
worksheet1.Cells["H13"].Value = floor.CDMopenings[1].Length;
worksheet1.Cells["H14"].Value = floor.CDMopenings[1].Width;
}
catch (Exception)
{
continue;
}
finally
{
package.Save();
}
};
}
}
public static void CDMColumnsToExcel(List<CDMColumn> columns, string sourceFileName, string destFolder)
{
foreach (var column in columns)
{
string destFileName = destFolder + "\\" + column.HcdmClass + "-" + column.HcdmNumber + ".xlsx";
File.Copy(sourceFileName, destFileName, true);
FileInfo fi = new FileInfo(destFileName);
using (ExcelPackage package = new ExcelPackage(fi))
{
var worksheet = package.Workbook.Worksheets[1];
//var worksheet = package.Workbook.Worksheets["基本构件"];
//构件标准名称
worksheet.Cells["G2"].Value = column.Name;
worksheet.Cells["G3"].Value = column.HcdmClass;
worksheet.Cells["G4"].Value = column.HcdmClass + "-" + column.HcdmNumber;
worksheet.Cells["H14"].Value = column.Xl;
worksheet.Cells["H15"].Value = column.Yw;
worksheet.Cells["H16"].Value = column.Zh;
worksheet.Cells["H17"].Value = 0;//均不旋转方向角为0
worksheet.Cells["H18"].Value = column.SectionB;
worksheet.Cells["H19"].Value = column.SectionH;
worksheet.Cells["H20"].Value = column.L;
package.Save();
};
}
}
public static void CDMBeamsToExcel(List<CDMBeam> beams, string sourceFileName, string destFolder)
{
foreach (var beam in beams)
{
string destFileName = destFolder + "\\" + beam.HcdmClass + "-" + beam.HcdmNumber + ".xlsx";
File.Copy(sourceFileName, destFileName, true);
FileInfo fi = new FileInfo(destFileName);
using (ExcelPackage package = new ExcelPackage(fi))
{
var worksheet = package.Workbook.Worksheets[1];
//var worksheet = package.Workbook.Worksheets["基本构件"];
//构件标准名称
worksheet.Cells["G2"].Value = beam.Name;
worksheet.Cells["G3"].Value = beam.HcdmClass;
worksheet.Cells["G4"].Value = beam.HcdmClass + "-" + beam.HcdmNumber;
worksheet.Cells["H14"].Value = beam.Xl;
worksheet.Cells["H15"].Value = beam.Yw;
worksheet.Cells["H16"].Value = beam.Zh;
worksheet.Cells["H17"].Value = beam.DegreesWithXAxis;
worksheet.Cells["H18"].Value = beam.L;
worksheet.Cells["H19"].Value = beam.SectionB;
worksheet.Cells["H20"].Value = beam.SectionH;
package.Save();
};
}
}
public static void CDMWallsToExcel(List<CDMWall> walls, string sourceFileName, string destFolder)
{
foreach (var wall in walls)
{
string destFileName = destFolder + "\\" + wall.HcdmClass + "-" + wall.HcdmNumber + ".xlsx";
File.Copy(sourceFileName, destFileName, true);
FileInfo fi = new FileInfo(destFileName);
using (ExcelPackage package = new ExcelPackage(fi))
{
var worksheet = package.Workbook.Worksheets[1];
//var worksheet = package.Workbook.Worksheets["基本构件"];
//构件标准名称
worksheet.Cells["G2"].Value = wall.Name;
worksheet.Cells["G3"].Value = wall.HcdmClass;
worksheet.Cells["G4"].Value = wall.HcdmClass + "-" + wall.HcdmNumber;
worksheet.Cells["H14"].Value = wall.Xl;
worksheet.Cells["H15"].Value = wall.Yw;
worksheet.Cells["H16"].Value = wall.Zh;
package.Save();
};
}
}
public static void CDMStairsToExcel(List<CDMStairs> stairs, string sourceFileName, string destFolder)
{
foreach (var stair in stairs)
{
string destFileName = destFolder + "\\" + stair.HcdmClass + "-" + stair.HcdmNumber + ".xlsx";
File.Copy(sourceFileName, destFileName, true);
FileInfo fi = new FileInfo(destFileName);
using (ExcelPackage package = new ExcelPackage(fi))
{
var worksheet = package.Workbook.Worksheets[1];
//var worksheet = package.Workbook.Worksheets["基本构件"];
//构件标准名称
worksheet.Cells["G2"].Value = stair.Name;
worksheet.Cells["G3"].Value = stair.HcdmClass;
worksheet.Cells["G4"].Value = stair.HcdmClass + "-" + stair.HcdmNumber;
worksheet.Cells["H14"].Value = stair.Runs[0].Xl;
worksheet.Cells["H15"].Value = stair.Runs[0].Yw;
worksheet.Cells["H16"].Value = stair.Runs[0].Zh;
worksheet.Cells["H17"].Value = stair.Runs[0].DegreesWithXAxis;
worksheet.Cells["H18"].Value = stair.Runs[0].Length;
worksheet.Cells["H19"].Value = stair.Runs[0].Width;
worksheet.Cells["H20"].Value = stair.Runs[0].Height;
worksheet.Cells["H21"].Value = stair.Runs[0].Thickness;
worksheet.Cells["H22"].Value = stair.Runs[0].NumberOfRisers;
worksheet.Cells["H23"].Value = stair.Landing.Xl;
worksheet.Cells["H24"].Value = stair.Landing.Yw;
worksheet.Cells["H25"].Value = stair.Landing.Zh;
worksheet.Cells["H26"].Value = stair.Landing.Length;
worksheet.Cells["H27"].Value = stair.Landing.Width;
worksheet.Cells["H28"].Value = stair.Landing.Thickness;
worksheet.Cells["H29"].Value = stair.Runs[1].Xl;
worksheet.Cells["H30"].Value = stair.Runs[1].Yw;
worksheet.Cells["H31"].Value = stair.Runs[1].Zh;
worksheet.Cells["H32"].Value = stair.Runs[1].DegreesWithXAxis;
worksheet.Cells["H33"].Value = stair.Runs[1].Length;
worksheet.Cells["H34"].Value = stair.Runs[1].Width;
worksheet.Cells["H35"].Value = stair.Runs[1].Height;
worksheet.Cells["H36"].Value = stair.Runs[1].Thickness;
worksheet.Cells["H37"].Value = stair.Runs[1].NumberOfRisers;
package.Save();
};
}
}
}
}

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CDM.Interop.Revit
{
class FilePathInfo
{
public string Path { get; set; }
public string FileName { get; set; }
public string Category { get; set; }
}
}

View File

@@ -0,0 +1,343 @@
using Microsoft.Win32;
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
/// <summary>
/// Prompts the user to select a folder with a vista style dialog.
/// </summary>
sealed class VistaFolderBrowserDialog
{
#region Properties
/// <summary>
/// Gets or sets the path selected by the user.
/// </summary>
public string SelectedPath { get; set; }
/// <summary>
/// Gets the name of the element selected by the user.
/// </summary>
public string SelectedElementName { get; private set; }
/// <summary>
/// Gets an array of paths selected by the user.
/// </summary>
public string[] SeletcedPaths { get; private set; }
/// <summary>
/// Gets an array of element names selected by the user.
/// </summary>
public string[] SelectedElementNames { get; private set; }
/// <summary>
/// Gets or sets a valie indicating whether the user is able to select non storage places.
/// </summary>
public bool AllowNonStoragePlaces { get; set; }
/// <summary>
/// Gets or sets a valie indicating whether the user can select multiple folders or elements.
/// </summary>
public bool Multiselect { get; set; }
#endregion Properties
#region Public Methods
/// <summary>
/// Shows the dialog with the default owner.
/// </summary>
/// <returns><c>true</c> if the user clicks OK in the dialog box; otherwise <c>false</c></returns>
public bool ShowDialog() => ShowDialog(IntPtr.Zero);
/// <summary>
/// Shows the dialog with <paramref name="owner"/> as the owner.
/// </summary>
/// <param name="owner">The owner of the dialog box.</param>
/// <returns><c>true</c> if the user clicks OK in the dialog box; otherwise <c>false</c></returns>
public bool ShowDialog(Window owner) => ShowDialog(owner == null ? IntPtr.Zero : new WindowInteropHelper(owner).Handle);
/// <summary>
/// Shows the dialog with <paramref name="owner"/> as the owner.
/// </summary>
/// <param name="owner">The owner of the dialog box.</param>
/// <returns><c>true</c> if the user clicks OK in the dialog box; otherwise <c>false</c></returns>
public bool ShowDialog(IWin32Window owner) => ShowDialog(owner == null ? IntPtr.Zero : owner.Handle);
/// <summary>
/// Shows the dialog with <paramref name="owner"/> as the owner.
/// </summary>
/// <param name="owner">The owner of the dialog box.</param>
/// <returns><c>true</c> if the user clicks OK in the dialog box; otherwise <c>false</c></returns>
public bool ShowDialog(IntPtr owner)
{
if (Environment.OSVersion.Version.Major < 6)
{
throw new InvalidOperationException("The dialog need at least Windows Vista to work.");
}
var dialog = CreateNativeDialog();
try
{
SetInitialFolder(dialog);
SetOptions(dialog);
if (dialog.Show(owner) != 0)
{
return false;
}
SetDialogResults(dialog);
return true;
}
finally
{
Marshal.ReleaseComObject(dialog);
}
}
#endregion Public Methods
#region Helper
private void GetPathAndElementName(IShellItem item, out string path, out string elementName)
{
item.GetDisplayName(SIGDN.PARENTRELATIVEFORADDRESSBAR, out elementName);
try
{
item.GetDisplayName(SIGDN.FILESYSPATH, out path);
}
catch (ArgumentException ex) when (ex.HResult == -2147024809)
{
path = null;
}
}
private IFileOpenDialog CreateNativeDialog()
{
return new FileOpenDialog() as IFileOpenDialog;
}
private void SetInitialFolder(IFileOpenDialog dialog)
{
IShellItem item;
if (!string.IsNullOrEmpty(SelectedPath))
{
IntPtr idl;
uint atts = 0;
if (NativeMethods.SHILCreateFromPath(SelectedPath, out idl, ref atts) == 0
&& NativeMethods.SHCreateShellItem(IntPtr.Zero, IntPtr.Zero, idl, out item) == 0)
{
dialog.SetFolder(item);
}
}
}
private void SetOptions(IFileOpenDialog dialog)
{
dialog.SetOptions(GetDialogOptions());
}
private FOS GetDialogOptions()
{
var options = FOS.PICKFOLDERS;
if (this.Multiselect)
{
options |= FOS.ALLOWMULTISELECT;
}
if (!AllowNonStoragePlaces)
{
options |= FOS.FORCEFILESYSTEM;
}
return options;
}
private void SetDialogResults(IFileOpenDialog dialog)
{
IShellItem item;
if (!this.Multiselect)
{
dialog.GetResult(out item);
string path, value;
GetPathAndElementName(item, out path, out value);
this.SelectedPath = path;
this.SeletcedPaths = new[] { path };
this.SelectedElementName = value;
this.SelectedElementNames = new[] { value };
}
else
{
IShellItemArray items;
dialog.GetResults(out items);
uint count;
items.GetCount(out count);
this.SeletcedPaths = new string[count];
this.SelectedElementNames = new string[count];
for (uint i = 0; i < count; ++i)
{
items.GetItemAt(i, out item);
string path, value;
GetPathAndElementName(item, out path, out value);
this.SeletcedPaths[i] = path;
this.SelectedElementNames[i] = value;
}
this.SelectedPath = null;
this.SelectedElementName = null;
}
}
#endregion Helper
#region Types
private class NativeMethods
{
[DllImport("shell32.dll")]
public static extern int SHILCreateFromPath([MarshalAs(UnmanagedType.LPWStr)] string pszPath, out IntPtr ppIdl, ref uint rgflnOut);
[DllImport("shell32.dll")]
public static extern int SHCreateShellItem(IntPtr pidlParent, IntPtr psfParent, IntPtr pidl, out IShellItem ppsi);
[DllImport("user32.dll")]
public static extern IntPtr GetActiveWindow();
}
[ComImport, Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
private interface IShellItem
{
void BindToHandler([In, MarshalAs(UnmanagedType.Interface)] IntPtr pbc, [In] ref Guid bhid, [In] ref Guid riid, out IntPtr ppv);
void GetParent([MarshalAs(UnmanagedType.Interface)] out IShellItem ppsi);
void GetDisplayName([In] SIGDN sigdnName, [MarshalAs(UnmanagedType.LPWStr)] out string ppszName);
void GetAttributes([In] uint sfgaoMask, out uint psfgaoAttribs);
void Compare([In, MarshalAs(UnmanagedType.Interface)] IShellItem psi, [In] uint hint, out int piOrder);
}
[ComImport, Guid("B63EA76D-1F85-456F-A19C-48159EFA858B"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
private interface IShellItemArray
{
void BindToHandler([In, MarshalAs(UnmanagedType.Interface)] IntPtr pbc, [In] ref Guid rbhid, [In] ref Guid riid, out IntPtr ppvOut);
void GetPropertyStore([In] int Flags, [In] ref Guid riid, out IntPtr ppv);
void GetPropertyDescriptionList([In, MarshalAs(UnmanagedType.Struct)] ref IntPtr keyType, [In] ref Guid riid, out IntPtr ppv);
void GetAttributes([In, MarshalAs(UnmanagedType.I4)] IntPtr dwAttribFlags, [In] uint sfgaoMask, out uint psfgaoAttribs);
void GetCount(out uint pdwNumItems);
void GetItemAt([In] uint dwIndex, [MarshalAs(UnmanagedType.Interface)] out IShellItem ppsi);
void EnumItems([MarshalAs(UnmanagedType.Interface)] out IntPtr ppenumShellItems);
}
[ComImport, Guid("d57c7288-d4ad-4768-be02-9d969532d960"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(FileOpenDialog))]
private interface IFileOpenDialog //: IFileDialog
{
[PreserveSig]
int Show([In] IntPtr parent);
void SetFileTypes([In] uint cFileTypes, [In, MarshalAs(UnmanagedType.Struct)] ref IntPtr rgFilterSpec);
void SetFileTypeIndex([In] uint iFileType);
void GetFileTypeIndex(out uint piFileType);
void Advise([In, MarshalAs(UnmanagedType.Interface)] IntPtr pfde, out uint pdwCookie);
void Unadvise([In] uint dwCookie);
void SetOptions([In] FOS fos);
void GetOptions(out FOS pfos);
void SetDefaultFolder([In, MarshalAs(UnmanagedType.Interface)] IShellItem psi);
void SetFolder([In, MarshalAs(UnmanagedType.Interface)] IShellItem psi);
void GetFolder([MarshalAs(UnmanagedType.Interface)] out IShellItem ppsi);
void GetCurrentSelection([MarshalAs(UnmanagedType.Interface)] out IShellItem ppsi);
void SetFileName([In, MarshalAs(UnmanagedType.LPWStr)] string pszName);
void GetFileName([MarshalAs(UnmanagedType.LPWStr)] out string pszName);
void SetTitle([In, MarshalAs(UnmanagedType.LPWStr)] string pszTitle);
void SetOkButtonLabel([In, MarshalAs(UnmanagedType.LPWStr)] string pszText);
void SetFileNameLabel([In, MarshalAs(UnmanagedType.LPWStr)] string pszLabel);
void GetResult([MarshalAs(UnmanagedType.Interface)] out IShellItem ppsi);
void AddPlace([In, MarshalAs(UnmanagedType.Interface)] IShellItem psi, FileDialogCustomPlace fdcp);
void SetDefaultExtension([In, MarshalAs(UnmanagedType.LPWStr)] string pszDefaultExtension);
void Close([MarshalAs(UnmanagedType.Error)] int hr);
void SetClientGuid([In] ref Guid guid);
void ClearClientData();
void SetFilter([MarshalAs(UnmanagedType.Interface)] IntPtr pFilter);
void GetResults([MarshalAs(UnmanagedType.Interface)] out IShellItemArray ppenum);
void GetSelectedItems([MarshalAs(UnmanagedType.Interface)] out IShellItemArray ppsai);
}
[ComImport, Guid("DC1C5A9C-E88A-4dde-A5A1-60F82A20AEF7")]
private class FileOpenDialog
{ }
private enum SIGDN : uint
{
DESKTOPABSOLUTEEDITING = 0x8004c000,
DESKTOPABSOLUTEPARSING = 0x80028000,
FILESYSPATH = 0x80058000,
NORMALDISPLAY = 0,
PARENTRELATIVE = 0x80080001,
PARENTRELATIVEEDITING = 0x80031001,
PARENTRELATIVEFORADDRESSBAR = 0x8007c001,
PARENTRELATIVEPARSING = 0x80018001,
URL = 0x80068000
}
[Flags]
private enum FOS
{
ALLNONSTORAGEITEMS = 0x80,
ALLOWMULTISELECT = 0x200,
CREATEPROMPT = 0x2000,
DEFAULTNOMINIMODE = 0x20000000,
DONTADDTORECENT = 0x2000000,
FILEMUSTEXIST = 0x1000,
FORCEFILESYSTEM = 0x40,
FORCESHOWHIDDEN = 0x10000000,
HIDEMRUPLACES = 0x20000,
HIDEPINNEDPLACES = 0x40000,
NOCHANGEDIR = 8,
NODEREFERENCELINKS = 0x100000,
NOREADONLYRETURN = 0x8000,
NOTESTFILECREATE = 0x10000,
NOVALIDATE = 0x100,
OVERWRITEPROMPT = 2,
PATHMUSTEXIST = 0x800,
PICKFOLDERS = 0x20,
SHAREAWARE = 0x4000,
STRICTFILETYPES = 4
}
#endregion Types
}