75 lines
2.8 KiB
C#
75 lines
2.8 KiB
C#
using System.Linq;
|
||
using System.Windows;
|
||
|
||
using Autodesk.Revit.Attributes;
|
||
using Autodesk.Revit.DB;
|
||
using Autodesk.Revit.UI;
|
||
|
||
using Nice3point.Revit.Toolkit.External;
|
||
|
||
namespace Szmedi.RvKits.ModelManager
|
||
{
|
||
[Transaction(TransactionMode.Manual)]
|
||
|
||
public class ResetBasePoint : ExternalCommand
|
||
{
|
||
public override void Execute()
|
||
{
|
||
//项目基点和测量点的位置在Revit2020版本才能获取,其中关联切换项目基点与测量点,测量点与底层坐标的关系相关的API在Revit2021.1才能使用,故当前无法实现
|
||
System.Collections.Generic.List<BasePoint> basePoints = Document.OfType<BasePoint>().ToList();
|
||
ProjectLocation projectLocation = UiDocument.Document.ActiveProjectLocation;
|
||
ProjectPosition projectPosition = projectLocation.GetProjectPosition(XYZ.Zero);
|
||
using Transaction trans = new(Document, "重置基点坐标");
|
||
try
|
||
{
|
||
trans.Start();
|
||
foreach (BasePoint basePoint in basePoints)
|
||
{
|
||
if (basePoint.IsShared) //测量点
|
||
{
|
||
#if REVIT2018 || REVIT2019
|
||
MessageBox.Show("该功能在Revit2020才可以使用", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||
#elif REVIT2020
|
||
if (!basePoint.SharedPosition.IsAlmostEqualTo(XYZ.Zero))
|
||
{
|
||
//basePoint.Pinned = false;
|
||
XYZ translate1 = XYZ.Zero - basePoint.SharedPosition;
|
||
basePoint.Location.Move(translate1);
|
||
}
|
||
|
||
//basePoint.Pinned = true;
|
||
XYZ translate = XYZ.Zero - basePoint.Position;
|
||
basePoint.Location.Move(translate);
|
||
#endif
|
||
}
|
||
else //项目基点
|
||
{
|
||
#if REVIT2018 || REVIT2019
|
||
|
||
#elif REVIT2020
|
||
XYZ translate = XYZ.Zero - basePoint.Position;
|
||
basePoint.Location.Move(translate);
|
||
#endif
|
||
}
|
||
//项目基点
|
||
if (basePoint.Category.Id == Category.GetCategory(Document, BuiltInCategory.OST_ProjectBasePoint).Id) { }
|
||
|
||
if (basePoint.Category.Id == Category.GetCategory(Document, BuiltInCategory.OST_SharedBasePoint).Id) { }
|
||
}
|
||
|
||
//Do Something.
|
||
trans.Commit();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
ErrorMessage = ex.Message;
|
||
if (trans.GetStatus() == TransactionStatus.Started)
|
||
{
|
||
trans.RollBack();
|
||
}
|
||
Result = Result.Failed;
|
||
}
|
||
}
|
||
}
|
||
}
|