123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- /*-------------------------------------------------------------------------
- * 功能描述:SolidUtil
- * 作者:xulisong
- * 创建时间: 2019/3/12 10:13:46
- * 版本号:v1.0
- * -------------------------------------------------------------------------*/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Autodesk.Revit.DB;
- namespace FWindSoft.Revit.Utils
- {
- public static class SolidUtil
- {
- #region 静态方法
- /// <summary>
- /// 替换视图中的图形,来修改颜色
- /// </summary>
- public static void SetColor(Element elem, Color color, View view = null,
- int transparency = 0)
- {
- var ogs = new OverrideGraphicSettings();
- #region 表面填充图案
- //可见
- ogs.SetProjectionFillPatternVisible(true);
- //颜色
- ogs.SetProjectionFillColor(color);
- //透明度
- ogs.SetSurfaceTransparency(transparency);
- #endregion
- #region 截面填充图案
- //可见
- ogs.SetCutFillPatternVisible(true);
- //颜色
- ogs.SetCutFillColor(color);
- //填充图案
- #endregion
- if (view != null)
- {
- view.SetElementOverrides(elem.Id, ogs);
- }
- else
- {
- elem.Document.ActiveView.SetElementOverrides(elem.Id, ogs);
- }
- }
- /// <summary>
- /// 使用指定的球心和半径创建球体
- /// </summary>
- public static Solid CreateSphereAtPoint(
- XYZ center,
- double radius)
- {
- // 使用标准的全局坐标系创建 Frame
- Frame frame = new Frame(center,
- XYZ.BasisX, XYZ.BasisY, XYZ.BasisZ);
- // 创建一个Z轴方向的半圆闭合曲线(注意所有的坐标都是相对全局坐标系的)
- Arc arc = Arc.Create(
- center - radius * XYZ.BasisZ,
- center + radius * XYZ.BasisZ,
- center + radius * XYZ.BasisX);
- Line line = Line.CreateBound(
- arc.EndPoint(),
- arc.StartPoint());
- CurveLoop halfCircle = new CurveLoop();
- halfCircle.Append(arc);
- halfCircle.Append(line);
- List<CurveLoop> loops = new List<CurveLoop>(1);
- loops.Add(halfCircle);
- return GeometryCreationUtilities
- .CreateRevolvedGeometry(
- frame, loops, 0, 2 * Math.PI);
- }
- public static Solid CreateSphere(List<CurveLoop> loops,XYZ vector)
- {
- return GeometryCreationUtilities.CreateExtrusionGeometry(loops, vector.Normalize(), vector.GetLength());
- }
- #endregion
- }
- }
|