多项功能优化
This commit is contained in:
@@ -5,6 +5,7 @@ using System.Windows;
|
||||
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI;
|
||||
using Autodesk.Revit.UI.Selection;
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
@@ -55,7 +56,71 @@ namespace Sai.RvKits.RvView
|
||||
uiapp =>
|
||||
{
|
||||
var uidoc = uiapp.ActiveUIDocument;
|
||||
var element = uidoc.SelectObject(new FuncFilter(elem => elem.GetLocCurve() is Line));
|
||||
var doc = uidoc.Document;
|
||||
//var element = uidoc.SelectObject(new FuncFilter(elem => elem.GetCurve() is Line));
|
||||
var placeProjectPoint = XYZ.Zero;
|
||||
Line locLine = null;
|
||||
XYZ lookDirection = null;
|
||||
var depth = 4.0;
|
||||
double baseLength = 4.0;
|
||||
Element element;
|
||||
if (IsParallel)
|
||||
{
|
||||
var refer = uidoc.Selection
|
||||
.PickObject(
|
||||
ObjectType.PointOnElement,
|
||||
new FuncFilter(elem => elem.GetCurve() is Line),
|
||||
"请选择前进方向起点(剖面看向将会在前进方向左侧)");
|
||||
var refer1 = uidoc.Selection
|
||||
.PickObject(
|
||||
ObjectType.PointOnElement,
|
||||
new FuncFilter(elem => elem.Id == refer.ElementId),
|
||||
"请选择前进方向终点(剖面看向将会在前进方向左侧)");
|
||||
element = doc.GetElement(refer);
|
||||
|
||||
var startPointPicked = refer.GlobalPoint;
|
||||
var startProjectPoint = element.GetCurve().Project(startPointPicked).XYZPoint;
|
||||
//终点投影
|
||||
var forwardPointPicked = refer1.GlobalPoint;
|
||||
var forwardProjectPoint = element.GetCurve().Project(forwardPointPicked).XYZPoint;
|
||||
//前进方向
|
||||
var d = forwardProjectPoint - startProjectPoint;
|
||||
//剖面宽度、跨度
|
||||
baseLength = d.GetLength();
|
||||
//左侧
|
||||
lookDirection = XYZ.BasisZ.CrossProduct(forwardProjectPoint - startProjectPoint).Normalize();
|
||||
|
||||
//中点,向查看方向反向移动,用于平行剖面的放置
|
||||
placeProjectPoint = (forwardProjectPoint + startProjectPoint) / 2 - lookDirection;
|
||||
}
|
||||
else
|
||||
{
|
||||
var refer = uidoc.Selection
|
||||
.PickObject(
|
||||
ObjectType.PointOnElement,
|
||||
new FuncFilter(elem => elem.GetCurve() is Line),
|
||||
"请选择放置剖面位置");
|
||||
var refer1 = uidoc.Selection
|
||||
.PickObject(
|
||||
ObjectType.PointOnElement,
|
||||
new FuncFilter(elem => elem.Id == refer.ElementId),
|
||||
"剖面看向方向和相对剖面放置的深度");
|
||||
element = doc.GetElement(refer);
|
||||
//正交剖面的放置位置
|
||||
var placePointPicked = refer.GlobalPoint;
|
||||
placeProjectPoint = element.GetCurve().Project(placePointPicked).XYZPoint;
|
||||
//深度的投影
|
||||
var lookPointPicked = refer1.GlobalPoint;
|
||||
var lookProjectPoint = element.GetCurve().Project(lookPointPicked).XYZPoint;
|
||||
|
||||
depth = placeProjectPoint.DistanceTo(lookProjectPoint);
|
||||
|
||||
//if (locLine.Direction.IsAlmostEqualTo((lookPointPicked - startPointPicked).Normalize()))
|
||||
//{
|
||||
//}
|
||||
lookDirection = (lookProjectPoint - placeProjectPoint).Normalize();
|
||||
}
|
||||
locLine = element.GetCurve() as Line;
|
||||
#region 选择方向
|
||||
//var firstTip = "请选择第一个点以确定正交剖面的定位点";
|
||||
//var lastTip = "请选择第二个点以确定拉抻的深度";
|
||||
@@ -64,33 +129,22 @@ namespace Sai.RvKits.RvView
|
||||
// firstTip = "请选择第一个剖面范围水平的边界点";
|
||||
// lastTip = "请选择第二个剖面范围水平的边界点";
|
||||
//}
|
||||
//var firstrefer = uidoc.Selection
|
||||
//var firstrefer = uiapp.Selection
|
||||
// .PickObject(Autodesk.Revit.UI.Selection.ObjectType.PointOnElement, firstTip);
|
||||
//var lastrefer = uidoc.Selection
|
||||
//var lastrefer = uiapp.Selection
|
||||
// .PickObject(Autodesk.Revit.UI.Selection.ObjectType.PointOnElement, lastTip);
|
||||
//var first = firstrefer.GlobalPoint;
|
||||
//var last = firstrefer.GlobalPoint;
|
||||
//var elementByCurve = uidoc.Document.GetElement(firstrefer);
|
||||
//var elementByCurve = uiapp.Document.GetElement(firstrefer);
|
||||
|
||||
//var firstPoint = elementByCurve.GetLocCurve().Project(first).XYZPoint;
|
||||
//var lastPoint = elementByCurve.GetLocCurve().Project(last).XYZPoint;
|
||||
//var firstProjectPoint = elementByCurve.GetCurve().Project(first).XYZPoint;
|
||||
//var lookProjectPoint = elementByCurve.GetCurve().Project(last).XYZPoint;
|
||||
#endregion
|
||||
|
||||
var lc = element.Location as LocationCurve;
|
||||
var line = lc.Curve as Line;
|
||||
var doc = uidoc.Document;
|
||||
//获取剖面图类型
|
||||
var viewfamilyType = doc.OfClass<ViewFamilyType>()
|
||||
.Cast<ViewFamilyType>()
|
||||
.Where(t => t.ViewFamily == ViewFamily.Section)
|
||||
.FirstOrDefault();
|
||||
|
||||
var bb = element.get_BoundingBox(null);
|
||||
var minZ = bb.Min.Z;
|
||||
var maxZ = bb.Max.Z;
|
||||
|
||||
var baseLength = (bb.Max - bb.Min).GetLength();
|
||||
|
||||
ViewSection viewSection = null;
|
||||
BoundingBoxXYZ sectionBox;
|
||||
//transform.x:RightDirection,transform.y:UpDirection=Z轴,transform.z:ViewDirection (r x u=v)
|
||||
@@ -100,8 +154,9 @@ namespace Sai.RvKits.RvView
|
||||
|
||||
Debug.WriteLine($"Min:{bb.Min}");
|
||||
Debug.WriteLine($"Max:{bb.Max}");
|
||||
//获得定位点
|
||||
t.Origin = line.Evaluate(0.5, true).Flatten();
|
||||
//设置定位点
|
||||
//t.Origin = line.Evaluate(0.5, true).Flatten();
|
||||
t.Origin = placeProjectPoint.Flatten();
|
||||
//t.Origin = line.GetEndPoint(0).Flatten();
|
||||
Debug.WriteLine("定义剖面:");
|
||||
Debug.WriteLine($"Transform.Origin:{t.Origin}");
|
||||
@@ -110,15 +165,17 @@ namespace Sai.RvKits.RvView
|
||||
if (IsParallel)
|
||||
{
|
||||
//剖面视图中,裁剪框左下角的点
|
||||
var min = new XYZ(-(baseLength + 1) / 2, minZ - 10, -2);
|
||||
var min = new XYZ(-(baseLength) / 2, minZ - 10, 0);
|
||||
//剖面视图中,裁剪框右上角的点
|
||||
var max = new XYZ((baseLength + 1) / 2, maxZ + 10, 2);
|
||||
var max = new XYZ((baseLength) / 2, maxZ + 10, depth);
|
||||
Debug.WriteLine($"Min:{min}");
|
||||
Debug.WriteLine($"Max:{max}");
|
||||
|
||||
viewName = $"平行剖面-{viewName}";
|
||||
t.BasisX = line.Direction;//与生成的最终剖面视图的RightDirection反向(定义Transform)
|
||||
t.BasisZ = line.Direction.CrossProduct(XYZ.BasisZ);//与生成的最终剖面视图的ViewDirection反向(定义Transform)
|
||||
//与生成的最终剖面视图的RightDirection反向(定义Transform)
|
||||
t.BasisX = XYZ.BasisZ.CrossProduct(lookDirection).Normalize();
|
||||
//与生成的最终剖面视图的ViewDirection反向(定义Transform)
|
||||
t.BasisZ = lookDirection;
|
||||
|
||||
Debug.WriteLine($"Transform.BasisX:{t.BasisX}");
|
||||
Debug.WriteLine($"Transform.BasisZ:{t.BasisZ}");
|
||||
@@ -134,10 +191,10 @@ namespace Sai.RvKits.RvView
|
||||
{
|
||||
//var transform = line.ComputeDerivatives(0.5, true);//求导切向为BasisX
|
||||
viewName = $"正交剖面-{viewName}";
|
||||
t.BasisX = XYZ.BasisZ.CrossProduct(line.Direction);
|
||||
t.BasisZ = line.Direction;
|
||||
var min = new XYZ(-5, minZ - 5, -2);
|
||||
var max = new XYZ(5, maxZ + 5, 2);
|
||||
t.BasisX = XYZ.BasisZ.CrossProduct(locLine.Direction).Normalize();
|
||||
t.BasisZ = locLine.Direction;
|
||||
var min = new XYZ(-10, minZ - 5, 0);
|
||||
var max = new XYZ(10, maxZ + 5, depth);
|
||||
|
||||
Debug.WriteLine($"Transform.BasisX:{t.BasisX}");
|
||||
Debug.WriteLine($"Transform.BasisZ:{t.BasisZ}");
|
||||
@@ -152,7 +209,6 @@ namespace Sai.RvKits.RvView
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@@ -163,6 +219,11 @@ namespace Sai.RvKits.RvView
|
||||
{
|
||||
return;
|
||||
}
|
||||
//获取剖面图类型
|
||||
var viewfamilyType = doc.OfClass<ViewFamilyType>()
|
||||
.Cast<ViewFamilyType>()
|
||||
.Where(t => t.ViewFamily == ViewFamily.Section)
|
||||
.FirstOrDefault();
|
||||
viewSection = ViewSection.CreateSection(uidoc.Document, viewfamilyType.Id, sectionBox);
|
||||
viewSection.DisplayStyle = DisplayStyle.ShadingWithEdges;
|
||||
viewSection.DetailLevel = ViewDetailLevel.Fine;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Autodesk.Revit.DB;
|
||||
|
||||
using Nice3point.Revit.Toolkit.External;
|
||||
|
||||
namespace Sai.RvKits.RvView;
|
||||
@@ -7,20 +8,20 @@ namespace Sai.RvKits.RvView;
|
||||
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
|
||||
public class SectionBoxControllerCmd : ExternalCommand
|
||||
{
|
||||
public override void Execute()
|
||||
{
|
||||
//if (Document.ActiveView.ViewType != ViewType.ThreeD)
|
||||
//{
|
||||
// UiDocument.ActiveView = Document.OfCollector<View3D>().Cast<View3D>().FirstOrDefault(v => !v.IsTemplate);
|
||||
public override void Execute()
|
||||
{
|
||||
//if (Document.ActiveView.ViewType != ViewType.ThreeD)
|
||||
//{
|
||||
// UiDocument.ActiveView = Document.OfCollector<View3D>().Cast<View3D>().FirstOrDefault(v => !v.IsTemplate);
|
||||
|
||||
//}
|
||||
try
|
||||
{
|
||||
WinDialogHelper.ShowModeless<SectionBoxControllerView>(new SectionBoxControllerViewModel(UiDocument));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ErrorMessage = ex.Message;
|
||||
}
|
||||
}
|
||||
//}
|
||||
try
|
||||
{
|
||||
WinDialogHelper.ShowModeless<SectionBoxControllerView>(new SectionBoxControllerViewModel(UiApplication));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ErrorMessage = ex.Message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,14 +15,14 @@ namespace Sai.RvKits.RvView;
|
||||
|
||||
public partial class SectionBoxControllerViewModel : ObservableObject
|
||||
{
|
||||
public SectionBoxControllerViewModel(UIDocument uidoc)
|
||||
public SectionBoxControllerViewModel(UIApplication uiapp)
|
||||
{
|
||||
uidoc.Application.ViewActivated -= Application_ViewActivated;
|
||||
uidoc.Application.ViewActivated += Application_ViewActivated;
|
||||
uiapp.ViewActivated -= Application_ViewActivated;
|
||||
uiapp.ViewActivated += Application_ViewActivated;
|
||||
|
||||
if (uidoc.ActiveView is View3D view3d)
|
||||
if (uiapp.ActiveUIDocument.ActiveView is View3D view3d)
|
||||
{
|
||||
using var trans = new Transaction(uidoc.Document, "激活剖面框");
|
||||
using var trans = new Transaction(uiapp.ActiveUIDocument.Document, "激活剖面框");
|
||||
trans.Start();
|
||||
if (!view3d.IsSectionBoxActive)
|
||||
{
|
||||
@@ -37,7 +37,7 @@ public partial class SectionBoxControllerViewModel : ObservableObject
|
||||
CanModify = false;
|
||||
}
|
||||
setSectionBoxHandler = new ActionEventHandler();
|
||||
this.uidoc = uidoc;
|
||||
this.uiapp = uiapp;
|
||||
}
|
||||
|
||||
private void Application_ViewActivated(object sender, Autodesk.Revit.UI.Events.ViewActivatedEventArgs e)
|
||||
@@ -58,13 +58,13 @@ public partial class SectionBoxControllerViewModel : ObservableObject
|
||||
public ObservableCollection<SectionBox> BoundingBoxes { get; set; } = [];
|
||||
|
||||
private readonly ActionEventHandler setSectionBoxHandler;
|
||||
private readonly UIDocument uidoc;
|
||||
private readonly UIApplication uiapp;
|
||||
private int index = 1;
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanModify))]
|
||||
private void RecordSectionBox()
|
||||
{
|
||||
if (uidoc.Document.ActiveView is View3D { IsSectionBoxActive: true } view3D)
|
||||
if (uiapp.ActiveUIDocument.Document.ActiveView is View3D { IsSectionBoxActive: true } view3D)
|
||||
{
|
||||
BoundingBoxes.Insert(0, new SectionBox($"剖面框 {index}", view3D.GetSectionBox()));
|
||||
index++;
|
||||
@@ -78,19 +78,19 @@ public partial class SectionBoxControllerViewModel : ObservableObject
|
||||
[RelayCommand]
|
||||
private void ResetSectionBox()
|
||||
{
|
||||
setSectionBoxHandler.Raise(_ =>
|
||||
setSectionBoxHandler.Raise(uiapp =>
|
||||
{
|
||||
var doc = uidoc.Document;
|
||||
var uidoc = uiapp.ActiveUIDocument;
|
||||
switch (SectionBoxType)
|
||||
{
|
||||
case SectionBoxType.Element:
|
||||
ResetSectionBoxByElement();
|
||||
ResetSectionBoxByElement(uidoc);
|
||||
break;
|
||||
case SectionBoxType.Rectangle:
|
||||
ResetSectionBoxByRectangle();
|
||||
ResetSectionBoxByRectangle(uidoc);
|
||||
break;
|
||||
case SectionBoxType.ViewSection:
|
||||
ResetSectionBoxByViewSection();
|
||||
ResetSectionBoxByViewSection(uidoc);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -101,7 +101,7 @@ public partial class SectionBoxControllerViewModel : ObservableObject
|
||||
/// <summary>
|
||||
/// 重设元素剖面框
|
||||
/// </summary>
|
||||
private void ResetSectionBoxByElement()
|
||||
private void ResetSectionBoxByElement(UIDocument uidoc)
|
||||
{
|
||||
var doc = uidoc.Document;
|
||||
doc.Invoke(
|
||||
@@ -163,10 +163,9 @@ public partial class SectionBoxControllerViewModel : ObservableObject
|
||||
/// <summary>
|
||||
/// 重设框选剖面框
|
||||
/// </summary>
|
||||
private void ResetSectionBoxByRectangle()
|
||||
private void ResetSectionBoxByRectangle(UIDocument uidoc)
|
||||
{
|
||||
var doc = uidoc.Document;
|
||||
|
||||
doc.Invoke(
|
||||
ts =>
|
||||
{
|
||||
@@ -207,7 +206,7 @@ public partial class SectionBoxControllerViewModel : ObservableObject
|
||||
/// <summary>
|
||||
/// 重设剖面视图范围的剖面框
|
||||
/// </summary>
|
||||
private void ResetSectionBoxByViewSection()
|
||||
private void ResetSectionBoxByViewSection(UIDocument uidoc)
|
||||
{
|
||||
var reference = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, new FuncFilter(elem => elem.Category?.GetHashCode() == -2000278), "请选择剖面视图");
|
||||
var doc = uidoc.Document;
|
||||
@@ -266,8 +265,9 @@ public partial class SectionBoxControllerViewModel : ObservableObject
|
||||
{
|
||||
if (obj is BoundingBoxXYZ boundingBoxXyz)
|
||||
{
|
||||
setSectionBoxHandler.Raise(_ =>
|
||||
setSectionBoxHandler.Raise(uiapp =>
|
||||
{
|
||||
var uidoc = uiapp.ActiveUIDocument;
|
||||
if (uidoc.ActiveView is View3D view3d)
|
||||
{
|
||||
uidoc.Document.Invoke(_ =>
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
using Nice3point.Revit.Toolkit.External;
|
||||
|
||||
using UIFramework;
|
||||
|
||||
namespace Sai.RvKits.RvView;
|
||||
|
||||
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
|
||||
@@ -13,6 +11,8 @@ public class SwitchBackgroundCmd : ExternalCommand
|
||||
public override void Execute()
|
||||
{
|
||||
var col = Application.BackgroundColor;
|
||||
Application.BackgroundColor = col.Red == 255 && col.Green == 255 && col.Blue == 255 ? new Color(32, 40, 49) : new Color(255, 255, 255);
|
||||
Application.BackgroundColor = col.Red == 255 && col.Green == 255 && col.Blue == 255
|
||||
? new Color(32, 40, 49)
|
||||
: new Color(255, 255, 255);
|
||||
}
|
||||
}
|
||||
@@ -313,7 +313,7 @@ public partial class ViewManagerViewModel : ObservableObject
|
||||
return true;
|
||||
}
|
||||
var item = o as ViewManagerModel;
|
||||
return item.Name.Contains(SearchText) || item.UserViewType.GetDescription().Contains(SearchText);
|
||||
return item.Name.Contains(SearchText) || item.UserViewType.GetAttribute<DescriptionAttribute>().Description.Contains(SearchText);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user