自己来结一下帖子,直接上代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.UI.Events;
using Autodesk.Revit.DB.Events;
using Autodesk.Revit;
using System.Drawing;
using Rectangle = System.Windows.Shapes.Rectangle;
namespace Bridge_design
{
/// <summary>
/// Cross_section_size.xaml 的交互逻辑
/// </summary>
public partial class Cross_section_size : System.Windows.Window
{
ExternalCommandData m_revit;
public Cross_section_size(ExternalCommandData revit)
{
InitializeComponent();
m_revit = revit;
InitTextbox();
InitCanvas();
}
private void InitCanvas()
{
double a1 = Convert.ToDouble(aa1.Text);
double a2 = Convert.ToDouble(aa2.Text);
double a3 = Convert.ToDouble(aa3.Text);
double a4 = Convert.ToDouble(aa4.Text);
double a5 = Convert.ToDouble(aa5.Text);
double a6 = Convert.ToDouble(aa6.Text);
double a7 = Convert.ToDouble(aa7.Text);
double a8 = Convert.ToDouble(aa8.Text);
double a9 = Convert.ToDouble(aa9.Text);
double b1 = Convert.ToDouble(bb1.Text);
double b2 = Convert.ToDouble(bb2.Text);
double b3 = Convert.ToDouble(bb3.Text);
double b4 = Convert.ToDouble(bb4.Text);
double b5 = Convert.ToDouble(bb5.Text);
double b6 = Convert.ToDouble(bb6.Text);
DrawingLine(new System.Windows.Point(0, 0), new System.Windows.Point(2 * a1 + 2 * a2 + 2 * a3 + a5, 0));
DrawingLine(new System.Windows.Point(0, b1), new System.Windows.Point(a1, b1));
DrawingLine(new System.Windows.Point(a1, b1), new System.Windows.Point(a1 + a2, b1 + b2));
DrawingLine(new System.Windows.Point(a1 + a2, b1 + b2), new System.Windows.Point(a6, b1 + b2 + b3 + b4 + b5));
DrawingLine(new System.Windows.Point(a6, b1 + b2 + b3 + b4 + b5), new System.Windows.Point(a6 + 2 * a7 + a9, b1 + b2 + b3 + b4 + b5));
DrawingLine(new System.Windows.Point(a6 + 2 * a7 + a9, b1 + b2 + b3 + b4 + b5), new System.Windows.Point(a1 + a2 + 2 * a3 + a5, b1 + b2));
DrawingLine(new System.Windows.Point(a1 + a2 + 2 * a3 + a5, b1 + b2), new System.Windows.Point(a1 + 2 * a2 + 2 * a3 + a5, b1));
DrawingLine(new System.Windows.Point(a1 + 2 * a2 + 2 * a3 + a5, b1), new System.Windows.Point(2 * a1 + 2 * a2 + 2 * a3 + a5, b1));
DrawingLine(new System.Windows.Point(a1 + a2 + a3, b1), new System.Windows.Point(a1 + a2 + a3 + a5, b1));
DrawingLine(new System.Windows.Point(a1 + a2 + a3 + a5, b1), new System.Windows.Point(a1 + a2 + a3 + a4 + a5, b1 + b2));
DrawingLine(new System.Windows.Point(a1 + a2 + a3 + a4 + a5, b1 + b2), new System.Windows.Point(a6 + a7 + a8 + a9, b1 + b2 + b3));
DrawingLine(new System.Windows.Point(a6 + a7 + a9, b1 + b2 + b3 + b4), new System.Windows.Point(a6 + a7, b1 + b2 + b3 + b4));
DrawingLine(new System.Windows.Point(a6 + a7 - a8, b1 + b2 + b3), new System.Windows.Point(a1 + a2 + a3 - a4, b1 + b6));
DrawingLine(new System.Windows.Point(a1 + a2 + a3 - a4, b1 + b6), new System.Windows.Point(a1 + a2 + a3, b1));
if (b4 == 0)
{
}
else
{
DrawingLine(new System.Windows.Point(a6 + a7 + a8 + a9, b1 + b2 + b3), new System.Windows.Point(a6 + a7 + a9, b1 + b2 + b3 + b4));
DrawingLine(new System.Windows.Point(a6 + a7, b1 + b2 + b3 + b4), new System.Windows.Point(a6 + a7 - a8, b1 + b2 + b3));
}
}
private void InitTextbox()
{
this.aa1.Text = 17.5.ToString();
this.aa2.Text = 19.2.ToString();
this.aa3.Text = 33.ToString();
this.aa4.Text = 15.ToString();
this.aa5.Text = 113.ToString();
this.aa6.Text = 67.ToString();
this.aa7.Text = 28.ToString();
this.aa8.Text = 16.ToString();
this.aa9.Text = 51.ToString();
this.bb1.Text = 15.ToString();
this.bb2.Text = 6.5.ToString();
this.bb3.Text = 110.ToString();
this.bb4.Text = 9.5.ToString();
this.bb5.Text = 18.ToString();
this.bb6.Text = 7.ToString();
this.aa1.TextChanged += Aa1_TextChanged;
}
private void Aa1_TextChanged(object sender, TextChangedEventArgs args)
{
mainPane1.Children.Clear();
System.Windows.Controls.TextBox textBox = sender as System.Windows.Controls.TextBox;
if (textBox == null)
return;
double x1 = Convert.ToDouble(textBox.Text);
double x2 = Convert.ToDouble(aa2.Text);
double x3 = Convert.ToDouble(aa3.Text);
double x4 = Convert.ToDouble(aa4.Text);
double x5 = Convert.ToDouble(aa5.Text);
double x6 = Convert.ToDouble(aa6.Text);
double x7 = Convert.ToDouble(aa7.Text);
double x8 = Convert.ToDouble(aa8.Text);
double x9 = Convert.ToDouble(aa9.Text);
double y1 = Convert.ToDouble(bb1.Text);
double y2 = Convert.ToDouble(bb2.Text);
double y3 = Convert.ToDouble(bb3.Text);
double y4 = Convert.ToDouble(bb4.Text);
double y5 = Convert.ToDouble(bb5.Text);
double y6 = Convert.ToDouble(bb6.Text);
DrawingLine(new System.Windows.Point(0, 0), new System.Windows.Point(2 * x1 + 2 * x2 + 2 * x3 + x5, 0));
DrawingLine(new System.Windows.Point(0, y1), new System.Windows.Point(x1, y1));
DrawingLine(new System.Windows.Point(x1, y1), new System.Windows.Point(x1 + x2, y1 + y2));
DrawingLine(new System.Windows.Point(x1 + x2, y1 + y2), new System.Windows.Point(x6, y1 + y2 + y3 + y4 + y5));
DrawingLine(new System.Windows.Point(x6, y1 + y2 + y3 + y4 + y5), new System.Windows.Point(x6 + 2 * x7 + x9, y1 + y2 + y3 + y4 + y5));
DrawingLine(new System.Windows.Point(x6 + 2 * x7 + x9, y1 + y2 + y3 + y4 + y5), new System.Windows.Point(x1 + x2 + 2 * x3 + x5, y1 + y2));
DrawingLine(new System.Windows.Point(x1 + x2 + 2 * x3 + x5, y1 + y2), new System.Windows.Point(x1 + 2 * x2 + 2 * x3 + x5, y1));
DrawingLine(new System.Windows.Point(x1 + 2 * x2 + 2 * x3 + x5, y1), new System.Windows.Point(2 * x1 + 2 * x2 + 2 * x3 + x5, y1));
DrawingLine(new System.Windows.Point(x1 + x2 + x3, y1), new System.Windows.Point(x1 + x2 + x3 + x5, y1));
DrawingLine(new System.Windows.Point(x1 + x2 + x3 + x5, y1), new System.Windows.Point(x1 + x2 + x3 + x4 + x5, y1 + y2));
DrawingLine(new System.Windows.Point(x1 + x2 + x3 + x4 + x5, y1 + y2), new System.Windows.Point(x6 + x7 + x8 + x9, y1 + y2 + y3));
DrawingLine(new System.Windows.Point(x6 + x7 + x9, y1 + y2 + y3 + y4), new System.Windows.Point(x6 + x7, y1 + y2 + y3 + y4));
DrawingLine(new System.Windows.Point(x6 + x7 - x8, y1 + y2 + y3), new System.Windows.Point(x1 + x2 + x3 - x4, y1 + y6));
DrawingLine(new System.Windows.Point(x1 + x2 + x3 - x4, y1 + y6), new System.Windows.Point(x1 + x2 + x3, y1));
if (y4 == 0)
{
}
else
{
DrawingLine(new System.Windows.Point(x6 + x7 + x8 + x9, y1 + y2 + y3), new System.Windows.Point(x6 + x7 + x9, y1 + y2 + y3 + y4));
DrawingLine(new System.Windows.Point(x6 + x7, y1 + y2 + y3 + y4), new System.Windows.Point(x6 + x7 - x8, y1 + y2 + y3));
}
}
protected void DrawingLine(System.Windows.Point startPt, System.Windows.Point endPt)
{
LineGeometry myLineGeometry = new LineGeometry();
myLineGeometry.StartPoint = startPt;
myLineGeometry.EndPoint = endPt;
Path myPath = new Path();
myPath.Stroke = System.Windows.Media.Brushes.Black;
myPath.StrokeThickness = 1;
myPath.Data = myLineGeometry;
this.mainPane1.Children.Add(myPath);
}
}
}
我的程序是再Revit中运行的,结果就是实时修改画线。