多项功能优化
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;
|
||||
|
||||
Reference in New Issue
Block a user