added Revit 2022 SDK minus except *rvt and *rfa

This commit is contained in:
Jeremy Tammik
2021-04-20 11:36:21 +02:00
parent 1133a82dc5
commit 7e327986e8
3034 changed files with 1245318 additions and 0 deletions
+71
View File
@@ -0,0 +1,71 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace Revit.SDK.Samples.Truss.CS
{
/// <summary>
/// The entrance of this example, implements the Execute method of IExternalCommand
/// </summary>
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
[Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)]
public class Command : IExternalCommand
{
#region IExternalCommand Members Implementation
///<summary>
/// Implement this method as an external command for Revit.
/// </summary>
/// <param name="commandData">An object that is passed to the external application
/// which contains data related to the command,
/// such as the application object and active view.</param>
/// <param name="message">A message that can be set by the external application
/// which will be displayed if a failure or cancellation is returned by
/// the external command.</param>
/// <param name="elements">A set of elements to which the external application
/// can add elements that are to be highlighted in case of failure or cancellation.</param>
/// <returns>Return the status of the external command.
/// A result of Succeeded means that the API external method functioned as expected.
/// Cancelled can be used to signify that the user cancelled the external operation
/// at some point. Failure should be returned if the application is unable to proceed with
/// the operation.</returns>
public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,
ref string message, Autodesk.Revit.DB.ElementSet elements)
{
TrussForm trussForm = new TrussForm(commandData);
// The form is created successfully
if (null != trussForm && false == trussForm.IsDisposed)
{
trussForm.ShowDialog();
}
return Autodesk.Revit.UI.Result.Succeeded;
}
#endregion
}
}
+100
View File
@@ -0,0 +1,100 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Collections;
namespace Revit.SDK.Samples.Truss.CS
{
/// <summary>
/// tool used to draw line
/// </summary>
class LineTool
{
#region class member variables
ArrayList m_Points; //record all the points draw by this tool
Point m_movePoint; //record the coordinate of location where mouse just moved to.
#endregion
/// <summary>
/// Get all the points of this tool
/// </summary>
public ArrayList Points
{
get
{
return m_Points;
}
set
{
m_Points = value;
}
}
/// <summary>
///Get coordinate of location where mouse just moved to.
/// </summary>
public Point MovePoint
{
get
{
return m_movePoint;
}
set
{
m_movePoint = value;
}
}
/// <summary>
/// default constructor
/// </summary>
public LineTool()
{
m_Points = new ArrayList();
}
/// <summary>
/// draw the stored lines
/// </summary>
/// <param name="graphics">Graphics object, used to draw geometry</param>
/// <param name="pen">Pen which used to draw lines</param>
public void Draw2D(Graphics graphics, Pen pen)
{
for (int i = 0; i < m_Points.Count - 1; i++)
{
graphics.DrawLine(pen, (Point)m_Points[i], (Point)m_Points[i+1]);
}
//draw the moving point
if (!m_movePoint.IsEmpty)
{
if (m_Points.Count >= 1)
{
graphics.DrawLine(pen, (Point)m_Points[m_Points.Count - 1], m_movePoint);
}
}
}
}
}
+462
View File
@@ -0,0 +1,462 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.Revit.DB;
namespace Revit.SDK.Samples.Truss.CS
{
/// <summary>
/// Vector4 is a homogeneous coordinate class used to store vector
/// and contain method to handle the vector
/// </summary>
public class Vector4
{
#region Class member variables and properties
private double m_x;
private double m_y;
private double m_z;
private double m_w = 1.0f;
/// <summary>
/// X property to get/set x value of Vector4
/// </summary>
public double X
{
get
{
return m_x;
}
set
{
m_x = value;
}
}
/// <summary>
/// Y property to get/set y value of Vector4
/// </summary>
public double Y
{
get
{
return m_y;
}
set
{
m_y = value;
}
}
/// <summary>
/// Z property to get/set z value of Vector4
/// </summary>
public double Z
{
get
{
return m_z;
}
set
{
m_z = value;
}
}
/// <summary>
/// W property to get/set fourth value of Vector4
/// </summary>
public double W
{
get
{
return m_w;
}
set
{
m_w = value;
}
}
#endregion
/// <summary>
/// constructor
/// </summary>
public Vector4(double x, double y, double z)
{
this.X = x; this.Y = y; this.Z = z;
}
/// <summary>
/// constructor, transfer Autodesk.Revit.DB.XYZ to vector
/// </summary>
/// <param name="v">Autodesk.Revit.DB.XYZ structure which needs to be transferred</param>
public Vector4(Autodesk.Revit.DB.XYZ v)
{
this.X = (double)v.X; this.Y = (double)v.Y; this.Z = (double)v.Z;
}
/// <summary>
/// adds two vectors
/// </summary>
/// <param name="va">first vector</param>
/// <param name="vb">second vector</param>
public static Vector4 operator+ (Vector4 va, Vector4 vb)
{
return new Vector4(va.X + vb.X, va.Y + vb.Y, va.Z + vb.Z);
}
/// <summary>
/// subtracts two vectors
/// </summary>
/// <param name="va">first vector</param>
/// <param name="vb">second vector</param>
/// <returns>subtraction of two vectors</returns>
public static Vector4 operator- (Vector4 va, Vector4 vb)
{
return new Vector4(va.X - vb.X, va.Y - vb.Y, va.Z - vb.Z);
}
/// <summary>
/// multiplies a vector by a doubling type value
/// </summary>
/// <param name="v">vector</param>
/// <param name="factor">multiplier of doubling type</param>
/// <returns> the result vector </returns>
public static Vector4 operator* (Vector4 v,double factor)
{
return new Vector4(v.X * factor, v.Y * factor, v.Z * factor);
}
/// <summary>
/// divides vector by a double type value
/// </summary>
/// <param name="v">vector</param>
/// <param name="factor">doubling type value</param>
/// <returns> vector divided by a doubling type value </returns>
public static Vector4 operator /(Vector4 v, double factor)
{
return new Vector4(v.X / factor, v.Y / factor, v.Z / factor);
}
/// <summary>
/// dot multiply vector
/// </summary>
/// <param name="v"> the result vector </param>
public double DotProduct(Vector4 v)
{
return (this.X * v.X + this.Y * v.Y + this.Z * v.Z);
}
/// <summary>
/// get normal vector of plane contains two vectors
/// </summary>
/// <param name="v">second vector</param>
/// <returns> normal vector of two vectors</returns>
public Vector4 CrossProduct(Vector4 v)
{
return new Vector4(this.Y * v.Z - this.Z * v.Y,this.Z * v.X
- this.X * v.Z,this.X * v.Y - this.Y * v.X);
}
/// <summary>
/// dot multiply two vectors
/// </summary>
/// <param name="va">first vector</param>
/// <param name="vb">second vector</param>
public static double DotProduct(Vector4 va, Vector4 vb)
{
return (va.X * vb.X + va.Y * vb.Y + va.Z * vb.Z);
}
/// <summary>
/// get normal vector of two vectors
/// </summary>
/// <param name="va">first vector</param>
/// <param name="vb">second vector</param>
/// <returns> normal vector of two vectors </returns>
public static Vector4 CrossProduct(Vector4 va, Vector4 vb)
{
return new Vector4(va.Y * vb.Z - va.Z * vb.Y, va.Z * vb.X
- va.X * vb.Z, va.X * vb.Y - va.Y * vb.X);
}
/// <summary>
/// get unit vector
/// </summary>
public void Normalize()
{
double length = Length();
if(length == 0)
{
length = 1;
}
this.X /= length;
this.Y /= length;
this.Z /= length;
}
/// <summary>
/// calculate the length of vector
/// </summary>
public double Length()
{
return (double)Math.Sqrt(this.X * this.X + this.Y * this.Y + this.Z * this.Z);
}
};
/// <summary>
/// Matrix used to transform between ucs coordinate and world coordinate.
/// </summary>
public class Matrix4
{
#region MatrixType
/// <summary>
/// Matrix Type Enum use to define function of matrix
/// </summary>
public enum MatrixType
{
/// <summary>
/// matrix use to rotate
/// </summary>
Rotation,
/// <summary>
/// matrix used to Translation
/// </summary>
Translation,
/// <summary>
/// matrix used to Scale
/// </summary>
Scale,
/// <summary>
/// matrix used to Rotation and Translation
/// </summary>
RotationAndTranslation,
/// <summary>
/// normal matrix
/// </summary>
Normal
};
private double[,] m_matrix = new double[4,4]; // an array stores the matrix
private MatrixType m_type; //type of matrix
#endregion
/// <summary>
/// default constructor
/// </summary>
public Matrix4()
{
m_type = MatrixType.Normal;
Identity();
}
/// <summary>
/// ctor,rotation matrix,origin at (0,0,0)
/// </summary>
/// <param name="xAxis">identity of x axis</param>
/// <param name="yAxis">identity of y axis</param>
/// <param name="zAxis">identity of z axis</param>
public Matrix4(Vector4 xAxis,Vector4 yAxis, Vector4 zAxis)
{
m_type = MatrixType.Rotation;
Identity();
m_matrix[0, 0] = xAxis.X; m_matrix[0, 1] = xAxis.Y; m_matrix[0, 2] = xAxis.Z;
m_matrix[1, 0] = yAxis.X; m_matrix[1, 1] = yAxis.Y; m_matrix[1, 2] = yAxis.Z;
m_matrix[2, 0] = zAxis.X; m_matrix[2, 1] = zAxis.Y; m_matrix[2, 2] = zAxis.Z;
}
/// <summary>
/// ctor,translation matrix.
/// </summary>
/// <param name="origin">origin of ucs in world coordinate</param>
public Matrix4(Vector4 origin)
{
m_type = MatrixType.Translation;
Identity();
m_matrix[3, 0] = origin.X; m_matrix[3, 1] = origin.Y; m_matrix[3, 2] = origin.Z;
}
/// <summary>
/// rotation and translation matrix constructor
/// </summary>
/// <param name="xAxis">x Axis</param>
/// <param name="yAxis">y Axis</param>
/// <param name="zAxis">z Axis</param>
/// <param name="origin">origin</param>
public Matrix4(Vector4 xAxis, Vector4 yAxis, Vector4 zAxis, Vector4 origin)
{
m_type = MatrixType.RotationAndTranslation;
Identity();
m_matrix[0, 0] = xAxis.X; m_matrix[0, 1] = xAxis.Y; m_matrix[0, 2] = xAxis.Z;
m_matrix[1, 0] = yAxis.X; m_matrix[1, 1] = yAxis.Y; m_matrix[1, 2] = yAxis.Z;
m_matrix[2, 0] = zAxis.X; m_matrix[2, 1] = zAxis.Y; m_matrix[2, 2] = zAxis.Z;
m_matrix[3, 0] = origin.X; m_matrix[3, 1] = origin.Y; m_matrix[3, 2] = origin.Z;
}
/// <summary>
/// scale matrix constructor
/// </summary>
/// <param name="scale">scale factor</param>
public Matrix4(double scale)
{
m_type = MatrixType.Scale;
Identity();
m_matrix[0, 0] = scale;
m_matrix[1, 1] = scale;
m_matrix[2, 2] = scale;
}
/// <summary>
/// indexer of matrix
/// </summary>
/// <param name="row">row number</param>
/// <param name="column">column number</param>
/// <returns></returns>
public double this[int row, int column]
{
get
{
return this.m_matrix[row, column];
}
set
{
this.m_matrix[row, column] = value;
}
}
/// <summary>
/// Identity matrix
/// </summary>
public void Identity()
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
this.m_matrix[i, j] = 0.0f;
}
}
this.m_matrix[0, 0] = 1.0f;
this.m_matrix[1, 1] = 1.0f;
this.m_matrix[2, 2] = 1.0f;
this.m_matrix[3, 3] = 1.0f;
}
/// <summary>
/// multiply matrix left and right
/// </summary>
/// <param name="left">left matrix</param>
/// <param name="right">right matrix</param>
/// <returns></returns>
public static Matrix4 Multiply(Matrix4 left, Matrix4 right)
{
Matrix4 result = new Matrix4();
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
result[i, j] = left[i, 0] * right[0, j] + left[i, 1] * right[1, j]
+ left[i, 2] * right[2, j] + left[i, 3] * right[3, j];
}
}
return result;
}
/// <summary>
/// transform point using this matrix
/// </summary>
/// <param name="point">point to be transformed</param>
/// <returns>transform result</returns>
public Vector4 Transform(Vector4 point)
{
return new Vector4(point.X * this[0, 0] + point.Y * this[1, 0]
+ point.Z * this[2, 0]+ point.W * this[3, 0],
point.X * this[0, 1] + point.Y * this[1, 1]
+ point.Z * this[2, 1]+ point.W * this[3, 1],
point.X * this[0, 2] + point.Y * this[1, 2]
+ point.Z * this[2, 2]+ point.W * this[3, 2]);
}
/// <summary>
/// if m_matrix is a rotation matrix,this method can get the rotation inverse matrix.
/// </summary>
/// <returns>inverse of rotation matrix</returns>
public Matrix4 RotationInverse()
{
return new Matrix4(new Vector4(this[0, 0], this[1, 0], this[2, 0]),
new Vector4(this[0, 1], this[1, 1], this[2, 1]),
new Vector4(this[0, 2], this[1, 2], this[2, 2]));
}
/// <summary>
/// if this m_matrix is a translation matrix,
/// this method can get the translation inverse matrix.
/// </summary>
/// <returns>inverse of translation matrix</returns>
public Matrix4 TranslationInverse()
{
return new Matrix4(new Vector4(-this[3, 0], -this[3, 1], -this[3, 2]));
}
/// <summary>
/// get inverse matrix
/// </summary>
/// <returns>inverse matrix</returns>
public Matrix4 Inverse()
{
switch(m_type)
{
case MatrixType.Rotation:
return RotationInverse();
case MatrixType.Translation:
return TranslationInverse();
case MatrixType.RotationAndTranslation:
return Multiply(TranslationInverse(),RotationInverse());
case MatrixType.Scale:
return ScaleInverse();
case MatrixType.Normal:
return new Matrix4();
default: return null;
}
}
/// <summary>
/// if m_matrix is a scale matrix,this method can get the scale inverse matrix.
/// </summary>
/// <returns>inverse of scale matrix</returns>
public Matrix4 ScaleInverse()
{
return new Matrix4(1 / m_matrix[0,0]);
}
};
}
@@ -0,0 +1,56 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Truss")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Truss")]
[assembly: AssemblyCopyright("Copyright © Autodesk, Inc. 2009")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("fc5a3d16-422f-48ee-bb05-7ec2be27032f")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
+63
View File
@@ -0,0 +1,63 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Truss.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Truss.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
Binary file not shown.
+13
View File
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
<AddIn Type="Command">
<Assembly>Truss.dll</Assembly>
<ClientId>3a049691-424b-4a35-9dcb-b2c295ee033f</ClientId>
<FullClassName>Revit.SDK.Samples.Truss.CS.Command</FullClassName>
<Text>Truss</Text>
<Description>Create truss, edit profile and truss member of new created truss.</Description>
<VisibilityMode>AlwaysVisible</VisibilityMode>
<VendorId>ADSK</VendorId>
<VendorDescription>Autodesk, www.autodesk.com</VendorDescription>
</AddIn>
</RevitAddIns>
+110
View File
@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{1AB26248-7122-4FE0-9B02-2C14013B2CF2}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Truss</RootNamespace>
<AssemblyName>Truss</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup>
<RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Command.cs" />
<Compile Include="LineTool.cs" />
<Compile Include="MathTools.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="TrussForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="TrussForm.Designer.cs">
<DependentUpon>TrussForm.cs</DependentUpon>
</Compile>
<Compile Include="TrussGeometry.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
<SubType>Designer</SubType>
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="TrussForm.resx">
<SubType>Designer</SubType>
<DependentUpon>TrussForm.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(SolutionDir)VSProps\SDKSamples.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<PropertyGroup>
<PostBuildEvent>set FILEFORSAMPLEREG="$(SolutionDir)..\..\..\..\Regression\API\SDKSamples\UpdateSampleDllForRegression.pl"
if exist %25FILEFORSAMPLEREG%25 perl %25FILEFORSAMPLEREG%25 $(ProjectExt) "$(ProjectPath)" "$(TargetPath)" "$(SolutionDir)"</PostBuildEvent>
</PropertyGroup>
<PropertyGroup>
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
</PropertyGroup>
</Project>
+374
View File
@@ -0,0 +1,374 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
namespace Revit.SDK.Samples.Truss.CS
{
/// <summary>
/// window form contains one three picture box to show the
/// profile of truss geometry and profile and tabControl.
/// User can create truss, edit profile of truss and change type of truss members.
/// </summary>
partial class TrussForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.TrussTypeComboBox = new System.Windows.Forms.ComboBox();
this.TrussGraphicsTabControl = new System.Windows.Forms.TabControl();
this.ViewTabPage = new System.Windows.Forms.TabPage();
this.Notelabel = new System.Windows.Forms.Label();
this.ViewComboBox = new System.Windows.Forms.ComboBox();
this.ViewLabel = new System.Windows.Forms.Label();
this.CreateButton = new System.Windows.Forms.Button();
this.TrussMembersTabPage = new System.Windows.Forms.TabPage();
this.BeamTypeLabel = new System.Windows.Forms.Label();
this.ChangeBeamTypeButton = new System.Windows.Forms.Button();
this.BeamTypeComboBox = new System.Windows.Forms.ComboBox();
this.TrussMembersPictureBox = new System.Windows.Forms.PictureBox();
this.ProfileEditTabPage = new System.Windows.Forms.TabPage();
this.CleanChordbutton = new System.Windows.Forms.Button();
this.BottomChordButton = new System.Windows.Forms.Button();
this.TopChordButton = new System.Windows.Forms.Button();
this.UpdateButton = new System.Windows.Forms.Button();
this.RestoreButton = new System.Windows.Forms.Button();
this.ProfileEditPictureBox = new System.Windows.Forms.PictureBox();
this.TrussTypeLabel = new System.Windows.Forms.Label();
this.CloseButton = new System.Windows.Forms.Button();
this.TrussGraphicsTabControl.SuspendLayout();
this.ViewTabPage.SuspendLayout();
this.TrussMembersTabPage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.TrussMembersPictureBox)).BeginInit();
this.ProfileEditTabPage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.ProfileEditPictureBox)).BeginInit();
this.SuspendLayout();
//
// TrussTypeComboBox
//
this.TrussTypeComboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.TrussTypeComboBox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.TrussTypeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.TrussTypeComboBox.FormattingEnabled = true;
this.TrussTypeComboBox.Location = new System.Drawing.Point(84, 6);
this.TrussTypeComboBox.Name = "TrussTypeComboBox";
this.TrussTypeComboBox.Size = new System.Drawing.Size(212, 21);
this.TrussTypeComboBox.TabIndex = 1;
this.TrussTypeComboBox.SelectedIndexChanged += new System.EventHandler(this.TrussTypeComboBox_SelectedIndexChanged);
//
// TrussGraphicsTabControl
//
this.TrussGraphicsTabControl.Controls.Add(this.ViewTabPage);
this.TrussGraphicsTabControl.Controls.Add(this.TrussMembersTabPage);
this.TrussGraphicsTabControl.Controls.Add(this.ProfileEditTabPage);
this.TrussGraphicsTabControl.Location = new System.Drawing.Point(12, 41);
this.TrussGraphicsTabControl.Name = "TrussGraphicsTabControl";
this.TrussGraphicsTabControl.SelectedIndex = 0;
this.TrussGraphicsTabControl.Size = new System.Drawing.Size(404, 343);
this.TrussGraphicsTabControl.TabIndex = 2;
this.TrussGraphicsTabControl.Selecting += new System.Windows.Forms.TabControlCancelEventHandler(this.TrussGraphicsTabControl_Selecting);
this.TrussGraphicsTabControl.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TrussGraphicsTabControl_KeyPress);
//
// ViewTabPage
//
this.ViewTabPage.Controls.Add(this.Notelabel);
this.ViewTabPage.Controls.Add(this.ViewComboBox);
this.ViewTabPage.Controls.Add(this.ViewLabel);
this.ViewTabPage.Controls.Add(this.CreateButton);
this.ViewTabPage.Location = new System.Drawing.Point(4, 22);
this.ViewTabPage.Name = "ViewTabPage";
this.ViewTabPage.Padding = new System.Windows.Forms.Padding(3);
this.ViewTabPage.Size = new System.Drawing.Size(396, 317);
this.ViewTabPage.TabIndex = 0;
this.ViewTabPage.Text = "Create Truss";
this.ViewTabPage.UseVisualStyleBackColor = true;
//
// Notelabel
//
this.Notelabel.AutoSize = true;
this.Notelabel.Location = new System.Drawing.Point(6, 17);
this.Notelabel.Name = "Notelabel";
this.Notelabel.Size = new System.Drawing.Size(155, 13);
this.Notelabel.TabIndex = 5;
this.Notelabel.Text = "Select a View to build truss on :";
//
// ViewComboBox
//
this.ViewComboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.ViewComboBox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.ViewComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.ViewComboBox.FormattingEnabled = true;
this.ViewComboBox.Location = new System.Drawing.Point(48, 57);
this.ViewComboBox.Name = "ViewComboBox";
this.ViewComboBox.Size = new System.Drawing.Size(236, 21);
this.ViewComboBox.TabIndex = 4;
this.ViewComboBox.SelectedIndexChanged += new System.EventHandler(this.ViewComboBox_SelectedIndexChanged);
//
// ViewLabel
//
this.ViewLabel.AutoSize = true;
this.ViewLabel.Location = new System.Drawing.Point(6, 60);
this.ViewLabel.Name = "ViewLabel";
this.ViewLabel.Size = new System.Drawing.Size(36, 13);
this.ViewLabel.TabIndex = 3;
this.ViewLabel.Text = "View :";
//
// CreateButton
//
this.CreateButton.Location = new System.Drawing.Point(301, 55);
this.CreateButton.Name = "CreateButton";
this.CreateButton.Size = new System.Drawing.Size(80, 23);
this.CreateButton.TabIndex = 2;
this.CreateButton.Text = "&Create Truss";
this.CreateButton.UseVisualStyleBackColor = true;
this.CreateButton.Click += new System.EventHandler(this.CreateButton_Click);
//
// TrussMembersTabPage
//
this.TrussMembersTabPage.Controls.Add(this.BeamTypeLabel);
this.TrussMembersTabPage.Controls.Add(this.ChangeBeamTypeButton);
this.TrussMembersTabPage.Controls.Add(this.BeamTypeComboBox);
this.TrussMembersTabPage.Controls.Add(this.TrussMembersPictureBox);
this.TrussMembersTabPage.Location = new System.Drawing.Point(4, 22);
this.TrussMembersTabPage.Name = "TrussMembersTabPage";
this.TrussMembersTabPage.Padding = new System.Windows.Forms.Padding(3);
this.TrussMembersTabPage.Size = new System.Drawing.Size(396, 317);
this.TrussMembersTabPage.TabIndex = 1;
this.TrussMembersTabPage.Text = "Truss Members";
this.TrussMembersTabPage.UseVisualStyleBackColor = true;
//
// BeamTypeLabel
//
this.BeamTypeLabel.AutoSize = true;
this.BeamTypeLabel.Location = new System.Drawing.Point(6, 291);
this.BeamTypeLabel.Name = "BeamTypeLabel";
this.BeamTypeLabel.Size = new System.Drawing.Size(67, 13);
this.BeamTypeLabel.TabIndex = 3;
this.BeamTypeLabel.Text = "Beam Type :";
//
// ChangeBeamTypeButton
//
this.ChangeBeamTypeButton.Enabled = false;
this.ChangeBeamTypeButton.Location = new System.Drawing.Point(309, 288);
this.ChangeBeamTypeButton.Name = "ChangeBeamTypeButton";
this.ChangeBeamTypeButton.Size = new System.Drawing.Size(81, 21);
this.ChangeBeamTypeButton.TabIndex = 2;
this.ChangeBeamTypeButton.Text = "Change Type";
this.ChangeBeamTypeButton.UseVisualStyleBackColor = true;
this.ChangeBeamTypeButton.Click += new System.EventHandler(this.ChangeBeamTypeButton_Click);
//
// BeamTypeComboBox
//
this.BeamTypeComboBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
this.BeamTypeComboBox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
this.BeamTypeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.BeamTypeComboBox.Enabled = false;
this.BeamTypeComboBox.FormattingEnabled = true;
this.BeamTypeComboBox.Location = new System.Drawing.Point(79, 288);
this.BeamTypeComboBox.Name = "BeamTypeComboBox";
this.BeamTypeComboBox.Size = new System.Drawing.Size(217, 21);
this.BeamTypeComboBox.TabIndex = 1;
this.BeamTypeComboBox.SelectedIndexChanged += new System.EventHandler(this.BeamTypeComboBox_SelectedIndexChanged);
//
// TrussMembersPictureBox
//
this.TrussMembersPictureBox.Location = new System.Drawing.Point(7, 7);
this.TrussMembersPictureBox.Name = "TrussMembersPictureBox";
this.TrussMembersPictureBox.Size = new System.Drawing.Size(384, 274);
this.TrussMembersPictureBox.TabIndex = 0;
this.TrussMembersPictureBox.TabStop = false;
this.TrussMembersPictureBox.MouseMove += new System.Windows.Forms.MouseEventHandler(this.TrussGeometryPictureBox_MouseMove);
this.TrussMembersPictureBox.Paint += new System.Windows.Forms.PaintEventHandler(this.TrussGeometryPictureBox_Paint);
this.TrussMembersPictureBox.MouseClick += new System.Windows.Forms.MouseEventHandler(this.TrussGeometryPictureBox_MouseClick);
//
// ProfileEditTabPage
//
this.ProfileEditTabPage.Controls.Add(this.CleanChordbutton);
this.ProfileEditTabPage.Controls.Add(this.BottomChordButton);
this.ProfileEditTabPage.Controls.Add(this.TopChordButton);
this.ProfileEditTabPage.Controls.Add(this.UpdateButton);
this.ProfileEditTabPage.Controls.Add(this.RestoreButton);
this.ProfileEditTabPage.Controls.Add(this.ProfileEditPictureBox);
this.ProfileEditTabPage.Location = new System.Drawing.Point(4, 22);
this.ProfileEditTabPage.Name = "ProfileEditTabPage";
this.ProfileEditTabPage.Size = new System.Drawing.Size(396, 317);
this.ProfileEditTabPage.TabIndex = 2;
this.ProfileEditTabPage.Text = "Profile Edit";
this.ProfileEditTabPage.UseVisualStyleBackColor = true;
//
// CleanChordbutton
//
this.CleanChordbutton.Location = new System.Drawing.Point(177, 286);
this.CleanChordbutton.Name = "CleanChordbutton";
this.CleanChordbutton.Size = new System.Drawing.Size(51, 23);
this.CleanChordbutton.TabIndex = 8;
this.CleanChordbutton.Text = "&Clean";
this.CleanChordbutton.UseVisualStyleBackColor = true;
this.CleanChordbutton.Click += new System.EventHandler(this.CleanChordbutton_Click);
//
// BottomChordButton
//
this.BottomChordButton.Location = new System.Drawing.Point(88, 286);
this.BottomChordButton.Name = "BottomChordButton";
this.BottomChordButton.Size = new System.Drawing.Size(83, 23);
this.BottomChordButton.TabIndex = 7;
this.BottomChordButton.Text = "&Bottom Chord";
this.BottomChordButton.UseVisualStyleBackColor = true;
this.BottomChordButton.Click += new System.EventHandler(this.BottomChordButton_Click);
//
// TopChordButton
//
this.TopChordButton.Location = new System.Drawing.Point(7, 286);
this.TopChordButton.Name = "TopChordButton";
this.TopChordButton.Size = new System.Drawing.Size(75, 23);
this.TopChordButton.TabIndex = 6;
this.TopChordButton.Text = "&Top Chord";
this.TopChordButton.UseVisualStyleBackColor = true;
this.TopChordButton.Click += new System.EventHandler(this.TopChordButton_Click);
//
// UpdateButton
//
this.UpdateButton.Location = new System.Drawing.Point(315, 287);
this.UpdateButton.Name = "UpdateButton";
this.UpdateButton.Size = new System.Drawing.Size(75, 23);
this.UpdateButton.TabIndex = 5;
this.UpdateButton.Text = "&Update";
this.UpdateButton.UseVisualStyleBackColor = true;
this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click);
//
// RestoreButton
//
this.RestoreButton.Location = new System.Drawing.Point(234, 287);
this.RestoreButton.Name = "RestoreButton";
this.RestoreButton.Size = new System.Drawing.Size(75, 23);
this.RestoreButton.TabIndex = 4;
this.RestoreButton.Text = "&Restore";
this.RestoreButton.UseVisualStyleBackColor = true;
this.RestoreButton.Click += new System.EventHandler(this.RestoreButton_Click);
//
// ProfileEditPictureBox
//
this.ProfileEditPictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.ProfileEditPictureBox.Cursor = System.Windows.Forms.Cursors.Default;
this.ProfileEditPictureBox.Location = new System.Drawing.Point(7, 6);
this.ProfileEditPictureBox.Name = "ProfileEditPictureBox";
this.ProfileEditPictureBox.Size = new System.Drawing.Size(384, 274);
this.ProfileEditPictureBox.TabIndex = 3;
this.ProfileEditPictureBox.TabStop = false;
this.ProfileEditPictureBox.MouseMove += new System.Windows.Forms.MouseEventHandler(this.ProfileEditPictureBox_MouseMove);
this.ProfileEditPictureBox.Paint += new System.Windows.Forms.PaintEventHandler(this.ProfileEditPictureBox_Paint);
this.ProfileEditPictureBox.MouseClick += new System.Windows.Forms.MouseEventHandler(this.ProfileEditPictureBox_MouseClick);
//
// TrussTypeLabel
//
this.TrussTypeLabel.AutoSize = true;
this.TrussTypeLabel.Location = new System.Drawing.Point(12, 9);
this.TrussTypeLabel.Name = "TrussTypeLabel";
this.TrussTypeLabel.Size = new System.Drawing.Size(66, 13);
this.TrussTypeLabel.TabIndex = 3;
this.TrussTypeLabel.Text = "Truss Type :";
//
// CloseButton
//
this.CloseButton.Location = new System.Drawing.Point(337, 390);
this.CloseButton.Name = "CloseButton";
this.CloseButton.Size = new System.Drawing.Size(80, 23);
this.CloseButton.TabIndex = 4;
this.CloseButton.Text = "&Close";
this.CloseButton.UseVisualStyleBackColor = true;
this.CloseButton.Click += new System.EventHandler(this.CloseButton_Click);
//
// TrussForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.CloseButton;
this.ClientSize = new System.Drawing.Size(426, 420);
this.Controls.Add(this.CloseButton);
this.Controls.Add(this.TrussTypeLabel);
this.Controls.Add(this.TrussGraphicsTabControl);
this.Controls.Add(this.TrussTypeComboBox);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "TrussForm";
this.ShowInTaskbar = false;
this.Text = "TrussForm";
this.Load += new System.EventHandler(this.TrussForm_Load);
this.TrussGraphicsTabControl.ResumeLayout(false);
this.ViewTabPage.ResumeLayout(false);
this.ViewTabPage.PerformLayout();
this.TrussMembersTabPage.ResumeLayout(false);
this.TrussMembersTabPage.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.TrussMembersPictureBox)).EndInit();
this.ProfileEditTabPage.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.ProfileEditPictureBox)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.ComboBox TrussTypeComboBox;
private System.Windows.Forms.TabControl TrussGraphicsTabControl;
private System.Windows.Forms.TabPage ViewTabPage;
private System.Windows.Forms.TabPage TrussMembersTabPage;
private System.Windows.Forms.TabPage ProfileEditTabPage;
private System.Windows.Forms.Button CreateButton;
private System.Windows.Forms.PictureBox TrussMembersPictureBox;
private System.Windows.Forms.Button UpdateButton;
private System.Windows.Forms.Button RestoreButton;
private System.Windows.Forms.PictureBox ProfileEditPictureBox;
private System.Windows.Forms.Label TrussTypeLabel;
private System.Windows.Forms.Button TopChordButton;
private System.Windows.Forms.Button BottomChordButton;
private System.Windows.Forms.Button CleanChordbutton;
private System.Windows.Forms.Button ChangeBeamTypeButton;
private System.Windows.Forms.ComboBox BeamTypeComboBox;
private System.Windows.Forms.Label BeamTypeLabel;
private System.Windows.Forms.ComboBox ViewComboBox;
private System.Windows.Forms.Label ViewLabel;
private System.Windows.Forms.Label Notelabel;
private System.Windows.Forms.Button CloseButton;
}
}
+582
View File
@@ -0,0 +1,582 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Autodesk.Revit;
using System.Collections;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB.Structure;
using System.Drawing.Drawing2D;
using System.Threading;
namespace Revit.SDK.Samples.Truss.CS
{
/// <summary>
/// window form contains one three picture box to show the
/// profile of truss geometry and profile and tabControl.
/// User can create truss, edit profile of truss and change type of truss members.
/// </summary>
public partial class TrussForm : System.Windows.Forms.Form
{
ExternalCommandData m_commandData; //object which contains reference of Revit Application
ArrayList m_trussTypes; //stores all the truss types
IEnumerable<Autodesk.Revit.DB.FamilySymbol> m_beamTypes; //stores all the beam types (FamilySymbol)
IEnumerable<Autodesk.Revit.DB.ViewPlan> m_views; //stores all the ViewPlan use to create truss
TrussGeometry trussGeometry; //TrussGeometry object store geometry info of Truss
TrussType m_selectedTrussType; //selected truss type
Autodesk.Revit.DB.Structure.Truss m_truss; //store the truss created by this sample
bool m_topChord = false; //allows to draw top chord when it's true, otherwise forbids to do it.
bool m_bottomChord = false; //draw bottom chord when it's true, otherwise forbids to do it.
int m_selectMemberIndex; //index of selected truss member
Autodesk.Revit.DB.ViewPlan m_selectedView; //store the selected view
FamilyInstance m_selecedtBeam; //store the selected beam
FamilySymbol m_selectedBeamType; //store the selected beam type
UIDocument m_activeDocument; //active document in Revit
FamilyInstance column1; //one of 2 columns which truss build on
FamilyInstance column2; //one of 2 columns which truss build on
const String NoAssociatedLevel = "<not associated>"; //when select truss doesn't have associate level
/// <summary>
/// constructor
/// </summary>
/// <param name="commandData">object which contains reference of Revit Application</param>
public TrussForm(ExternalCommandData commandData)
{
m_commandData = commandData;
m_activeDocument = m_commandData.Application.ActiveUIDocument;
InitializeComponent();
m_trussTypes = new ArrayList();
//Get user selection
if (!GetSelectTrussOrColumns())
{
TaskDialog.Show("Select", "Please select 1 existing truss or 2 columns before load this application.");
this.Close();
}
// get all the beam types, truss types and all the view plans from the active document
DataInitialize();
}
/// <summary>
/// Get 1 truss or 2 columns from selection
/// </summary>
/// <returns>return false if selection incorrect</returns>
private bool GetSelectTrussOrColumns()
{
if (m_activeDocument.Selection.GetElementIds().Count > 2 ||
0 == m_activeDocument.Selection.GetElementIds().Count)
{ return false; }
ElementSet es = new ElementSet();
foreach (ElementId elementId in m_activeDocument.Selection.GetElementIds())
{
es.Insert(m_activeDocument.Document.GetElement(elementId));
}
IEnumerator iter = es.GetEnumerator();
iter.Reset();
while (iter.MoveNext())
{
if (iter.Current is Autodesk.Revit.DB.Structure.Truss)
{
if (null == m_truss)
{ m_truss = iter.Current as Autodesk.Revit.DB.Structure.Truss; }
else { return false; }
}
else if (iter.Current is Autodesk.Revit.DB.FamilyInstance)
{
FamilyInstance familyInstance = iter.Current as FamilyInstance;
if (StructuralType.Column == familyInstance.StructuralType)
{
if (null == column1) { column1 = familyInstance; }
else { column2 = familyInstance; }
}
else
{ return false; }
}
else { return false; }
}
if (null == m_truss && (null == column1 || null == column2))
{ return false; }
return true;
}
/// <summary>
/// get all the beam types, truss types and all the view plans from the active document
/// </summary>
public void DataInitialize()
{
// get all the beam types
GetBeamTypes();
// get all the truss types
// there's no truss type in the active document
FilteredElementCollector filteredElementCollector = new FilteredElementCollector(m_activeDocument.Document);
filteredElementCollector.OfClass(typeof(FamilySymbol));
filteredElementCollector.OfCategory(BuiltInCategory.OST_Truss);
IList<TrussType> trussTypes = filteredElementCollector.Cast<TrussType>().ToList<TrussType>();
if (null == trussTypes || 0 == trussTypes.Count)
{
TaskDialog.Show("Load Truss Type", "Please load at least one truss type into your project.");
this.Close();
}
foreach (TrussType trussType in trussTypes)
{
if (null == trussType)
{
continue;
}
String trussTypeName = trussType.get_Parameter
(BuiltInParameter.SYMBOL_FAMILY_AND_TYPE_NAMES_PARAM).AsString();
this.TrussTypeComboBox.Items.Add(trussTypeName);
m_trussTypes.Add(trussType);
}
// get all the views
// Skip view templates because they're behind-the-scene and invisible in project browser; also invalid for API..., etc.
m_views = from elem in
new FilteredElementCollector(m_activeDocument.Document).OfClass(typeof(ViewPlan)).ToElements()
let viewPlan = elem as ViewPlan
where viewPlan != null && !viewPlan.IsTemplate
select viewPlan;
foreach (Autodesk.Revit.DB.View view in m_views)
{
this.ViewComboBox.Items.Add(view.Name);
}
}
/// <summary>
/// get all the beam types
/// </summary>
private void GetBeamTypes()
{
m_beamTypes = from elem in
new FilteredElementCollector(m_activeDocument.Document).OfClass(
typeof(FamilySymbol)).OfCategory(Autodesk.Revit.DB.BuiltInCategory.OST_StructuralFraming)
let type = elem as FamilySymbol
select type;
// can't obtain beam types from the active document
if (null == m_beamTypes ||
0 == m_beamTypes.Count())
{
TaskDialog.Show("Load Structural Framing Family", "No Structural Framing Family loaded. Please load one of the Structure Framing Family.");
this.Close();
}
foreach (FamilySymbol familySymbol in m_beamTypes)
{
String beamTypeName = familySymbol.get_Parameter(
BuiltInParameter.SYMBOL_FAMILY_AND_TYPE_NAMES_PARAM).AsString();
this.BeamTypeComboBox.Items.Add(beamTypeName);
}
}
/// <summary>
/// initialize the UI ComboBox's appearance
/// </summary>
/// <param name="sender">object who sent this event</param>
/// <param name="e">event args</param>
private void TrussForm_Load(object sender, EventArgs e)
{
this.TrussTypeComboBox.SelectedIndex = 0;
this.ViewComboBox.SelectedIndex = 0;
//user pre-select a truss in Revit UI
if (m_truss != null)
{
// show the truss type and level of pre-selected truss in the ComboBox
String nameOfTrussType = m_truss.TrussType.get_Parameter
(BuiltInParameter.SYMBOL_FAMILY_AND_TYPE_NAMES_PARAM).AsString();
this.TrussTypeComboBox.SelectedIndex = this.TrussTypeComboBox.Items.IndexOf(nameOfTrussType);
Parameter viewName = m_truss.get_Parameter(BuiltInParameter.SKETCH_PLANE_PARAM);
if (null == viewName || 0 == viewName.AsString().CompareTo(NoAssociatedLevel))
{
this.ViewComboBox.Items.Add(NoAssociatedLevel);
this.ViewComboBox.SelectedIndex = this.ViewComboBox.Items.IndexOf(NoAssociatedLevel);
}
else
{
String nameOfViewPlane = viewName.AsString().Substring(8);
this.ViewComboBox.SelectedIndex = this.ViewComboBox.Items.IndexOf(nameOfViewPlane);
}
this.TrussTypeComboBox.Enabled = false;
this.CreateButton.Enabled = false;
this.ViewComboBox.Enabled = false;
trussGeometry = new TrussGeometry(m_truss, m_commandData);
this.TrussGraphicsTabControl.SelectedIndex = 1;
}
}
/// <summary>
/// get selected truss type, this data will be used in truss creation
/// </summary>
/// <param name="sender">object who sent this event</param>
/// <param name="e">event args</param>
private void TrussTypeComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
m_selectedTrussType = (TrussType)m_trussTypes[this.TrussTypeComboBox.SelectedIndex];
}
/// <summary>
/// create new truss
/// </summary>
/// <param name="sender">object who sent this event</param>
/// <param name="e">event args</param>
private void CreateButton_Click(object sender, EventArgs e)
{
try
{
Transaction transaction = new Transaction(m_commandData.Application.ActiveUIDocument.Document, "CreateTruss");
transaction.Start();
// create the truss
m_truss = CreateTruss();
m_truss.Location.Move(new Autodesk.Revit.DB.XYZ(0, 0, m_selectedView.GenLevel.Elevation));
transaction.Commit();
trussGeometry = new TrussGeometry(m_truss, m_commandData);
this.TrussGraphicsTabControl.SelectedIndex = 1;
}
catch (Exception ex)
{
TaskDialog.Show("Exception", ex.Message);
}
this.TrussTypeComboBox.Enabled = false;
this.CreateButton.Enabled = false;
this.ViewComboBox.Enabled = false;
}
/// <summary>
/// create truss in Revit
/// </summary>
/// <returns>new created truss</returns>
public Autodesk.Revit.DB.Structure.Truss CreateTruss()
{
Autodesk.Revit.DB.Document document = m_commandData.Application.ActiveUIDocument.Document;
Autodesk.Revit.Creation.Document createDoc = document.Create;
Autodesk.Revit.Creation.Application createApp = m_commandData.Application.Application.Create;
//sketchPlane
Autodesk.Revit.DB.XYZ origin = new Autodesk.Revit.DB.XYZ(0, 0, 0);
Autodesk.Revit.DB.XYZ xDirection = new Autodesk.Revit.DB.XYZ(1, 0, 0);
Autodesk.Revit.DB.XYZ yDirection = new Autodesk.Revit.DB.XYZ(0, 1, 0);
Plane plane = Plane.CreateByOriginAndBasis(xDirection, yDirection, origin);
SketchPlane sketchPlane = SketchPlane.Create(document, plane);
//new base Line
AnalyticalModel frame1 = column1.GetAnalyticalModel();
Autodesk.Revit.DB.XYZ centerPoint1 = (frame1.GetCurve() as Line).GetEndPoint(0);
AnalyticalModel frame2 = column2.GetAnalyticalModel();
Autodesk.Revit.DB.XYZ centerPoint2 = (frame2.GetCurve() as Line).GetEndPoint(0);
Autodesk.Revit.DB.XYZ startPoint = new Autodesk.Revit.DB.XYZ(centerPoint1.X, centerPoint1.Y, 0);
Autodesk.Revit.DB.XYZ endPoint = new Autodesk.Revit.DB.XYZ(centerPoint2.X, centerPoint2.Y, 0);
Autodesk.Revit.DB.Line baseLine = null;
try
{ baseLine = Line.CreateBound(startPoint, endPoint); }
catch (System.ArgumentException)
{
TaskDialog.Show("Argument Exception", "Two column you selected are too close to create truss.");
}
return Autodesk.Revit.DB.Structure.Truss.Create(document, m_selectedTrussType.Id, sketchPlane.Id, baseLine);
}
/// <summary>
/// draw profile, top chord and bottom of truss
/// </summary>
/// <param name="sender">object who sent this event</param>
/// <param name="e">event args</param>
private void ProfileEditPictureBox_Paint(object sender, PaintEventArgs e)
{
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
if (trussGeometry != null)
{ trussGeometry.Draw2D(e.Graphics, Pens.Blue); }
Font font = new Font("Verdana", 10, FontStyle.Regular);
string indicator = "Draw Top Chord and Bottom Chord here:";
e.Graphics.DrawString(indicator, font, Brushes.Blue, new PointF(20, 10));
}
/// <summary>
/// add point to top chord and bottom chord
/// </summary>
/// <param name="sender">object who sent this event</param>
/// <param name="e">event args</param>
private void ProfileEditPictureBox_MouseClick(object sender, MouseEventArgs e)
{
// draw top chord line
if (m_topChord)
{ trussGeometry.AddTopChordPoint(e.X, e.Y); }
// draw bottom chord line
else if (m_bottomChord)
{ trussGeometry.AddBottomChordPoint(e.X, e.Y); }
this.ProfileEditPictureBox.Refresh();
}
/// <summary>
/// change move point of top chord lineTool and bottom chord lineTool
/// </summary>
/// <param name="sender">object who sent this event</param>
/// <param name="e">event args</param>
private void ProfileEditPictureBox_MouseMove(object sender, MouseEventArgs e)
{
if (m_topChord)
{ trussGeometry.AddTopChordMovePoint(e.X, e.Y); }
else if (m_bottomChord)
{ trussGeometry.AddBottomChordMovePoint(e.X, e.Y); }
this.ProfileEditPictureBox.Refresh();
}
/// <summary>
/// begin to draw top chord
/// </summary>
/// <param name="sender">object who sent this event</param>
/// <param name="e">event args</param>
private void TopChordButton_Click(object sender, EventArgs e)
{
m_topChord = true;
m_bottomChord = false;
this.ProfileEditPictureBox.Cursor = Cursors.Cross;
this.ProfileEditPictureBox.Refresh();
}
/// <summary>
/// begin to draw bottom chord
/// </summary>
/// <param name="sender">object who sent this event</param>
/// <param name="e">event args</param>
private void BottomChordButton_Click(object sender, EventArgs e)
{
m_topChord = false;
m_bottomChord = true;
this.ProfileEditPictureBox.Cursor = Cursors.Cross;
this.ProfileEditPictureBox.Refresh();
}
/// <summary>
/// update the truss according to the top chord line and the bottom chord line
/// </summary>
/// <param name="sender">object who sent this event</param>
/// <param name="e">event args</param>
private void UpdateButton_Click(object sender, EventArgs e)
{
Transaction transaction = new Transaction(m_activeDocument.Document, "SetProfile");
transaction.Start();
//update the truss
trussGeometry.SetProfile(m_commandData);
transaction.Commit();
this.ProfileEditPictureBox.Refresh();
}
/// <summary>
/// restore profile of truss
/// </summary>
/// <param name="sender">object who sent this event</param>
/// <param name="e">event args</param>
private void RestoreButton_Click(object sender, EventArgs e)
{
Transaction transaction = new Transaction(m_activeDocument.Document, "RemoveProfile");
transaction.Start();
// restore the profile
trussGeometry.RemoveProfile();
transaction.Commit();
this.ProfileEditPictureBox.Refresh();
}
/// <summary>
/// clear points of top and bottom chord line
/// </summary>
/// <param name="sender">object who sent this event</param>
/// <param name="e">event args</param>
private void CleanChordbutton_Click(object sender, EventArgs e)
{
trussGeometry.ClearChords();
m_topChord = false;
m_bottomChord = false;
this.ProfileEditPictureBox.Cursor = Cursors.Default;
this.ProfileEditPictureBox.Refresh();
}
/// <summary>
/// draw geometry of truss, and draw selected line red
/// </summary>
/// <param name="sender">object who sent this event</param>
/// <param name="e">event args</param>
private void TrussGeometryPictureBox_Paint(object sender, PaintEventArgs e)
{
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
if (trussGeometry != null)
{ trussGeometry.Draw2D(e.Graphics, Pens.Blue); }
Font font = new Font("Verdana", 10, FontStyle.Regular);
string indicator = "Select a beam from the truss:";
e.Graphics.DrawString(indicator, font, Brushes.Blue, new PointF(20, 10));
}
/// <summary>
/// get selected truss member (Beam)
/// </summary>
/// <param name="sender">object who sent this event</param>
/// <param name="e">event args</param>
private void TrussGeometryPictureBox_MouseMove(object sender, MouseEventArgs e)
{
// indicates whether the mouse moves over or hovers on one beam
// if true, paints the beam to red
m_selectMemberIndex = trussGeometry.SelectTrussMember(e.X, e.Y);
this.TrussMembersPictureBox.Refresh();
}
/// <summary>
/// select truss member (beam)
/// </summary>
/// <param name="sender">object who sent this event</param>
/// <param name="e">event args</param>
private void TrussGeometryPictureBox_MouseClick(object sender, MouseEventArgs e)
{
// clicks in the canvas but doesn't select anything
if (-1 == m_selectMemberIndex)
{
this.BeamTypeComboBox.Enabled = false;
this.ChangeBeamTypeButton.Enabled = false;
return;
}
// clicks in the canvas and selects a beam
m_selecedtBeam = trussGeometry.GetSelectedBeam(m_commandData);
if (null != m_selecedtBeam)
{
FamilySymbol symbol = m_selecedtBeam.Symbol;
// get the type of the selected beam
String nameOfSymbol = symbol.get_Parameter(
BuiltInParameter.SYMBOL_FAMILY_AND_TYPE_NAMES_PARAM).AsString();
int index = this.BeamTypeComboBox.Items.IndexOf(nameOfSymbol);
// show the beam type in the ComboBox
this.BeamTypeComboBox.SelectedIndex = index;
this.BeamTypeComboBox.Enabled = true;
this.ChangeBeamTypeButton.Enabled = true;
this.TrussMembersPictureBox.Refresh();
}
}
/// <summary>
/// change selected beam type
/// </summary>
/// <param name="sender">object who sent this event</param>
/// <param name="e">event args</param>
private void BeamTypeComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
// choose a new beam type for the selected beam
m_selectedBeamType = m_beamTypes.ElementAt(this.BeamTypeComboBox.SelectedIndex);
}
/// <summary>
/// change type of selected beam
/// </summary>
/// <param name="sender">object who sent this event</param>
/// <param name="e">event args</param>
private void ChangeBeamTypeButton_Click(object sender, EventArgs e)
{
// apply the beam type change
Transaction transaction = new Transaction(m_activeDocument.Document, "ChangeSelectedBeamType");
transaction.Start();
if (null != m_selecedtBeam)
{ m_selecedtBeam.Symbol = m_selectedBeamType; }
transaction.Commit();
}
/// <summary>
/// change selected ViewPlan
/// </summary>
/// <param name="sender">object who sent this event</param>
/// <param name="e">event args</param>
private void ViewComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
// choose another view for the truss creation
if (this.ViewComboBox.SelectedIndex < m_views.Count())
{ m_selectedView = m_views.ElementAt(this.ViewComboBox.SelectedIndex); }
}
/// <summary>
/// quit the "top chord" or "bottom chord" drawing operation
/// by pressing the "ESC" key
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TrussGraphicsTabControl_KeyPress(object sender, KeyPressEventArgs e)
{
// the "Profile Edit" tab page is active
// and the user presses the "ESC" key (e.KeyChar == 27)
if (TrussGraphicsTabControl.SelectedTab == ProfileEditTabPage &&
e.KeyChar == (char)27)
{
// quit the "chord" drawing and remove the move indicating line
m_topChord = false;
m_bottomChord = false;
this.ProfileEditPictureBox.Cursor = Cursors.Default;
trussGeometry.ClearMovePoint();
this.ProfileEditPictureBox.Refresh();
}
}
/// <summary>
/// won't let open truss member tab until truss create successfully
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TrussGraphicsTabControl_Selecting(object sender, TabControlCancelEventArgs e)
{
// if no truss is created, locks the tab pages to the 1st tab page
if (null == trussGeometry)
{
this.TrussGraphicsTabControl.SelectedIndex = 0;
}
else
{
trussGeometry.Reset();
m_selecedtBeam = null;
}
}
/// <summary>
/// Close dialogue box
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CloseButton_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
+132
View File
@@ -0,0 +1,132 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="TrussMembersTabPage.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ProfileEditTabPage.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="TrussMembersTabPage.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ProfileEditTabPage.Locked" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>
+573
View File
@@ -0,0 +1,573 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using Autodesk.Revit;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Collections;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB.Structure;
using Point = System.Drawing.Point;
namespace Revit.SDK.Samples.Truss.CS
{
/// <summary>
/// TrussGeometry class contains Geometry information of new created Truss,
/// and contains methods used to Edit profile of truss.
/// </summary>
class TrussGeometry
{
#region class member variables
Autodesk.Revit.DB.Structure.Truss m_truss; //object of truss in Revit
LineTool m_topChord; //line tool used to draw top chord
LineTool m_bottomChord; //line tool used to draw top chord
ArrayList m_graphicsPaths; //store all the GraphicsPath objects of each curve in truss.
int m_selectMemberIndex = -1; // index of selected truss member (beam), -1 when nothing selected.
int m_clickMemberIndex = -1; // index of clicked truss member (beam), -1 when nothing clicked.
List<XYZ> m_points; // store all the points on the needed face
Autodesk.Revit.DB.XYZ[] m_boundPoints; // store array store bound point of truss
Matrix4 m_to2DMatrix = null; // store the Matrix used to transform 3D points to 2D
Matrix4 m_moveToCenterMatrix = null; // store the Matrix used to move points to center
Matrix4 m_scaleMatrix = null; // store the Matrix used to scale profile fit to pictureBox
Matrix4 m_transformMatrix = null; // store the Matrix used to transform Revit coordinate to window UI
Matrix4 m_restoreMatrix = null; // store the Matrix used to transform window UI coordinate to Revit
Matrix4 m_2DToTrussProfileMatrix = null; //store matrix use to transform point on pictureBox to truss (profile) plane
Vector4 m_origin = null; //base point of truss
ExternalCommandData m_commandData; //object which contains reference of Revit Application
Autodesk.Revit.DB.XYZ startLocation = null; //store the start point of truss location
Autodesk.Revit.DB.XYZ endLocation = null; //store the end point of truss location
#endregion
/// <summary>
/// constructor
/// </summary>
/// <param name="truss">new created truss object in Revit</param>
public TrussGeometry(Autodesk.Revit.DB.Structure.Truss truss, ExternalCommandData commandData)
{
m_commandData = commandData;
m_topChord = new LineTool();
m_bottomChord = new LineTool();
m_truss = truss;
m_graphicsPaths = new ArrayList();
GetTrussGeometryInfo();
}
/// <summary>
/// Calculate geometry info for truss
/// </summary>
private void GetTrussGeometryInfo()
{
// get the start and end point of the basic line of the truss
m_points = GetTrussPoints();
// Get a matrix which can transform points to 2D
m_to2DMatrix = GetTo2DMatrix();
// get the boundary of all the points
m_boundPoints = GetBoundsPoints();
// get a matrix which can keep all the points in the center of the canvas
m_moveToCenterMatrix = GetMoveToCenterMatrix();
// get a matrix for scaling all the points and lines within the canvas
m_scaleMatrix = GetScaleMatrix();
// transform 3D points to 2D
m_transformMatrix = Get3DTo2DMatrix();
// transform from 2D to 3D
m_restoreMatrix = Get2DTo3DMatrix();
// transform from 2D (on picture box) to truss profile plane
m_2DToTrussProfileMatrix = Get2DToTrussProfileMatrix();
// create the graphics path which contains all the lines
CreateGraphicsPath();
}
/// <summary>
/// Get points of the truss
/// </summary>
/// <returns>points array stores all the points on truss</returns>
public List<XYZ> GetTrussPoints()
{
List<XYZ> xyzArray = new List<XYZ>();
try
{
IEnumerator iter = m_truss.Members.GetEnumerator();
iter.Reset();
while (iter.MoveNext())
{
Autodesk.Revit.DB.ElementId id = (Autodesk.Revit.DB.ElementId)(iter.Current);
Autodesk.Revit.DB.Element elem =
m_commandData.Application.ActiveUIDocument.Document.GetElement(id);
FamilyInstance familyInstace = (FamilyInstance)(elem);
AnalyticalModel frame = familyInstace.GetAnalyticalModel();
Line line = (Line)(frame.GetCurve());
xyzArray.Add(line.GetEndPoint(0));
xyzArray.Add(line.GetEndPoint(1));
}
}
catch (System.ArgumentException)
{
TaskDialog.Show("Revit", "The start point and the end point of the line are too close, please re-draw it.");
}
return xyzArray;
}
/// <summary>
/// Get a matrix which can transform points to 2D
/// </summary>
/// <returns>matrix which can transform points to 2D</returns>
public Matrix4 GetTo2DMatrix()
{
Line trussLocation = (m_truss.Location as LocationCurve).Curve as Line;
startLocation = trussLocation.GetEndPoint(0);
endLocation = trussLocation.GetEndPoint(1);
//use baseline of truss as the X axis
XYZ diff = endLocation - startLocation;
Vector4 xAxis = new Vector4(new Autodesk.Revit.DB.XYZ(diff.X, diff.Y, diff.Z));
xAxis.Normalize();
//get Z Axis
Vector4 zAxis = Vector4.CrossProduct(xAxis, new Vector4(new Autodesk.Revit.DB.XYZ(0, 0, 1)));
zAxis.Normalize();
//get Y Axis, downward
Vector4 yAxis = Vector4.CrossProduct(xAxis, zAxis);
yAxis.Normalize();
//get original point, first point
m_origin = new Vector4(m_points[0]);
return new Matrix4(xAxis, yAxis, zAxis, m_origin);
}
/// <summary>
/// calculate the matrix use to scale
/// </summary>
/// <returns>maxtrix is use to scale the profile</returns>
public Matrix4 GetScaleMatrix()
{
double xScale = 384 / (m_boundPoints[1].X - m_boundPoints[0].X);
double yScale = 275 / (m_boundPoints[1].Y - m_boundPoints[0].Y);
double factor = xScale <= yScale ? xScale : yScale;
return new Matrix4((double)(factor * 0.85));
}
/// <summary>
/// Get a matrix which can move points to center
/// </summary>
/// <returns>matrix used to move point to center of graphics</returns>
public Matrix4 GetMoveToCenterMatrix()
{
//translate the origin to bound center
Autodesk.Revit.DB.XYZ[] bounds = GetBoundsPoints();
Autodesk.Revit.DB.XYZ min = bounds[0];
Autodesk.Revit.DB.XYZ max = bounds[1];
Autodesk.Revit.DB.XYZ center = new Autodesk.Revit.DB.XYZ((min.X + max.X) / 2, (min.Y + max.Y) / 2, 0);
return new Matrix4(new Vector4(center.X, center.Y, 0));
}
/// <summary>
/// calculate the matrix used to transform 3D to 2D
/// </summary>
/// <returns>maxtrix is use to transform 3d points to 2d</returns>
public Matrix4 Get3DTo2DMatrix()
{
Matrix4 result = Matrix4.Multiply(
m_to2DMatrix.Inverse(), m_moveToCenterMatrix.Inverse());
result = Matrix4.Multiply(result, m_scaleMatrix);
return Matrix4.Multiply(result, new Matrix4(new Vector4(192, 137, 0)));
}
/// <summary>
/// calculate the matrix used to transform 2D to 3D
/// </summary>
/// <returns>maxtrix is use to transform 2d points to 3d</returns>
public Matrix4 Get2DTo3DMatrix()
{
Matrix4 matrix = Matrix4.Multiply(
new Matrix4(new Vector4(-192, -137, 0)), m_scaleMatrix.Inverse());
matrix = Matrix4.Multiply(matrix, m_moveToCenterMatrix);
return Matrix4.Multiply(matrix, m_to2DMatrix);
}
/// <summary>
/// calculate the matrix used to transform 2d points (on pictureBox) to the plane of truss
/// which use to set profile
/// </summary>
/// <returns>maxtrix is use to transform 2d points to the plane of truss</returns>
public Matrix4 Get2DToTrussProfileMatrix()
{
Matrix4 matrix = Matrix4.Multiply(
new Matrix4(new Vector4(-192, -137, 0)), m_scaleMatrix.Inverse());
return Matrix4.Multiply(matrix, m_moveToCenterMatrix);
////downward in picture box, so rotate upward here, y = -y
//Matrix4 upward = new Matrix4(new Vector4(new Autodesk.Revit.DB.XYZ (1, 0, 0)),
// new Vector4(new Autodesk.Revit.DB.XYZ (0, -1, 0)), new Vector4(new Autodesk.Revit.DB.XYZ (0, 0, 1)));
//return Matrix4.Multiply(matrix, upward);
}
/// <summary>
/// Get max and min coordinates of all points
/// </summary>
/// <returns>points array stores the bound of all points</returns>
public Autodesk.Revit.DB.XYZ[] GetBoundsPoints()
{
Matrix4 matrix = m_to2DMatrix;
Matrix4 inverseMatrix = matrix.Inverse();
double minX = 0, maxX = 0, minY = 0, maxY = 0;
bool bFirstPoint = true;
//get the max and min point on the face
foreach (Autodesk.Revit.DB.XYZ point in m_points)
{
Vector4 v = new Vector4(point);
Vector4 v1 = inverseMatrix.Transform(v);
if (bFirstPoint)
{
minX = maxX = v1.X;
minY = maxY = v1.Y;
bFirstPoint = false;
}
else
{
if (v1.X < minX) { minX = v1.X; }
else if (v1.X > maxX) { maxX = v1.X; }
if (v1.Y < minY) { minY = v1.Y; }
else if (v1.Y > maxY) { maxY = v1.Y; }
}
}
//return an array with max and min value of all points
Autodesk.Revit.DB.XYZ[] resultPoints = new Autodesk.Revit.DB.XYZ[2] {
new Autodesk.Revit.DB.XYZ (minX, minY, 0), new Autodesk.Revit.DB.XYZ (maxX, maxY, 0) };
return resultPoints;
}
/// <summary>
/// draw profile of truss in pictureBox
/// </summary>
/// <param name="graphics">form graphic</param>
/// <param name="pen">pen used to draw line in pictureBox</param>
public void Draw2D(Graphics graphics, Pen pen)
{
//draw truss curves
for (int i = 0; i < m_points.Count - 1; i += 2)
{
Autodesk.Revit.DB.XYZ point1 = m_points[i];
Autodesk.Revit.DB.XYZ point2 = m_points[i + 1];
Vector4 v1 = new Vector4(point1);
Vector4 v2 = new Vector4(point2);
v1 = m_transformMatrix.Transform(v1);
v2 = m_transformMatrix.Transform(v2);
graphics.DrawLine(pen, new Point((int)v1.X, (int)v1.Y),
new Point((int)v2.X, (int)v2.Y));
}
//draw selected beam (line) by red pen
DrawSelectedLineRed(graphics);
//draw top chord and bottom chord
m_topChord.Draw2D(graphics, Pens.Red);
m_bottomChord.Draw2D(graphics, Pens.Black);
}
/// <summary>
/// Set profile of truss
/// </summary>
/// <param name="commandData">object which contains reference of Revit Application</param>
public void SetProfile(ExternalCommandData commandData)
{
if (m_topChord.Points.Count < 2)
{ TaskDialog.Show("Truss API", "Haven't drawn top chord"); return; }
else if (m_bottomChord.Points.Count < 2)
{ TaskDialog.Show("Truss API", "Haven't drawn bottom chord"); return; }
Autodesk.Revit.Creation.Document createDoc = commandData.Application.ActiveUIDocument.Document.Create;
Autodesk.Revit.Creation.Application createApp = commandData.Application.Application.Create;
CurveArray curvesTop = createApp.NewCurveArray();
CurveArray curvesBottom = createApp.NewCurveArray();
//get coordinates of top (bottom) chord from lineTool
GetChordPoints(m_topChord, curvesTop, createApp);
GetChordPoints(m_bottomChord, curvesBottom, createApp);
try
{
//set profile by top curve and bottom curve drawn by user in picture box
m_truss.SetProfile(curvesTop, curvesBottom);
}
catch (Exception ex)
{
TaskDialog.Show("Truss API", ex.Message);
}
//re-calculate geometry info after truss profile changed
GetTrussGeometryInfo();
ClearChords();
}
private void GetChordPoints(LineTool chord, CurveArray curves, Autodesk.Revit.Creation.Application createApp)
{
//get coordinates of top chord from lineTool
for (int i = 0; i < chord.Points.Count - 1; i++)
{
Point point = (Point)chord.Points[i];
Point point2 = (Point)chord.Points[i + 1];
Autodesk.Revit.DB.XYZ xyz = new Autodesk.Revit.DB.XYZ(point.X, point.Y, 0);
Autodesk.Revit.DB.XYZ xyz2 = new Autodesk.Revit.DB.XYZ(point2.X, point2.Y, 0);
Vector4 v1 = new Vector4(xyz);
Vector4 v2 = new Vector4(xyz2);
v1 = m_restoreMatrix.Transform(v1);
v2 = m_restoreMatrix.Transform(v2);
try
{
Line line = Line.CreateBound(
new Autodesk.Revit.DB.XYZ(v1.X, v1.Y, v1.Z), new Autodesk.Revit.DB.XYZ(v2.X, v2.Y, v2.Z));
curves.Append(line);
}
catch (System.ArgumentException)
{
TaskDialog.Show("Revit",
"The start point and the end point of the line are too close, please re-draw it.");
ClearChords();
}
}
}
/// <summary>
/// restores truss profile to original
/// </summary>
public void RemoveProfile()
{
m_truss.RemoveProfile();
GetTrussGeometryInfo();
ClearChords();
}
/// <summary>
/// add new point to line tool which used to draw top chord
/// </summary>
/// <param name="x">X coordinate</param>
/// <param name="y">Y coordinate</param>
public void AddTopChordPoint(int x, int y)
{
// doesn't allow to add 2 points near-by
if (m_topChord.Points.Count > 0)
{
Point lastPoint = (Point)m_topChord.Points[m_topChord.Points.Count - 1];
if (Math.Abs(lastPoint.X - x) < 1 ||
Math.Abs(lastPoint.Y - y) < 1)
{
return;
}
}
m_topChord.Points.Add(new Point(x, y));
}
/// <summary>
/// add new point to line tool which used to draw bottom chord
/// </summary>
/// <param name="x">X coordinate</param>
/// <param name="y">Y coordinate</param>
public void AddBottomChordPoint(int x, int y)
{
// doesn't allow to add 2 points near-by
if (m_topChord.Points.Count > 0)
{
Point lastPoint = (Point)m_topChord.Points[m_topChord.Points.Count - 1];
if (Math.Abs(lastPoint.X - x) < 1 ||
Math.Abs(lastPoint.Y - y) < 1)
{
return;
}
}
m_bottomChord.Points.Add(new Point(x, y));
}
/// <summary>
/// add move point to line tool of top chord
/// </summary>
/// <param name="x">X coordinate</param>
/// <param name="y">Y coordinate</param>
public void AddTopChordMovePoint(int x, int y)
{
m_topChord.MovePoint = new Point(x, y);
m_bottomChord.MovePoint = Point.Empty;
}
/// <summary>
/// add move point to line tool of bottom chord
/// </summary>
/// <param name="x">X coordinate</param>
/// <param name="y">Y coordinate</param>
public void AddBottomChordMovePoint(int x, int y)
{
m_bottomChord.MovePoint = new Point(x, y);
m_topChord.MovePoint = Point.Empty;
}
public void ClearMovePoint()
{
m_topChord.MovePoint = Point.Empty;
m_bottomChord.MovePoint = Point.Empty;
}
/// <summary>
/// clear points of top chord and bottom chord
/// </summary>
public void ClearChords()
{
m_topChord.Points.Clear();
m_bottomChord.Points.Clear();
}
/// <summary>
/// Create GraphicsPath object for each curves of truss
/// </summary>
public void CreateGraphicsPath()
{
m_graphicsPaths.Clear();
//create path for all the curves of Truss
for (int i = 0; i < m_points.Count - 1; i += 2)
{
Autodesk.Revit.DB.XYZ point1 = m_points[i];
Autodesk.Revit.DB.XYZ point2 = m_points[i + 1];
Vector4 v1 = new Vector4(point1);
Vector4 v2 = new Vector4(point2);
v1 = m_transformMatrix.Transform(v1);
v2 = m_transformMatrix.Transform(v2);
GraphicsPath path = new GraphicsPath();
path.AddLine(new Point((int)v1.X, (int)v1.Y), new Point((int)v2.X, (int)v2.Y));
m_graphicsPaths.Add(path);
}
}
/// <summary>
/// Judge which truss member has been selected via location of mouse
/// </summary>
/// <param name="x">X coordinate of mouse location</param>
/// <param name="y">Y coordinate of mouse location</param>
/// <returns>index of selected member</returns>
public int SelectTrussMember(int x, int y)
{
Point point = new Point(x, y);
for (int i = 0; i < m_graphicsPaths.Count; i++)
{
GraphicsPath path = (GraphicsPath)m_graphicsPaths[i];
if (path.IsOutlineVisible(point, Pens.Blue))
{
m_selectMemberIndex = i;
return m_selectMemberIndex;
}
}
m_selectMemberIndex = -1;
return m_selectMemberIndex;
}
/// <summary>
/// Draw selected line (beam) by red pen
/// </summary>
/// <param name="graphics">graphics of picture box</param>
public void DrawSelectedLineRed(Graphics graphics)
{
Pen redPen = new Pen(System.Drawing.Color.Red, (float)2.0);
//draw the selected beam as red line
if (m_selectMemberIndex != -1)
{
GraphicsPath selectPath = (GraphicsPath)(m_graphicsPaths[m_selectMemberIndex]);
PointF startPointOfSelectedLine = (PointF)(selectPath.PathPoints.GetValue(0));
PointF endPointOfSelectedLine = (PointF)(selectPath.PathPoints.GetValue(1));
graphics.DrawLine(redPen, startPointOfSelectedLine, endPointOfSelectedLine);
}
//draw clicked beam red
if (m_clickMemberIndex != -1)
{
GraphicsPath selectPath = (GraphicsPath)(m_graphicsPaths[m_clickMemberIndex]);
PointF startPointOfSelectedLine = (PointF)(selectPath.PathPoints.GetValue(0));
PointF endPointOfSelectedLine = (PointF)(selectPath.PathPoints.GetValue(1));
graphics.DrawLine(redPen, startPointOfSelectedLine, endPointOfSelectedLine);
}
}
/// <summary>
/// Get selected beam (truss member) by select index
/// </summary>
/// <param name="commandData">object which contains reference of Revit Application</param>
/// <returns>index of selected member</returns>
public FamilyInstance GetSelectedBeam(ExternalCommandData commandData)
{
m_clickMemberIndex = m_selectMemberIndex;
Autodesk.Revit.DB.ElementId id = null;
List<ElementId> idSet = m_truss.Members as List<ElementId>;
IEnumerator iter = idSet.GetEnumerator();
iter.Reset();
int i = 0;
while (iter.MoveNext())
{
if (i == m_selectMemberIndex)
{
id = iter.Current as Autodesk.Revit.DB.ElementId;
break;
}
i++;
}
return (FamilyInstance)commandData.Application.ActiveUIDocument.Document.GetElement(id);
}
/// <summary>
/// Reset index and clear line tool
/// </summary>
public void Reset()
{
m_clickMemberIndex = -1;
m_selectMemberIndex = -1;
m_topChord.Points.Clear();
m_bottomChord.Points.Clear();
}
}
}