1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using System;
- using Autodesk.Revit.DB;
- namespace SAGA.RevitUtils.Extends
- {
- public static class LocationExtend
- {
- /// <summary>
- /// 定位点
- /// </summary>
- /// <param name="loc"></param>
- /// <returns></returns>
- public static XYZ GetPoint(this Location loc)
- {
- XYZ point = null;
- if (loc is LocationPoint lp)
- {
- point = lp?.Point;
- }
- else if(loc is LocationCurve lc)
- {
- point = lc.Curve.MiddlePoint();
- }
-
- return point;
- }
- /// <summary>
- /// 转角度
- /// </summary>
- /// <param name="loc"></param>
- /// <returns></returns>
- public static double GetRotation(this Location loc)
- {
- double dRotate = 0;
- try
- {
- if (loc is LocationPoint lp)
- dRotate = lp.Rotation;//MEP中有一些族获取此参数时抛出不明异常
- }
- catch { }
- return dRotate;
- }
- /// <summary>
- /// 定位曲线
- /// </summary>
- /// <param name="loc"></param>
- /// <returns></returns>
- public static Curve GetCurve(this Location loc)
- {
- if (!(loc is LocationCurve)) return null;
- LocationCurve lc = loc as LocationCurve;
- return lc.Curve;
- }
- /// <summary>
- /// 定位线
- /// </summary>
- /// <param name="loc"></param>
- /// <returns></returns>
- public static Line GetLine(this Location loc)
- {
- return loc.GetCurve().GetLine();
- }
- public static bool MoveLength(this LocationCurve location, double length, bool isOuter)
- {
- Curve curve = location.Curve;
- XYZ translation;
- if (curve is Line)
- {
- Line line = curve as Line;
- translation = line.Direction;
- translation = translation.VectorRotate(isOuter ? -Math.PI / 2 : Math.PI / 2, line.StartPoint()) * length;
- return location.Move(translation);
- }
- else if (curve is Arc)
- {
- Arc arc = curve as Arc;
- XYZ center = arc.Center;
- XYZ middle = arc.MiddlePoint();
- Line line = Line.CreateBound(middle, center);
- translation = line.Direction;
- if (isOuter)
- translation = translation.VectorRotate(-Math.PI, line.StartPoint()) * length;
- else
- translation = translation * length;
- return location.Move(translation);
- }
- return false;
- }
- }
- }
|