2024-09-22 11:05:41 +08:00
|
|
|
|
// [Directories](文件位置)
|
|
|
|
|
|
//
|
|
|
|
|
|
// ·ProjectPath——打开项目时的默认路径
|
|
|
|
|
|
//
|
|
|
|
|
|
// ·ExternalParameters——共享参数文件保存路径
|
|
|
|
|
|
//
|
|
|
|
|
|
//
|
|
|
|
|
|
//
|
|
|
|
|
|
// [Graphics](图形设置)
|
|
|
|
|
|
//
|
|
|
|
|
|
// ·TempDimFontSizeInPoints——临时尺寸标注文字外观
|
|
|
|
|
|
//
|
|
|
|
|
|
// ·AllowNavigationDuringRedraw——重绘期间允许导航
|
|
|
|
|
|
//
|
|
|
|
|
|
// ·UseGpuOcclusionCulling——仅绘制可见图元
|
|
|
|
|
|
//
|
|
|
|
|
|
// ·Antialiasing——使用反失真平滑线条
|
|
|
|
|
|
//
|
|
|
|
|
|
// ·AntialiasingOptions——使用反失真平滑线条选项
|
|
|
|
|
|
//
|
|
|
|
|
|
// ·SemiTransparent——半透明
|
|
|
|
|
|
//
|
|
|
|
|
|
// ·ThinLinesEnabled——是否启用细线
|
|
|
|
|
|
//
|
|
|
|
|
|
// ·UseGraphicsHardware——是否使用硬件加速
|
|
|
|
|
|
//
|
|
|
|
|
|
//
|
|
|
|
|
|
//
|
|
|
|
|
|
// [Selection](选择设置)
|
|
|
|
|
|
//
|
|
|
|
|
|
// ·AllowFaceSelection——是否按面选择图元
|
|
|
|
|
|
//
|
|
|
|
|
|
// ·AllowLinkSelection——是否选择链接
|
|
|
|
|
|
//
|
|
|
|
|
|
// ·AllowPinnedSelection——是否选择锁定图元
|
|
|
|
|
|
//
|
|
|
|
|
|
// ·AllowPressAndDrag——是否选择时拖拽图元
|
|
|
|
|
|
//
|
|
|
|
|
|
// ·AllowUnderlaySelection——是否选择基线图元
|
|
|
|
|
|
//
|
|
|
|
|
|
//
|
|
|
|
|
|
//
|
|
|
|
|
|
// [Windows](窗口)
|
|
|
|
|
|
//
|
|
|
|
|
|
// ·Maximized = 0(0 = 以最后一次任务期间使用的窗口大小启动 Revit(默认);1 = 以最大化窗口启动 Revit。)
|
|
|
|
|
|
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
2025-04-24 20:56:44 +08:00
|
|
|
|
namespace ShrlAlgoToolkit.Revit.Assists
|
2024-09-22 11:05:41 +08:00
|
|
|
|
{
|
|
|
|
|
|
public static class RevitIniAssist
|
|
|
|
|
|
{
|
|
|
|
|
|
public static string RevitVersion;
|
|
|
|
|
|
|
|
|
|
|
|
public static string IniPath { get; } =
|
|
|
|
|
|
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + $"\\Autodesk\\Revit\\Autodesk Revit {RevitVersion}\\Revit.ini";
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 添加项目样板
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="revitVersion"></param>
|
|
|
|
|
|
/// <param name="revitTemplateIniFilePath">.ini文件的完整路径</param>
|
|
|
|
|
|
/// <param name="templateFilePath"></param>
|
|
|
|
|
|
public static void AddProjectTemplate(string revitVersion, string revitTemplateIniFilePath, string templateFilePath)
|
|
|
|
|
|
{
|
|
|
|
|
|
//Autodesk.Revit.ApplicationServices.Application.CurrentUsersDataFolderPath
|
|
|
|
|
|
string oriDateFilePath = Environment.GetEnvironmentVariable("appdata") + $"\\Autodesk\\Revit\\Autodesk Revit {revitVersion}\\Revit.ini";
|
|
|
|
|
|
|
|
|
|
|
|
if (File.Exists(oriDateFilePath))
|
|
|
|
|
|
{
|
|
|
|
|
|
using (StreamReader sr = new StreamReader(oriDateFilePath, Encoding.Unicode))
|
|
|
|
|
|
{
|
|
|
|
|
|
StreamWriter sw = new StreamWriter(revitTemplateIniFilePath, false, Encoding.Unicode);
|
|
|
|
|
|
string inputLine;
|
|
|
|
|
|
|
|
|
|
|
|
while ((inputLine = sr.ReadLine()) != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (inputLine.StartsWith("DefaultTemplate="))
|
|
|
|
|
|
{
|
|
|
|
|
|
_ = inputLine.Insert(16, templateFilePath);
|
|
|
|
|
|
//if (inputLine.Contains("Example_SCHEMA.rte"))
|
|
|
|
|
|
//{
|
|
|
|
|
|
//}
|
|
|
|
|
|
//else
|
|
|
|
|
|
//{
|
|
|
|
|
|
// inputLine = inputLine + @", Example_SCHEMA=C:\temp\Example_SCHEMA.rte";
|
|
|
|
|
|
//}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sw.WriteLine(inputLine);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sw.Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
File.Replace(revitTemplateIniFilePath, oriDateFilePath, null);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static string ReadRevitIniData(string fileName, string targetTemplateFilePath)
|
|
|
|
|
|
{
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
using (StreamReader sr = new StreamReader(fileName, Encoding.Unicode))
|
|
|
|
|
|
{
|
|
|
|
|
|
string lineBuf;
|
|
|
|
|
|
bool isTargetSection = false;
|
|
|
|
|
|
while ((lineBuf = sr.ReadLine()) != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (lineBuf == "[DirectoriesCHS]")
|
|
|
|
|
|
{
|
|
|
|
|
|
isTargetSection = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (isTargetSection)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (lineBuf.Contains("DefaultTemplate"))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!lineBuf.Contains(targetTemplateFilePath))
|
|
|
|
|
|
{
|
|
|
|
|
|
int starIndex = "DefaultTemplate=".Length;
|
|
|
|
|
|
string endStr = lineBuf.Substring(starIndex);
|
|
|
|
|
|
lineBuf = "DefaultTemplate=" + targetTemplateFilePath;
|
|
|
|
|
|
lineBuf += ",";
|
|
|
|
|
|
lineBuf += endStr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
isTargetSection = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sb.AppendLine(lineBuf);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void WriteFileData(string fileName, string value)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (StreamWriter sw = new StreamWriter(fileName, false, Encoding.Unicode))
|
|
|
|
|
|
{
|
|
|
|
|
|
sw.Write(value);
|
|
|
|
|
|
sw.Flush();
|
|
|
|
|
|
sw.Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void WriteRevitIniData(string existFilePath, string templateFilePath)
|
|
|
|
|
|
{
|
|
|
|
|
|
string directory = Path.GetDirectoryName(existFilePath);
|
|
|
|
|
|
if (directory == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DirectoryInfo dirInfo = new DirectoryInfo(directory);
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if (dirInfo.Exists)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (File.Exists(existFilePath))
|
|
|
|
|
|
{
|
|
|
|
|
|
string outPut = ReadRevitIniData(existFilePath, templateFilePath);
|
|
|
|
|
|
if (!string.IsNullOrEmpty(outPut))
|
|
|
|
|
|
{
|
|
|
|
|
|
WriteFileData(existFilePath, outPut);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine(e);
|
|
|
|
|
|
throw;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|