79 lines
3.0 KiB
C#
79 lines
3.0 KiB
C#
using Autodesk.Revit.Attributes;
|
|
using Autodesk.Revit.DB;
|
|
|
|
using Nice3point.Revit.Toolkit.External;
|
|
|
|
using System;
|
|
using System.Text;
|
|
|
|
using System.Windows;
|
|
|
|
|
|
namespace Szmedi.RvKits.ModelManager
|
|
{
|
|
/// <summary>
|
|
/// Revit执行命令
|
|
/// </summary>
|
|
[Transaction(TransactionMode.Manual)]
|
|
public class ResetCoordinateCmd : ExternalCommand
|
|
{
|
|
public override void Execute()
|
|
{
|
|
FolderBrowserDialog dialog = new();
|
|
|
|
if (dialog.ShowDialog(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle))
|
|
{
|
|
string path = dialog.SelectedPath;
|
|
DirectoryInfo directory = Directory.CreateDirectory(path);
|
|
FileInfo[] files = directory.GetFiles("*.rvt", SearchOption.AllDirectories);
|
|
StringBuilder sb = new();
|
|
foreach (FileInfo file in files)
|
|
{
|
|
Document docToProcess = Application.OpenDocumentFile(file.FullName);
|
|
Element bp = new FilteredElementCollector(docToProcess)
|
|
.OfClass(typeof(BasePoint))
|
|
.OfCategory(BuiltInCategory.OST_ProjectBasePoint)
|
|
.FirstElement();
|
|
try
|
|
{
|
|
using (Transaction trans = new(docToProcess, "项目基点归零"))
|
|
{
|
|
trans.Start();
|
|
bool defaultPined = bp.Pinned;
|
|
if (defaultPined)
|
|
{
|
|
bp.Pinned = false;
|
|
}
|
|
docToProcess.Regenerate();
|
|
if (bp.Category.Id == Category.GetCategory(docToProcess, BuiltInCategory.OST_ProjectBasePoint).Id)
|
|
{
|
|
bp.get_Parameter(BuiltInParameter.BASEPOINT_NORTHSOUTH_PARAM).Set(0); //"北/南"
|
|
bp.get_Parameter(BuiltInParameter.BASEPOINT_EASTWEST_PARAM).Set(0); //"东/西"
|
|
bp.get_Parameter(BuiltInParameter.BASEPOINT_ANGLETON_PARAM).Set(0); //"到正北的角度"
|
|
bp.get_Parameter(BuiltInParameter.BASEPOINT_ELEVATION_PARAM).Set(0); //"高程"
|
|
}
|
|
|
|
if (defaultPined)
|
|
{
|
|
bp.Pinned = true;
|
|
}
|
|
|
|
trans.Commit();
|
|
}
|
|
docToProcess.Close(true);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
sb.AppendLine(file.Name);
|
|
docToProcess.Close(false);
|
|
}
|
|
}
|
|
if (sb.Length > 0)
|
|
{
|
|
MessageBox.Show(sb.ToString(), "文件处理失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|