Files
ShrlAlgoToolkit/ShrlAlgoToolkit.RevitAddins/RvIndependent/MetroGauges/GaugesModelView.xaml.cs
2025-04-24 20:56:44 +08:00

849 lines
29 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Collections.ObjectModel;
using System.Data;
using System.Globalization;
using System.IO;
using System.Windows;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace ShrlAlgoToolkit.RevitAddins.RvIndependent.MetroGauges;
using Curve = LandXMLData.Curve;
using LandXMLData_Alignment = LandXMLData.Alignment;
using LandXMLData_CircCurve = LandXMLData.CircCurve;
using LandXMLData_Spiral = LandXMLData.Spiral;
using Line = LandXMLData.Line;
using Model = LandXMLData.Model;
using TextPoint2D = LandXMLData.TextPoint2D;
/// <summary>
/// Interaction logic for GaugesModelView.xaml
/// </summary>
public partial class GaugesModelView
{
public GaugesModelView(UIApplication uiapp)
{
InitializeComponent();
this.uiapp = uiapp;
doc = uiapp.ActiveUIDocument.Document;
}
private readonly CircuitHelper ch = new();
private readonly Document doc;
private readonly ProfileHelper ph = new();
private readonly UIApplication uiapp;
private LandXMLData_Alignment align;
private ObservableCollection<Region> allregions;
private bool isSolid;
private Model result;
/// <summary>
/// 按桩号创建体量
/// </summary>
/// <param name="horizonCurve"></param>
/// <param name="startStation"></param>
/// <param name="endStation"></param>
/// <param name="al"></param>
/// <param name="endProfilePath"></param>
public void CreateFormByStation(
LandXMLData_Alignment al,
CurveByPoints horizonCurve,
double startStation,
double endStation,
string startProfilePath,
string endProfilePath
)
{
var starpara = (startStation - al.StationStart) / horizonCurve.GeometryCurve.Length;
var endpara = (endStation - al.StationStart) / horizonCurve.GeometryCurve.Length;
}
/// <summary>
/// 从LandXML中得到平曲线数据转成DataTable
/// </summary>
/// <param name="al"></param>
/// <returns></returns>
private DataTable CoordGeomData(LandXMLData_Alignment al)
{
DataTable dt = new("CoordGeom");
dt.Columns.Add("曲线类型", typeof(string)); //直缓圆
dt.Columns.Add("起点北距", typeof(double)); //Y
dt.Columns.Add("起点东距", typeof(double)); //X
dt.Columns.Add("终点北距", typeof(double)); //Y
dt.Columns.Add("终点东距", typeof(double)); //X
dt.Columns.Add("半径m", typeof(string)); //radius
dt.Columns.Add("长度m", typeof(double)); //length
var hc = al.CoordGeom.HorizonCurve;
for (var i = 0; i < hc.Count; i++)
{
var dr = dt.NewRow();
if (hc[i].GetType() == typeof(Curve))
{
var c = (Curve)hc[i];
//dr[1] = c.GetType().Name;
dr[0] = "圆曲线";
dr[1] = Math.Round(c.Start.First, 3, MidpointRounding.AwayFromZero);
dr[2] = Math.Round(c.Start.Second, 3, MidpointRounding.AwayFromZero);
dr[3] = Math.Round(c.End.First, 3, MidpointRounding.AwayFromZero);
dr[4] = Math.Round(c.End.Second, 3, MidpointRounding.AwayFromZero);
dr[5] = Math.Round(c.Radius, 3, MidpointRounding.AwayFromZero).ToString(CultureInfo.InvariantCulture);
dr[6] = Math.Round(c.Length, 3, MidpointRounding.AwayFromZero);
}
else if (hc[i].GetType() == typeof(Line))
{
var l = (Line)hc[i];
//dr[1] = l.GetType().Name;
dr[0] = "直线";
dr[1] = Math.Round(l.Start.First, 3, MidpointRounding.AwayFromZero);
dr[2] = Math.Round(l.Start.Second, 3, MidpointRounding.AwayFromZero);
dr[3] = Math.Round(l.End.First, 3, MidpointRounding.AwayFromZero);
dr[4] = Math.Round(l.End.Second, 3, MidpointRounding.AwayFromZero);
dr[5] = "∞";
dr[6] = Math.Round(l.Length, 3, MidpointRounding.AwayFromZero);
}
else if (hc[i].GetType() == typeof(Spiral))
{
var s = (LandXMLData_Spiral)hc[i];
//dr[1] = s.GetType().Name;
dr[0] = "缓和曲线";
dr[1] = Math.Round(s.Start.First, 3, MidpointRounding.AwayFromZero);
dr[2] = Math.Round(s.Start.Second, 3, MidpointRounding.AwayFromZero);
dr[3] = Math.Round(s.End.First, 3, MidpointRounding.AwayFromZero);
dr[4] = Math.Round(s.End.Second, 3, MidpointRounding.AwayFromZero);
dr[5] = s.RadiusStart + "-" + s.RadiusEnd;
dr[6] = Math.Round(s.Length, 3, MidpointRounding.AwayFromZero);
}
dt.Rows.Add(dr);
}
return dt;
}
/// <summary>
/// 从LandXML中得到竖曲线数据转成DataTable
/// </summary>
/// <param name="al"></param>
/// <returns></returns>
private DataTable ProfileData(LandXMLData_Alignment al)
{
DataTable dt = new("Profile");
dt.Columns.Add("类型", typeof(string)); //起终点,变坡点
dt.Columns.Add("桩号m", typeof(double));
dt.Columns.Add("高程m", typeof(double));
dt.Columns.Add("半径m", typeof(string));
dt.Columns.Add("曲线长m", typeof(double));
var profCurs = al.Profile.ProfileCurve;
for (var i = 0; i < profCurs.Count; i++)
{
for (var j = 0; j < profCurs[i].PVIs.Count; j++)
{
var p = profCurs[i].PVIs[j];
var dr = dt.NewRow();
if (p.GetType() == typeof(TextPoint2D) && j == 0)
{
var t = p;
//dr[1] = t.GetType().Name;
dr[0] = "起点";
dr[1] = Math.Round(t.First, 3, MidpointRounding.AwayFromZero);
dr[2] = Math.Round(t.Second, 3, MidpointRounding.AwayFromZero);
dr[3] = 0;
dr[4] = t.Length;
}
else if (p.GetType() == typeof(CircCurve))
{
var c = (LandXMLData_CircCurve)p;
//dr[1] = c.GetType().Name;
dr[0] = "变坡点";
dr[1] = Math.Round(c.First, 3, MidpointRounding.AwayFromZero);
dr[2] = Math.Round(c.Second, 3, MidpointRounding.AwayFromZero);
dr[3] = c.Radius;
dr[4] = Math.Round(c.CurveLength, 3, MidpointRounding.AwayFromZero);
}
else if (p.GetType() == typeof(TextPoint2D) && j < profCurs[i].PVIs.Count - 1)
{
var t = p;
//dr[1] = t.GetType().Name;
dr[0] = "变坡点";
dr[1] = Math.Round(t.First, 3, MidpointRounding.AwayFromZero);
dr[2] = Math.Round(t.Second, 3, MidpointRounding.AwayFromZero);
dr[3] = 0;
dr[4] = t.Length;
}
else
{
var t = p;
//dr[1] = t.GetType().Name;
dr[0] = "终点";
dr[1] = Math.Round(t.First, 3, MidpointRounding.AwayFromZero);
dr[2] = Math.Round(t.Second, 3, MidpointRounding.AwayFromZero);
dr[3] = 0;
dr[4] = t.Length;
}
dt.Rows.Add(dr);
}
}
return dt;
}
/// <summary>
/// 初始化区域
/// </summary>
/// <param name="al"></param>
/// <returns></returns>
private ObservableCollection<Region> Regions(LandXMLData_Alignment al)
{
allregions = new ObservableCollection<Region>();
var endsta = al.StationStart + al.Length;
Region re = new(al.StationStart, endsta);
allregions.Add(re);
DgCross.ItemsSource = allregions;
return allregions;
}
/// <summary>
/// 设置项目基点
/// </summary>
/// <param name="position"></param>
private void SetProjectPosition(XYZ position)
{
using Transaction trans = new(doc);
trans.Start("设置项目基点");
XYZ p = new();
ProjectPosition pp = new(position.X, position.Y, position.Z, 0);
//设置项目基点
doc.ActiveProjectLocation.SetProjectPosition(p, pp);
trans.Commit();
}
private void BtnAdd_Click(object sender, RoutedEventArgs e)
{
var endStation = align.StationStart + align.Length;
Region region = new(allregions[allregions.Count - 1].EndStation, endStation);
allregions.Add(region);
}
/// <summary>
/// 删除区间
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnDelete_Click(object sender, RoutedEventArgs e)
{
//Button aBtn = sender as Button;
//string ID = aBtn.ReferenceFamily.ToString();
allregions.RemoveAt(DgCross.SelectedIndex);
//DGCross.
//((Button)sender)
}
/// <summary>
/// 终点断面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnEndLoad_Click(object sender, RoutedEventArgs e)
{
const string filter = "断面文件(*.xml;*.rfa|*.Xml;*.xml;*.rfa|所有文件(*.*|*.*";
FileOpenDialog dialog = new(filter) { Title = "选择XML文件", };
if (dialog.Show() == ItemSelectionDialogResult.Confirmed)
{
//Region region = (Region)DGCross.SelectedItem;
var region = (Region)DgCross.SelectedValue;
region.FilePathEnd = ModelPathUtils.ConvertModelPathToUserVisiblePath(dialog.GetSelectedModelPath());
FileInfo fileInfo = new(region.FilePathEnd);
region.FileNameEnd = fileInfo.Name;
//BindingExpression b = DGCross.GetBindingExpression();
//b.UpdateTarget();
DgCross.ItemsSource = null;
DgCross.ItemsSource = allregions;
}
}
private void BtnSetByCurve_Click(object sender, RoutedEventArgs e)
{
if (align != null)
{
var dict = ch.GetIntervalRegion(align);
allregions.Clear();
allregions = new ObservableCollection<Region>();
foreach (var reg in dict.Values)
{
allregions.Add(reg);
}
DgCross.ItemsSource = null;
DgCross.ItemsSource = allregions;
}
else
{
MessageBox.Show("请加载LandXML文件", "提示");
//System.Windows.MessageBox.ShowAhead("请加载LandXML文档");
}
}
/// <summary>
/// 起始断面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnStartLoad_Click(object sender, RoutedEventArgs e)
{
const string filter = "断面文件(*.xml;*.rfa|*.Xml;*.xml;*.rfa|所有文件(*.*|*.*";
FileOpenDialog dialog = new(filter) { Title = "选择XML文件", };
if (dialog.Show() == ItemSelectionDialogResult.Confirmed)
{
//Region region = (Region)DGCross.SelectedItem;
var region = (Region)DgCross.SelectedValue;
region.FilePathStart = ModelPathUtils.ConvertModelPathToUserVisiblePath(dialog.GetSelectedModelPath());
FileInfo fileInfo = new(region.FilePathEnd);
region.FileNameStart = fileInfo.Name;
//BindingExpression b = DGCross.GetBindingExpression();
//b.UpdateTarget();
DgCross.ItemsSource = null;
DgCross.ItemsSource = allregions;
}
}
/// <summary>
/// 创建体量
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CreateFrom_Click(object sender, RoutedEventArgs e)
{
using Transaction trans = new(doc, "ProcessMode");
trans.Start();
if (doc.IsFamilyDocument)
{
var horiPts = ch.GetHorizonPts(align, doc);
XYZ mDir = new((horiPts[0].X / 2) + (horiPts.Last().X / 2), (horiPts[0].Y / 2) + (horiPts.Last().Y / 2), 0);
var tf = Transform.CreateTranslation(-mDir);
foreach (var reg in allregions)
{
if (!reg.FileNameStart.EndsWith(".rfa"))
{
MessageBox.Show("请设置rfa断面文件", "提示");
trans.RollBack();
return;
}
var pts = ch.Get3DRefPointOfRegion(align, reg, 1);
//错误警告处理
var fho1 = trans.GetFailureHandlingOptions();
fho1.SetFailuresPreprocessor(new FailuresPreProcessor());
trans.SetFailureHandlingOptions(fho1);
ReferencePointArray translatedRefpts = new();
for (var i = 0; i < pts.Count; i++)
{
//XYZ p = tf.OfPoint(pts[i]);
var p = CircuitHelper.TransformPoint(pts[i], tf);
var refp = doc.FamilyCreate.NewReferencePoint(p);
//var refp = doc.FamilyCreate.NewReferencePoint(pts[i]);
translatedRefpts.Append(refp);
}
var curve = doc.FamilyCreate.NewCurveByPoints(translatedRefpts);
ReferenceArrayArray profiles = new();
var staProfileCurs = ph.ProfileFromRfa(uiapp, curve, reg, 0);
var endProfileCurs = ph.ProfileFromRfa(uiapp, curve, reg, 1);
profiles.Append(staProfileCurs);
profiles.Append(endProfileCurs);
////取得放样融合路径曲线的参照
ReferenceArray path = new();
path.Append(curve.GeometryCurve.Reference);
try
{
isSolid = CbSolid.IsChecked == true;
//Getprofiles(curve, reg);
//doc.FamilyCreate.NewLoftForm(isSolid, Getprofiles(curve, reg));
doc.FamilyCreate.NewSweptBlendForm(isSolid, path, profiles);
//doc.FamilyCreate.NewSweptBlendForm(isSolid, path, Getprofiles(curve, reg));
}
catch (Exception ex)
{
trans.RollBack();
//throw new Exception(e.ViewMessage);
MessageBox.Show(ex.Message);
return;
//throw;
}
//doc.FamilyCreate.NewSweptBlendForm(true, path, profiles);
//Autodesk.Revit.DB.Line l=Autodesk.Revit.DB.Line.CreateBound(stapt, enpt);
//CurveArray curarray = new CurveArray();
//curarray.Append(l);
//CurveArrArray curarrarray = new CurveArrArray();
//curarrarray.Append(curarray);
//SweepProfile sweep = doc.Application.Create.NewCurveLoopsProfile(curarrarray);
//doc.FamilyCreate.NewSweep(true, path, sweep, 0, ProfilePlaneLocation.Start);
//revitDoc.CloseTrigger(false);
//form.Name = align.Name;
}
}
else
{
//Solid solid = GeometryCreationUtilities.CreateSweptBlendGeometry(path,)
var ds = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_Mass));
ds?.AppendShape(new List<GeometryObject>());
}
trans.Commit();
}
private void CreateGaugesModel_Click(object sender, RoutedEventArgs e)
{
//Document formdoc = uiApplication.Application.NewFamilyDocument(@"C:\ProgramData\Autodesk\RVT 2017\Family Templates\Chinese\概念体量\公制体量.rft");
//this.formdoc = formdoc;
Transaction trans = new(doc, "ProcessMode");
trans.Start();
if (doc.IsFamilyDocument)
{
var horiPts = ch.GetHorizonPts(align, doc);
var tf = Transform.CreateTranslation(new XYZ(-horiPts[0].X, -horiPts[0].Y, 0));
foreach (var reg in allregions)
{
if (!reg.FileNameStart.EndsWith(".xml"))
{
MessageBox.Show("请设置xml断面文件", "提示");
trans.RollBack();
return;
}
var pts = ch.Get3DRefPointOfRegion(align, reg, 1);
//错误警告处理
var fho1 = trans.GetFailureHandlingOptions();
fho1.SetFailuresPreprocessor(new FailuresPreProcessor());
trans.SetFailureHandlingOptions(fho1);
ReferencePointArray refpts = new();
for (var i = 0; i < pts.Count; i++)
{
//XYZ p = tf.OfPoint(pts[i]);
var p = CircuitHelper.TransformPoint(pts[i], tf);
var refp = doc.FamilyCreate.NewReferencePoint(p);
//var refp = doc.FamilyCreate.NewReferencePoint(pts[i]);
refpts.Append(refp);
}
var curve = doc.FamilyCreate.NewCurveByPoints(refpts);
ReferenceArrayArray profiles = new();
var startprof0 = ph.ProfileFromXml(doc, curve, reg, ph.GetXmlOthersPt(reg.FilePathStart), 0);
var endprof0 = ph.ProfileFromXml(doc, curve, reg, ph.GetXmlOthersPt(reg.FilePathEnd), 1);
profiles.Append(startprof0);
profiles.Append(endprof0);
////取得放样融合路径曲线的参照
ReferenceArray path = new();
path.Append(curve.GeometryCurve.Reference);
doc.FamilyCreate.NewSweptBlendForm(true, path, profiles);
}
//if (formdoc.IsFamilyDocument)
//{
// FamilyManager fm = formdoc.FamilyManager;
// string name = "formname";
// FamilyType cft = fm.NewType(name);
// cft = fm.CurrentType;
//}
//获取到的是英制的单位*304.8/1000转公制
//double l0 = curve.GeometryCurve.Length * 304.8 / 1000;
//for (int i = 0; i < allregions.Count; i++)
//{
//CreateFormByStation(align, GetHorizonCurve(align), allregions[i].StartStation, allregions[i].EndStation, allregions[i].FilePathStart, allregions[i].FilePathEnd);
//}
}
trans.Commit();
trans.Dispose();
}
/// <summary>
/// 得到起终点线段中心点的向量的偏移变换
/// </summary>
private void LoadLandXml_Click(object sender, RoutedEventArgs e)
{
const string filter = "LandXML文件(*.Xml,*.xml)|*.Xml;*.xml";
FileOpenDialog dialog = new(filter) { Title = "选择LandXML文件", };
if (dialog.Show() == ItemSelectionDialogResult.Confirmed)
{
var file = ModelPathUtils.ConvertModelPathToUserVisiblePath(dialog.GetSelectedModelPath());
Loader load = new();
result = load.Load(file);
if (doc != null)
{
var aligns = result.Alignments.AlignmentList;
DgHorizon.ItemsSource = CoordGeomData(aligns[0]).DefaultView;
DgVertical.ItemsSource = ProfileData(aligns[0]).DefaultView;
DgCross.ItemsSource = Regions(aligns[0]);
align = aligns[0];
//DGCross.DataContext = InitCross(al);
//DGCross.DataContext = InitCross(al);
//pointsdt = SpaceXYs(CoordGeomData(al));
//formName = al.Name;
}
}
if (result != null)
{
btnSetByCurve.IsEnabled = true;
btnCreateGauges.IsEnabled = true;
btnCreateForm.IsEnabled = true;
}
}
#region
private void DGHorizon_LoadingRow(object sender, System.Windows.Controls.DataGridRowEventArgs e)
{
e.Row.Header = e.Row.GetIndex() + 1;
}
private void DGVertical_LoadingRow(object sender, System.Windows.Controls.DataGridRowEventArgs e)
{
e.Row.Header = e.Row.GetIndex() + 1;
}
private void DGCross_LoadingRow(object sender, System.Windows.Controls.DataGridRowEventArgs e)
{
e.Row.Header = e.Row.GetIndex() + 1;
}
#endregion
#region
// formdoc = UiDocument.Document;
// Transaction trans = new Transaction(formdoc, "horizon");
// XYZ xAxis = new XYZ(1, 0, 0);
// XYZ yAxis = new XYZ(0, 1, 0);
// XYZ zAxis = new XYZ(0, 0, 1);
// XYZ origin = new XYZ();
// //生成三维路线的全部点
// trans.Start();
// //ReferencePointArray refpts = new ReferencePointArray();
// ReferencePointArray D3pt = new ReferencePointArray();
// for (int i = 0; i < spts.Count; i++)
// {
// XYZ p = new XYZ(spts[i].X, spts[i].Y, spts[i].Bottom);
// ReferencePoint refpt = formdoc.FamilyCreate.NewReferencePoint(p);
// D3pt.Append(refpt);
// }
// //CurveByPoints curve = formdoc.FamilyCreate.NewCurveByPoints(refpts);
// CurveByPoints curve = formdoc.FamilyCreate.NewCurveByPoints(D3pt);
// //curve.GeometryCurve.Evaluate(, false);
// //curve.GeometryCurve.ComputeDerivatives();
// trans.Commit();
//var dp = DividedPath.Create(formdoc, refs);
//dp.FixedNumberOfPoints = 200;
//dp.SpacingRuleLayout = SpacingRuleLayout.FixedNumber;
//dp.MeasurementType = DividedPathMeasurementType.SegmentLength;
////Options ops = new Options();
////ops.View = formdoc.ActiveView;
////var points = dp.get_Geometry(ops).GetEnumerator();
////Autodesk.Revit.DB.Point pt=
//ErrorModels<Autodesk.Revit.DB.Point> pts = new ErrorModels<Autodesk.Revit.DB.Point>();
//formdoc.Regenerate();
//Options opts = dp.Document.Application.Create.NewGeometryOptions();
//opts.ComputeReferences = true;
//opts.View = dp.Document.ActiveView;
////opts.IncludeNonVisibleObjects = true;
//GeometryElement geoels = dp.get_Geometry(opts);
//var elsenu = geoels.GetEnumerator();
//while (elsenu.MoveNext())
//{
// Autodesk.Revit.DB.Point pt = (Autodesk.Revit.DB.Point)elsenu.Current;
// pts.Add(pt);
//}
//ReferencePointArray refpts = new ReferencePointArray();
//foreach (var pt in pts)
//{
// ReferencePoint refpt = formdoc.FamilyCreate.NewReferencePoint(pt.Coord);
// refpts.Append(refpt);
//}
//CurveByPoints HorizonCurve = formdoc.FamilyCreate.NewCurveByPoints(refpts);
////var p = HorizonCurve.GeometryCurve.Evaluate(0.5, true);
////var l = HorizonCurve.GeometryCurve.Tessellate();
////var r = HorizonCurve.GeometryCurve.ProjectOf(origin);
//HorizonCurve.GeometryCurve.GetEndParameter(1);
//PointOnCurveMeasurementType.SegmentLength;点沿着曲线放置方式
//private IList<XYZ> SpaceXYs(DataTable dt)
//{
// IList<XYZ> pts = new ErrorModels<XYZ>();
// for (int i = 0; i < dt.Rows.Count; i++)
// {
// if (i < dt.Rows.Count - 1)
// {
// XYZ pt = new XYZ(Convert.ToDouble(dt.Rows[i][2]), Convert.ToDouble(dt.Rows[i][3]), 0);
// pts.Add(pt);
// }
// else
// {
// pts.Add(new XYZ(Convert.ToDouble(dt.Rows[i][6]), Convert.ToDouble(dt.Rows[i][7]), 0));
// }
// }
// return pts;
//}
///// <param name="pts"></param>
//private void CreatForm(string formname, IList<XYZ> pts)
//{
// Document formdoc = uiApplication.Application.NewFamilyDocument(@"C:\ProgramData\Autodesk\RVT 2016\Family Templates\Chinese\概念体量\公制体量.rft");
// this.formdoc = formdoc;
// #region 注释
// //FilteredElementCollector col = new FilteredElementCollector(formdoc).OfClass(typeof(View3D));
// //foreach (View3D v3d in col)
// //{
// // if (v3d.ViewName =="{3D}")
// // {
// // v = v3d;
// // }
// //}
// //XYZ max = new XYZ();
// //XYZ min = new XYZ();
// //max= curve.get_BoundingBox(v).Max;
// //min = curve.get_BoundingBox(v).Min;
// //XYZ v = new XYZ(-(refpoints.get_Item(0).Position.X + refpoints.get_Item(refpoints.Size - 1).Position.X) / 2, -(refpoints.get_Item(0).Position.Y + refpoints.get_Item(refpoints.Size - 1).Position.Y) / 2, 0);
// #endregion
// //得到变换向量坐标
// ReferencePointArray refpoints = new ReferencePointArray();
// XYZ v = new XYZ(-(pts[0].X + pts[pts.Count - 1].X) * 1000 / 304.8 / 2, -(pts[0].Y + pts[pts.Count - 1].Y) * 1000 / 304.8 / 2, 0);
// //项目基点坐标
// XYZ projectPt = v.Negate();
// Transform tf = Transform.CreateTranslation(v);
// refpoints.Clear();
// Transaction tr = new Transaction(formdoc);
// tr.Start("创建实体");
// foreach (var pt in pts)
// {
// //XYZ point = ImpericalToMetric(pt);
// //XYZ xyz = TransformPoint(point, tf);
// XYZ xyz = TransformPoint(pt, tf);
// ReferencePoint refpt = formdoc.FamilyCreate.NewReferencePoint(xyz);
// refpoints.Append(refpt);
// }
// CurveByPoints curve = formdoc.FamilyCreate.NewCurveByPoints(refpoints);
// //BoundingBoxXYZ bd = new BoundingBoxXYZ();
// //Plane staplane = Plane.CreateByNormalAndOrigin((curve.GeometryCurve as HermiteSpline).Tangents[0], curve.GeometryCurve.GetEndPoint(0));
// #region 截面
// Plane staplane = Plane.CreateByNormalAndOrigin(curve.GeometryCurve.GetEndPoint(0), (curve.GeometryCurve as HermiteSpline).Tangents[0]);
// Arc arc0 = Arc.Create(staplane, 2000 / 304.8, 0, 2 * Math.PI);
// ModelCurve mc = formdoc.FamilyCreate.NewModelCurve(arc0, SketchPlane.Create(formdoc, staplane));
// //Plane endplane = Plane.CreateByNormalAndOrigin((curve.GeometryCurve as HermiteSpline).Tangents[pts.Count - 1], curve.GeometryCurve.GetEndPoint(1));
// Plane endplane = Plane.CreateByNormalAndOrigin(curve.GeometryCurve.GetEndPoint(1), (curve.GeometryCurve as HermiteSpline).Tangents[pts.Count - 1]);
// //curve.GeometryCurve.ComputeDerivatives(0, true)
// Arc arc1 = Arc.Create(endplane, 3000 / 304.8, 0, 2 * Math.PI);
// ModelCurve mc0 = formdoc.FamilyCreate.NewModelCurve(arc1, SketchPlane.Create(formdoc, endplane));
// #endregion
// #region 生成参照及模型
// //取得截面模型线的参照
// ReferenceArray profile0 = new ReferenceArray();
// profile0.Append(mc.GeometryCurve.Reference);
// ReferenceArray profile1 = new ReferenceArray();
// profile1.Append(mc0.GeometryCurve.Reference);
// //作为轮廓
// ReferenceArrayArray profiles = new ReferenceArrayArray();
// profiles.Append(profile0);
// profiles.Append(profile1);
// //取得路径曲线的参照
// ReferenceArray path = new ReferenceArray();
// path.Append(curve.GeometryCurve.Reference);
// //var s = formdoc.FamilyCreate.NewSweptBlendForm(true, path, profiles);
// var s = formdoc.FamilyCreate.NewSweptBlendForm(true, path, profiles);
// if (formdoc.IsFamilyDocument)
// {
// FamilyManager fm = formdoc.FamilyManager;
// FamilyType cft = fm.NewType(formname);
// cft = fm.CurrentType;
// }
// #endregion
// tr.Commit();
// LoadAndCreateInstance(formname);
// SetProjectPosition(projectPt);
//}
///// <param name="name"></param>
//public void LoadAndCreateInstance(string name)
//{
// Transaction trans = new Transaction(formdoc, "Excm");
// using (TransactionGroup tg = new TransactionGroup(doc, "创建路面"))
// {
// if (tg.Start() == TransactionStatus.Started)
// {
// LoadOpions lo = new LoadOpions();
// Family fa = formdoc.LoadFamily(doc);
// formdoc.CloseTrigger(false);
// trans = new Transaction(doc, "Change Family Name");
// trans.Start();
// fa.Name = name;
// FilteredElementCollector col = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol));
// FamilySymbol familySymbol = null;
// foreach (FamilySymbol fs in col)
// {
// if (fs.Name == name)
// {
// familySymbol = fs;
// }
// }
// familySymbol.Activate();
// Autodesk.Revit.DB.View v = doc.ActiveView;
// StructuralType stNon = StructuralType.NonStructural;
// FamilyInstance instance = doc.Create.NewFamilyInstance(new XYZ(), familySymbol, stNon);
// trans.Commit();
// trans.Dispose();
// tg.Assimilate();
// }
// else
// {
// tg.RollBack();
// }
// };
//}
//private ReferenceArrayArray Getprofiles(CurveByPoints curve, Region reg)
//{
// Document revitDoc = uiApplication.Application.OpenDocumentFile(reg.FilePathStart);
// FilteredElementCollector modelCurveCollector = new FilteredElementCollector(revitDoc);
// ErrorModels<ModelCurve> modelCurveList =
// modelCurveCollector.OfCollector(BuiltInCategory.OST_Lines).OfClass(typeof(CurveElement)).ToList()
// .ConvertAll(x => x as ModelCurve);
// ReferenceArray profile = new ReferenceArray();
// ReferenceArrayArray profiles = new ReferenceArrayArray();
// IList<XYZ> tangents = (curve.GeometryCurve as HermiteSpline).Tangents;
// for (int i = 0; i < tangents.Count; i = i + 4)
// {
// //为了求出X轴的单位向量
// XYZ horizonNor = new XYZ(tangents[i].X, tangents[i].Y, 0);
// XYZ orign = curve.GeometryCurve.Evaluate(i * 1000 / 304.8, false);
// //curve在xy平面上的投影某点的工作平面
// //Plane horiCurPl = Plane.CreateByNormalAndOrigin(horizonNor, orign);
// //XYZ xVect = horiCurPl.XVec;
// //叉乘求出X轴单位向量
// XYZ xAxis = horizonNor.CrossProduct(new XYZ(0, 0, 1)).Normalize();
// //在curve上的工作平面
// Plane pl = Plane.CreateByNormalAndOrigin(tangents[i], orign);
// SketchPlane skp = SketchPlane.Create(doc, pl);
// //XYZ xVect = pl.XVec;//z=0
// //求出curve上某点工作平面的y向量
// XYZ yAxis = xAxis.CrossProduct(tangents[i]).Normalize();//z>0
// if (yAxis.Z < 0)
// {
// //xVect = horiCurPl.XVec.Negate();
// xAxis = xAxis.Negate();
// yAxis = yAxis.Negate();
// }
// foreach (ModelCurve c in modelCurveList)
// {
// if (c.GetType() == typeof(ModelLine))
// {
// ModelLine ml = (ModelLine)c;
// var startpt = ml.GeometryCurve.GetEndPoint(0);
// var endpt = ml.GeometryCurve.GetEndPoint(1);
// XYZ stapt = (startpt.X * xAxis) + orign + startpt.Y * yAxis;
// XYZ enpt = endpt.X * xAxis + orign + endpt.Y * yAxis;
// Autodesk.Revit.DB.Line l = Autodesk.Revit.DB.Line.CreateBound(stapt, enpt);
// ModelCurve m_l = doc.FamilyCreate.NewModelCurve(l, skp);
// profile.Append(m_l.GeometryCurve.Reference);
// }
// else if (c.GetType() == typeof(ModelArc))
// {
// ModelArc marc = (ModelArc)c;
// Arc ar = (Arc)marc.GeometryCurve;
// //XYZ startpt = marc.GeometryCurve.GetEndPoint(0);
// //XYZ centpt = marc.GeometryCurve.Evaluate(0.5, true);
// //XYZ endpt = marc.GeometryCurve.GetEndPoint(1);
// Arc arc;
// if (marc.GeometryCurve.IsBound)
// {
// XYZ startpt = ar.GetEndPoint(0);
// XYZ centpt = ar.Evaluate(0.5, true);
// XYZ endpt = ar.GetEndPoint(1);
// XYZ stapt = startpt.X * xAxis + orign + startpt.Y * yAxis;
// XYZ cept = centpt.X * xAxis + orign + centpt.Y * yAxis;
// XYZ enpt = endpt.X * xAxis + orign + endpt.Y * yAxis;
// arc = Arc.Create(stapt, enpt, cept);
// }
// else
// {
// XYZ center = ar.HorizontallyCenter.X * xAxis + orign + ar.HorizontallyCenter.Y * yAxis;
// arc = Arc.Create(center, ar.Radius, 0, 2 * Math.PI, xAxis, yAxis);
// //arc = Arc.Create(pl, ar.Radius, 0, 2 * Math.PI);
// }
// ModelCurve m_c = doc.FamilyCreate.NewModelCurve(arc, skp);
// profile.Append(m_c.GeometryCurve.Reference);
// }
// }
// profiles.Append(profile);
// }
// return profiles;
//}
#endregion
}