commit 1588dc09d1a7eb1cce7e6fddd7f9c34e1fafb02a Author: GG Z <903524121@qq.com> Date: Mon Feb 23 11:05:30 2026 +0800 添加项目文件。 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9491a2f --- /dev/null +++ b/.gitignore @@ -0,0 +1,363 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Oo]ut/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd \ No newline at end of file diff --git a/DimensionTools.AddInDeployer/AddInManager.cs b/DimensionTools.AddInDeployer/AddInManager.cs new file mode 100644 index 0000000..03b23b5 --- /dev/null +++ b/DimensionTools.AddInDeployer/AddInManager.cs @@ -0,0 +1,72 @@ +#region + +using System; +using System.IO; +using Autodesk.RevitAddIns; + +#endregion + +namespace DimensionTools.AddInDeployer +{ + public class AddInManager + { + private readonly string vendorDescription = "深圳市地铁集团有限公司"; + private readonly string vendorid = "SZMC"; + + internal AddInManager(string revitVersion, string addinname) + { + Manifest = new RevitAddInManifest(); + ManifestPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), + "Autodesk\\ApplicationPlugins\\DimensionTools.bundle\\Contents", revitVersion, addinname); + //ManifestPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Autodesk\\Revit\\Addins", revitVersion, addinname); + } + + private RevitAddInManifest Manifest { get; } + + private string ManifestPath { get; } + + + internal void CreateApplication(string name, string assemblyPath, string fullClassName) + { + RevitAddInApplication item = + new RevitAddInApplication(name, assemblyPath, Guid.NewGuid(), fullClassName, vendorid) + { + VendorDescription = vendorDescription + }; + Manifest.AddInApplications.Add(item); + } + + internal void CreateCommand(string assemblyPath, string fullClassName) + { + RevitAddInCommand item = new RevitAddInCommand(assemblyPath, Guid.NewGuid(), fullClassName, vendorid) + { + VendorDescription = vendorDescription + }; + Manifest.AddInCommands.Add(item); + } + + internal void Install() + { + DirectoryInfo directory = new FileInfo(ManifestPath).Directory; + if (directory == null) + { + return; + } + + if (!directory.Exists) + { + Directory.CreateDirectory(directory.FullName); + } + + Manifest.SaveAs(ManifestPath); + } + + internal void Uninstall() + { + if (File.Exists(ManifestPath)) + { + File.Delete(ManifestPath); + } + } + } +} \ No newline at end of file diff --git a/DimensionTools.AddInDeployer/CustomAction.config b/DimensionTools.AddInDeployer/CustomAction.config new file mode 100644 index 0000000..9696db3 --- /dev/null +++ b/DimensionTools.AddInDeployer/CustomAction.config @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + diff --git a/DimensionTools.AddInDeployer/CustomAction.cs b/DimensionTools.AddInDeployer/CustomAction.cs new file mode 100644 index 0000000..a4cd118 --- /dev/null +++ b/DimensionTools.AddInDeployer/CustomAction.cs @@ -0,0 +1,63 @@ +using System.Collections.Generic; +using System.IO; +using System.Text; +using Microsoft.Deployment.WindowsInstaller; + +namespace DimensionTools.AddInDeployer +{ + public class CustomActions + { + public const string dllName = "DimensionTools.dll"; + public const string addinName = "DimensionTools.addin"; + + [CustomAction] + public static ActionResult Uninstaller(Session session) + { + session.Log("Begin Uninstaller"); + var commonAppDataFolder = session["CommonAppDataFolder"]; + var addinFilePath = $"{commonAppDataFolder}\\Autodesk\\DimensionTools.bundle"; + Directory.Delete(addinFilePath,true); + return ActionResult.Success; + } + + [CustomAction] + public static ActionResult Installer(Session session) + { + session.Log("Begin Installer"); + var manufacturer = session["Manufacturer"]; + var productName = session["ProductName"]; + var appdir = session["APPDIR"]; //װ·,ûѡ + var sourceDir = session["SourceDir"]; //װѹ· + var programFiles64Folder = session["ProgramFiles64Folder"]; //64λװ·C:\ProgramFiles + var commonAppDataFolder = session["CommonAppDataFolder"]; //C:\ProgramData + var addinFilePath = $"{commonAppDataFolder}\\Autodesk\\DimensionTools.bundle\\Contents"; + //List revitProductsInstalled = RevitProductUtility.GetAllInstalledRevitProducts(); + //foreach (var product in revitProductsInstalled) + //{ + //} + List dlls = new List(); + DirectoryInfo dir = Directory.CreateDirectory(appdir); + StringBuilder sb = new StringBuilder(); + foreach (var fileInfo in dir.GetFiles("*", SearchOption.AllDirectories)) + { + if (fileInfo.Name == dllName) + { + dlls.Add(fileInfo); + } + } + + foreach (var dllPath in dlls) + { + var versionNum = dllPath.Directory.Name; + AddInManager manager = new AddInManager(versionNum, addinName); + + manager.CreateApplication("ע", dllPath.FullName, "DimensionTools.UiRibbon"); + + manager.Uninstall(); + manager.Install(); + } + + return ActionResult.Success; + } + } +} \ No newline at end of file diff --git a/DimensionTools.AddInDeployer/DimensionTools.AddInDeployer.csproj b/DimensionTools.AddInDeployer/DimensionTools.AddInDeployer.csproj new file mode 100644 index 0000000..3b09b48 --- /dev/null +++ b/DimensionTools.AddInDeployer/DimensionTools.AddInDeployer.csproj @@ -0,0 +1,97 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {1E6F7706-97B3-4929-8FF9-79DF5485801B} + Library + Properties + DimensionTools.AddInDeployer + DimensionTools.AddInDeployer + v4.7.2 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + x64 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x64\Debug\ + DEBUG;TRACE + full + AnyCPU + 7.3 + prompt + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + 7.3 + prompt + + + true + bin\Debug\ + DEBUG;TRACE + full + AnyCPU + 7.3 + prompt + + + bin\Release\ + TRACE + true + pdbonly + AnyCPU + 7.3 + prompt + + + + C:\Program Files\Autodesk\Revit 2020\RevitAddInUtility.dll + + + + + + + + + True + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DimensionTools.AddInDeployer/Properties/AssemblyInfo.cs b/DimensionTools.AddInDeployer/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..9150077 --- /dev/null +++ b/DimensionTools.AddInDeployer/Properties/AssemblyInfo.cs @@ -0,0 +1,34 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Szmedi.AddinDeployer")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyCompany("Administrator")] +[assembly: AssemblyProduct("Szmedi.AddinDeployer")] +[assembly: AssemblyCopyright("Copyright © Administrator 2022")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("1e6f7706-97b3-4929-8ff9-79df5485801b")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/DimensionTools.sln b/DimensionTools.sln new file mode 100644 index 0000000..3f0fdbb --- /dev/null +++ b/DimensionTools.sln @@ -0,0 +1,55 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 18 +VisualStudioVersion = 18.3.11512.155 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DimensionTools", "DimensionTools\DimensionTools.csproj", "{5FE4E018-C3DF-481E-A739-9B0B663EDE60}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug One|Any CPU = Debug One|Any CPU + Debug One|x64 = Debug One|x64 + Debug One|x86 = Debug One|x86 + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + DefaultBuild|Any CPU = DefaultBuild|Any CPU + DefaultBuild|x64 = DefaultBuild|x64 + DefaultBuild|x86 = DefaultBuild|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5FE4E018-C3DF-481E-A739-9B0B663EDE60}.Debug One|Any CPU.ActiveCfg = Debug One|x64 + {5FE4E018-C3DF-481E-A739-9B0B663EDE60}.Debug One|Any CPU.Build.0 = Debug One|x64 + {5FE4E018-C3DF-481E-A739-9B0B663EDE60}.Debug One|x64.ActiveCfg = Debug One|x64 + {5FE4E018-C3DF-481E-A739-9B0B663EDE60}.Debug One|x64.Build.0 = Debug One|x64 + {5FE4E018-C3DF-481E-A739-9B0B663EDE60}.Debug One|x86.ActiveCfg = Debug One|x64 + {5FE4E018-C3DF-481E-A739-9B0B663EDE60}.Debug One|x86.Build.0 = Debug One|x64 + {5FE4E018-C3DF-481E-A739-9B0B663EDE60}.Debug|Any CPU.ActiveCfg = Debug|x64 + {5FE4E018-C3DF-481E-A739-9B0B663EDE60}.Debug|Any CPU.Build.0 = Debug|x64 + {5FE4E018-C3DF-481E-A739-9B0B663EDE60}.Debug|x64.ActiveCfg = Debug|x64 + {5FE4E018-C3DF-481E-A739-9B0B663EDE60}.Debug|x64.Build.0 = Debug|x64 + {5FE4E018-C3DF-481E-A739-9B0B663EDE60}.Debug|x86.ActiveCfg = Debug|x64 + {5FE4E018-C3DF-481E-A739-9B0B663EDE60}.Debug|x86.Build.0 = Debug|x64 + {5FE4E018-C3DF-481E-A739-9B0B663EDE60}.DefaultBuild|Any CPU.ActiveCfg = Debug One|x64 + {5FE4E018-C3DF-481E-A739-9B0B663EDE60}.DefaultBuild|Any CPU.Build.0 = Debug One|x64 + {5FE4E018-C3DF-481E-A739-9B0B663EDE60}.DefaultBuild|x64.ActiveCfg = Debug One|x64 + {5FE4E018-C3DF-481E-A739-9B0B663EDE60}.DefaultBuild|x64.Build.0 = Debug One|x64 + {5FE4E018-C3DF-481E-A739-9B0B663EDE60}.DefaultBuild|x86.ActiveCfg = Debug One|x64 + {5FE4E018-C3DF-481E-A739-9B0B663EDE60}.DefaultBuild|x86.Build.0 = Debug One|x64 + {5FE4E018-C3DF-481E-A739-9B0B663EDE60}.Release|Any CPU.ActiveCfg = Release|x64 + {5FE4E018-C3DF-481E-A739-9B0B663EDE60}.Release|Any CPU.Build.0 = Release|x64 + {5FE4E018-C3DF-481E-A739-9B0B663EDE60}.Release|x64.ActiveCfg = Release|x64 + {5FE4E018-C3DF-481E-A739-9B0B663EDE60}.Release|x64.Build.0 = Release|x64 + {5FE4E018-C3DF-481E-A739-9B0B663EDE60}.Release|x86.ActiveCfg = Release|x64 + {5FE4E018-C3DF-481E-A739-9B0B663EDE60}.Release|x86.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {FEA09681-016B-4A46-AEDC-0C863FA1AA1B} + EndGlobalSection +EndGlobal diff --git a/DimensionTools/Civil/ExportPilesInfo.cs b/DimensionTools/Civil/ExportPilesInfo.cs new file mode 100644 index 0000000..5ab2c25 --- /dev/null +++ b/DimensionTools/Civil/ExportPilesInfo.cs @@ -0,0 +1,39 @@ +using System; +using System.IO; + +using Autodesk.Revit.Attributes; +using Autodesk.Revit.DB; +using Autodesk.Revit.UI; + +using EPPlus.Core.Extensions; + +namespace DimensionTools.Civil +{ + /// + /// Revit执行命令 + /// + [Transaction(TransactionMode.Manual)] + [Regeneration(RegenerationOption.Manual)] + public class ExportPilesInfo : IExternalCommand + { + public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) + { + //程序UI界面 + UIApplication uiapp = commandData.Application; + //获取元素(选择) 显示元素 视图(活动视图)管理(对象) + UIDocument uidoc = uiapp.ActiveUIDocument; + + string addInPath = typeof(ExportPilesInfo).Assembly.Location; + string dirAssembly = System.IO.Path.GetDirectoryName(addInPath); + PilesInfo pilesInfo = new PilesInfo(uidoc); + _ = new System.Windows.Interop.WindowInteropHelper(pilesInfo) + { + Owner = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle + }; + pilesInfo.Show(); + + return Result.Succeeded; + //OfficeOpenXml.ExcelWorksheet worksheet = excelPackage.GenerateWorksheet(Assembly.GetExecutingAssembly(), nameof(FamilyInstance)); + } + } +} \ No newline at end of file diff --git a/DimensionTools/Civil/PileModel.cs b/DimensionTools/Civil/PileModel.cs new file mode 100644 index 0000000..59e10f8 --- /dev/null +++ b/DimensionTools/Civil/PileModel.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Autodesk.Revit.DB; + +namespace DimensionTools.Civil +{ + public class PileModel + { + + public string FamilyName { get; set; } + public string SymbolName { get; set; } + public string Code { get; set; } + + public ElementId InstanceId { get; set; } + + public double TopElev { get; set; } + public double BottomElev { get; set; } + + public double WestEast { get; set; } + public double NorthSouth { get; set; } + } +} diff --git a/DimensionTools/Civil/PilesAnnotationCmd.cs b/DimensionTools/Civil/PilesAnnotationCmd.cs new file mode 100644 index 0000000..d0819a9 --- /dev/null +++ b/DimensionTools/Civil/PilesAnnotationCmd.cs @@ -0,0 +1,317 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; + +using Autodesk.Revit.DB; +using Autodesk.Revit.UI; +using Autodesk.Revit.UI.Selection; + +namespace DimensionTools.Civil +{ + [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] + [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] + public class PilesAnnotationCmd : IExternalCommand + { + /// + /// 按路径排序的集合 + /// + private readonly List orderedByPath = new List(); + + public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) + { + UIApplication uiapp = commandData.Application; + UIDocument uidoc = uiapp.ActiveUIDocument; + Document doc = uidoc.Document; + if (doc.ActiveView.ViewType != ViewType.FloorPlan && doc.ActiveView.ViewType != ViewType.CeilingPlan && doc.ActiveView.ViewType != ViewType.EngineeringPlan) + { + message = "请选择平面视图"; + return Result.Failed; + } + string addInPath = typeof(ExportPilesInfo).Assembly.Location; + string dirAssembly = System.IO.Path.GetDirectoryName(addInPath); + PilesDimSettings pilesDim = new PilesDimSettings(doc); + pilesDim.ShowDialog(); + + if (pilesDim.DialogResult != true) return Result.Cancelled; + + var isManualSelected = pilesDim.SelectedRb.IsChecked; + var id = pilesDim.DimStyleCbb.SelectedValue as ElementId; + var ruleIndex = pilesDim.RuleCbb.SelectedIndex; + var prefix = pilesDim.CodeTb.Text; + var canParse = int.TryParse(pilesDim.StartCodeTb.Text, out int startCode); + if (!canParse) + { + TaskDialog.Show("错误", "起始编号有误"); + return Result.Cancelled; + } + + using (TransactionGroup tg = new TransactionGroup(doc, "标注桩")) + { + try + { + //桩集合 + //沿路径编号起点 + FamilyInstance firstElem; + //排序后集合 + List elemsOrdered; + tg.Start(); + if (isManualSelected == true) + { + IList refers = uidoc.Selection.PickObjects(ObjectType.Element, new PileFilter(), "请选择需要编码标注的围护桩"); + var enumerable = from refer in refers + select doc.GetElement(refer) as FamilyInstance; + elemsOrdered = enumerable.OrderBy(x => ((LocationPoint)x.Location).Point.X) + .ThenBy(y => ((LocationPoint)y.Location).Point.Y) + .ToList(); + } + else + { + List elems = new FilteredElementCollector(doc, + doc.ActiveView.Id) + .OfClass(typeof(FamilyInstance)) + .Cast() + .Where(p => p.Name.Contains("桩") || p.Symbol.FamilyName.Contains("桩")) + .ToList(); + switch (ruleIndex) + { + case 0: + //从左到右 + elemsOrdered = elems.OrderBy(x => ((LocationPoint)x.Location).Point.X).ToList(); + break; + case 1: + //从上到下 + elemsOrdered = elems.OrderByDescending(y => ((LocationPoint)y.Location).Point.Y).ToList(); + break; + default: + { + var first = uidoc.Selection.PickObject(ObjectType.Element, new PileFilter(), "请选择路径起点围护桩"); + firstElem = doc.GetElement(first) as FamilyInstance; + elems = elems.Where(x => firstElem != null && x.Id.IntegerValue != firstElem.Id.IntegerValue && x.Symbol.Family.Id == firstElem.Symbol.Family.Id) + .ToList(); + orderedByPath.Clear(); + Order(elems, firstElem); + elemsOrdered = orderedByPath; + break; + } + } + //uidoc.Selection.SetElementIds(elems.Select(e => e.Id).ToList()); + } + + MarkPiles(doc, id, elemsOrdered, isManualSelected); + CodePile(doc, elemsOrdered, prefix, startCode); + + if (tg.GetStatus() == TransactionStatus.Started) + { + tg.Assimilate(); + } + } + catch (Autodesk.Revit.Exceptions.OperationCanceledException) + { + if (tg.GetStatus() == TransactionStatus.Started) + { + tg.RollBack(); + } + } + catch (Exception) + { + if (tg.GetStatus() == TransactionStatus.Started) + { + tg.RollBack(); + } + } + } + + return Result.Succeeded; + } + + /// + /// 桩编号 + /// + /// + /// + /// + /// + private static void CodePile(Document doc, List orderElem, string prefix, int startCode) + { + using (Transaction trans = new Transaction(doc, "围护桩编号")) + { + try + { + trans.Start(); + + for (int i = 0; i < orderElem.Count; i++) + { + //if (i + startCode <= 9) + //{ + // code = startCode == 0 ? $"00{i + 1 + startCode}" : $"00{i + startCode}"; + //} + //else if (i + startCode <= 99) + //{ + // code = startCode == 0 ? $"0{i + 1 + startCode}" : $"0{i + startCode}"; + //} + //else + //{ + // code = startCode == 0 ? $"{i + 1 + startCode}" : $"{i + startCode}"; + //} + int number = i + startCode; + var code = number > 1000 ? number.ToString() : number.ToString().PadLeft(4, '0'); + if (prefix != string.Empty) + { + code = $"{prefix}-{code}"; + } + //间隔四个标注一个 + + orderElem[i].get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).Set(code); + } + + trans.Commit(); + } + catch (Autodesk.Revit.Exceptions.OperationCanceledException) + { + if (trans.GetStatus() == TransactionStatus.Started) + { + trans.RollBack(); + } + } + catch (Exception) + { + if (trans.GetStatus() == TransactionStatus.Started) + { + trans.RollBack(); + } + } + } + } + /// + /// 标注 + /// + /// + /// 坐标标注类型Id + /// + /// 是否手动选择 + private static void MarkPiles(Document doc, ElementId id, List elems, bool? isManualSelected) + { + using (Transaction trans = new Transaction(doc, "标注")) + { + trans.Start(); + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < elems.Count; i++) + { + FamilyInstance fi = elems[i]; + var pt = (fi.Location as LocationPoint)?.Point; + //var face = GeometryUtil.GetTopFaceByElement(fi); + //Reference refer = GeometryUtil.GetSpotDimensionReference(doc, pt) ?? fi.GetReferences(FamilyInstanceReferenceType.CenterFrontBack).FirstOrDefault(); + Reference refer = fi.GetReferences(FamilyInstanceReferenceType.CenterFrontBack).FirstOrDefault(); + if (refer != null) + refer = fi.GetReferences(FamilyInstanceReferenceType.CenterLeftRight).FirstOrDefault(); + //Line l = Line.CreateUnbound(pt, XYZ.BasisZ); + //var t = fi.FindIntersects(l).OrderBy(p => p.Key.Z).LastOrDefault(); + //if (t.Key == null) + //{ + // sb.AppendLine($"{fi.Name}:{fi.Id}"); + // continue; + //} + + if (isManualSelected == true) + { + SpotDimension spotDimension = doc.Create.NewSpotCoordinate(doc.ActiveView, refer, pt, pt + new XYZ(0.1, 1, 0) * 5, pt + XYZ.BasisX * 5, pt, true); + //SpotDimension spotDimension = doc.Create.NewSpotCoordinate(doc.ActiveView, refer, t.Key, t.Key + new XYZ(0.1, 1, 0) * 5, t.Key + XYZ.BasisX * 5, t.Key, true); + spotDimension.ChangeTypeId(id); + } + else + { + //坐标标注 + if (i % 10 == 0) + { + //SpotDimension spotDimension = doc.Create.NewSpotCoordinate(doc.ActiveView, refer, t.Key, t.Key + new XYZ(0.1, 1, 0) * 5, t.Key + XYZ.BasisX * 5, t.Key, true); + SpotDimension spotDimension = doc.Create.NewSpotCoordinate(doc.ActiveView, refer, pt, pt + new XYZ(0.1, 1, 0) * 5, pt + XYZ.BasisX * 5, pt, true); + spotDimension.ChangeTypeId(id); + } + } + + + //pt = face.Origin / 2 + face.Origin.Z * XYZ.BasisZ; + //var centerPoint = face.Origin / 2 + face.Origin.Z * XYZ.BasisZ; + //var pt = fi.GetTransform().OfPoint(centerPoint); + //标高标注 + //SpotDimension spotDimension1 = doc.Create.NewSpotElevation(doc.ActiveView, face.Reference, p, p + new XYZ(0.2, 1, 0) * 5, p + XYZ.BasisX * 2, p, true); + } + + if (sb.Length > 0) + { + TaskDialog.Show("无法创建坐标标注", sb.ToString()); + } + + trans.Commit(); + } + } + + /// + /// 排序 + /// + /// 合集,不包含第一个元素 + /// 第一个元素 + private void Order(List elements, FamilyInstance firstElem) + { + while (true) + { + if (firstElem == null) + { + return; + } + orderedByPath.Add(firstElem); + if (elements.Count == 0) + { + return; + } + Debug.Assert(elements.Count >= 1, "条件不成立"); + //var b = elements.Remove(firstElem); + double distance = 10.0; + FamilyInstance closest = null; + + foreach (var elem in elements) //最后一次循环为0个 + { + if (elements.Count == 1) + { + closest = elem; + } + if (elem.Location is LocationPoint lp && firstElem?.Location is LocationPoint lpf) + { + var tempDistance = (lp.Point - lp.Point.Z * XYZ.BasisZ).DistanceTo(lpf.Point - lpf.Point.Z * XYZ.BasisZ); + if (tempDistance < distance) + { + closest = elem; + distance = tempDistance; + } + } + + } + elements.Remove(closest); + firstElem = closest; + } + } + } + + /// + /// 桩过滤器 + /// + public class PileFilter : ISelectionFilter + { + public bool AllowElement(Element elem) + { + if (elem is FamilyInstance fi) + { + return fi.Symbol.FamilyName.Contains("桩") || fi.Symbol.Name.Contains("桩"); + } + + return false; + } + + public bool AllowReference(Reference reference, XYZ position) + { + return true; + } + } +} \ No newline at end of file diff --git a/DimensionTools/Civil/PilesDimSettings.xaml b/DimensionTools/Civil/PilesDimSettings.xaml new file mode 100644 index 0000000..51f5842 --- /dev/null +++ b/DimensionTools/Civil/PilesDimSettings.xaml @@ -0,0 +1,134 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +