added Revit 2020 SDK files

This commit is contained in:
Jeremy Tammik
2019-09-11 14:43:53 +02:00
parent fbb29172ed
commit 8b8832b7be
2956 changed files with 938523 additions and 0 deletions
@@ -0,0 +1,81 @@
//
// (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 notify appears in all copies and
// that both that copyright notify and the limited warranty and
// restricted rights notify 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.Windows.Forms;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace Revit.SDK.Samples.TransactionControl.CS
{
/// <summary>
/// Implements the Revit add-in interface 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
{
/// <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)
{
try
{
// process data from Revit and show dialog
using (TransactionForm transactionFrm = new TransactionForm(commandData))
{
if (transactionFrm.ShowDialog() == DialogResult.OK)
{
return Autodesk.Revit.UI.Result.Succeeded;
}
}
}
catch (Exception ex)
{
message = ex.Message;
return Autodesk.Revit.UI.Result.Failed;
}
return Autodesk.Revit.UI.Result.Cancelled;
}
}
}
@@ -0,0 +1,313 @@
//
// (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 notify appears in all copies and
// that both that copyright notify and the limited warranty and
// restricted rights notify 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.TransactionControl.CS
{
partial class CreateWallForm
{
/// <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.okButton = new System.Windows.Forms.Button();
this.cancelButton = new System.Windows.Forms.Button();
this.spXTextBox = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.spYTextBox = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.spZTextBox = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.epXTextBox = new System.Windows.Forms.TextBox();
this.epYTextBox = new System.Windows.Forms.TextBox();
this.epZTextBox = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
this.levelsComboBox = new System.Windows.Forms.ComboBox();
this.wallTypesComboBox = new System.Windows.Forms.ComboBox();
this.label10 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// okButton
//
this.okButton.Location = new System.Drawing.Point(96, 253);
this.okButton.Name = "okButton";
this.okButton.Size = new System.Drawing.Size(75, 23);
this.okButton.TabIndex = 8;
this.okButton.Text = "&OK";
this.okButton.UseVisualStyleBackColor = true;
this.okButton.Click += new System.EventHandler(this.okButton_Click);
//
// cancelButton
//
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cancelButton.Location = new System.Drawing.Point(177, 253);
this.cancelButton.Name = "cancelButton";
this.cancelButton.Size = new System.Drawing.Size(75, 23);
this.cancelButton.TabIndex = 9;
this.cancelButton.Text = "&Cancel";
this.cancelButton.UseVisualStyleBackColor = true;
//
// spXTextBox
//
this.spXTextBox.Location = new System.Drawing.Point(26, 40);
this.spXTextBox.Name = "spXTextBox";
this.spXTextBox.Size = new System.Drawing.Size(61, 20);
this.spXTextBox.TabIndex = 0;
this.spXTextBox.Text = "0";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(7, 43);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(17, 13);
this.label1.TabIndex = 11;
this.label1.Text = "X:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(7, 16);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(58, 13);
this.label2.TabIndex = 10;
this.label2.Text = "Start point:";
//
// spYTextBox
//
this.spYTextBox.Location = new System.Drawing.Point(109, 40);
this.spYTextBox.Name = "spYTextBox";
this.spYTextBox.Size = new System.Drawing.Size(61, 20);
this.spYTextBox.TabIndex = 1;
this.spYTextBox.Text = "0";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(90, 43);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(17, 13);
this.label3.TabIndex = 12;
this.label3.Text = "Y:";
//
// spZTextBox
//
this.spZTextBox.Location = new System.Drawing.Point(191, 40);
this.spZTextBox.Name = "spZTextBox";
this.spZTextBox.Size = new System.Drawing.Size(61, 20);
this.spZTextBox.TabIndex = 2;
this.spZTextBox.Text = "0";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(172, 43);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(17, 13);
this.label4.TabIndex = 13;
this.label4.Text = "Z:";
//
// epXTextBox
//
this.epXTextBox.Location = new System.Drawing.Point(26, 97);
this.epXTextBox.Name = "epXTextBox";
this.epXTextBox.Size = new System.Drawing.Size(61, 20);
this.epXTextBox.TabIndex = 3;
this.epXTextBox.Text = "10";
//
// epYTextBox
//
this.epYTextBox.Location = new System.Drawing.Point(109, 97);
this.epYTextBox.Name = "epYTextBox";
this.epYTextBox.Size = new System.Drawing.Size(61, 20);
this.epYTextBox.TabIndex = 4;
this.epYTextBox.Text = "0";
//
// epZTextBox
//
this.epZTextBox.Location = new System.Drawing.Point(191, 97);
this.epZTextBox.Name = "epZTextBox";
this.epZTextBox.Size = new System.Drawing.Size(61, 20);
this.epZTextBox.TabIndex = 5;
this.epZTextBox.Text = "0";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(7, 100);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(17, 13);
this.label5.TabIndex = 15;
this.label5.Text = "X:";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(90, 100);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(17, 13);
this.label6.TabIndex = 16;
this.label6.Text = "Y:";
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(172, 100);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(17, 13);
this.label7.TabIndex = 17;
this.label7.Text = "Z:";
//
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(7, 73);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(55, 13);
this.label8.TabIndex = 14;
this.label8.Text = "End point:";
//
// label9
//
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(7, 187);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(36, 13);
this.label9.TabIndex = 19;
this.label9.Text = "Level:";
//
// levelsComboBox
//
this.levelsComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.levelsComboBox.FormattingEnabled = true;
this.levelsComboBox.Location = new System.Drawing.Point(26, 211);
this.levelsComboBox.Name = "levelsComboBox";
this.levelsComboBox.Size = new System.Drawing.Size(103, 21);
this.levelsComboBox.TabIndex = 7;
//
// wallTypesComboBox
//
this.wallTypesComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.wallTypesComboBox.FormattingEnabled = true;
this.wallTypesComboBox.Location = new System.Drawing.Point(26, 155);
this.wallTypesComboBox.Name = "wallTypesComboBox";
this.wallTypesComboBox.Size = new System.Drawing.Size(226, 21);
this.wallTypesComboBox.TabIndex = 6;
//
// label10
//
this.label10.AutoSize = true;
this.label10.Location = new System.Drawing.Point(7, 131);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(54, 13);
this.label10.TabIndex = 18;
this.label10.Text = "Wall type:";
//
// CreateWallForm
//
this.AcceptButton = this.okButton;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.cancelButton;
this.ClientSize = new System.Drawing.Size(264, 288);
this.Controls.Add(this.label10);
this.Controls.Add(this.wallTypesComboBox);
this.Controls.Add(this.levelsComboBox);
this.Controls.Add(this.label9);
this.Controls.Add(this.label8);
this.Controls.Add(this.label2);
this.Controls.Add(this.label7);
this.Controls.Add(this.label4);
this.Controls.Add(this.label6);
this.Controls.Add(this.label3);
this.Controls.Add(this.label5);
this.Controls.Add(this.label1);
this.Controls.Add(this.epZTextBox);
this.Controls.Add(this.spZTextBox);
this.Controls.Add(this.epYTextBox);
this.Controls.Add(this.spYTextBox);
this.Controls.Add(this.epXTextBox);
this.Controls.Add(this.spXTextBox);
this.Controls.Add(this.cancelButton);
this.Controls.Add(this.okButton);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "CreateWallForm";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Create Wall";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button okButton;
private System.Windows.Forms.Button cancelButton;
private System.Windows.Forms.TextBox spXTextBox;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox spYTextBox;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox spZTextBox;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox epXTextBox;
private System.Windows.Forms.TextBox epYTextBox;
private System.Windows.Forms.TextBox epZTextBox;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.ComboBox levelsComboBox;
private System.Windows.Forms.ComboBox wallTypesComboBox;
private System.Windows.Forms.Label label10;
}
}
@@ -0,0 +1,197 @@
//
// (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 notify appears in all copies and
// that both that copyright notify and the limited warranty and
// restricted rights notify 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.Drawing;
using System.Text;
using System.Windows.Forms;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace Revit.SDK.Samples.TransactionControl.CS
{
/// <summary>
/// A Form used to create a wall
/// </summary>
public partial class CreateWallForm : System.Windows.Forms.Form
{
/// <summary>
/// A reference to the external command data.
/// </summary>
private ExternalCommandData m_commandData;
/// <summary>
/// The created wall
/// </summary>
private Wall m_createdWall = null;
/// <summary>
/// The created wall
/// </summary>
public Wall CreatedWall
{
get
{
return m_createdWall;
}
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="commandData">the external command data</param>
public CreateWallForm(ExternalCommandData commandData)
{
InitializeComponent();
m_commandData = commandData;
Initialize();
}
/// <summary>
/// do some initialization work: get all levels and wall types in active document
/// and add them to combo box
/// </summary>
private void Initialize()
{
//add levels to combo box levelsComboBox
Document document = m_commandData.Application.ActiveUIDocument.Document;
FilteredElementCollector collector = new FilteredElementCollector(document);
ElementClassFilter filter = new ElementClassFilter(typeof(Level));
IList<Element> levels = collector.WherePasses(filter).ToElements();
foreach (Element element in levels)
{
Level level = element as Level;
if (level != null)
{
this.levelsComboBox.Items.Add(level);
}
}
if (this.levelsComboBox.Items.Count > 0)
{
this.levelsComboBox.DisplayMember = "Name";
this.levelsComboBox.SelectedIndex = 0;
}
//add wall types to combo box wallTypesComboBox
FilteredElementCollector filteredElementCollector = new FilteredElementCollector(document);
filteredElementCollector.OfClass(typeof(WallType));
foreach (Element element in filteredElementCollector)
{
WallType wallType = element as WallType;
if (null == wallType)
{
continue;
}
this.wallTypesComboBox.Items.Add(wallType);
}
if (this.wallTypesComboBox.Items.Count > 0)
{
this.wallTypesComboBox.DisplayMember = "Name";
this.wallTypesComboBox.SelectedIndex = 0;
}
}
/// <summary>
/// try to create a wall. if failed, keep this dialog,
/// otherwise, close it.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void okButton_Click(object sender, EventArgs e)
{
try
{
Document document = m_commandData.Application.ActiveUIDocument.Document;
double x, y, z;
Autodesk.Revit.DB.XYZ sPoint;
//try to convert string to double, and return without closing dialog if failed
if (Double.TryParse(this.spXTextBox.Text, out x) &&
Double.TryParse(this.spYTextBox.Text, out y) &&
Double.TryParse(this.spZTextBox.Text, out z))
{
sPoint = new Autodesk.Revit.DB.XYZ(x, y, z);
}
else
{
TaskDialog.Show("Revit", "Failed to get the start point.");
return;
}
//try to convert string to double, and return without closing dialog if failed
Autodesk.Revit.DB.XYZ ePoint;
if (Double.TryParse(this.epXTextBox.Text, out x) &&
Double.TryParse(this.epYTextBox.Text, out y) &&
Double.TryParse(this.epZTextBox.Text, out z))
{
ePoint = new Autodesk.Revit.DB.XYZ(x, y, z);
}
else
{
TaskDialog.Show("Revit", "Failed to get the end point.");
return;
}
if (sPoint.IsAlmostEqualTo(ePoint))
{
TaskDialog.Show("Revit", "The start point and end point cannot have the same location.");
return;
}
Autodesk.Revit.DB.Line line = Line.CreateBound(sPoint, ePoint);
Level level = this.levelsComboBox.SelectedItem as Level;
WallType wallType = this.wallTypesComboBox.SelectedItem as WallType;
//check whether parameters used to create wall are not null
if (null == line)
{
TaskDialog.Show("Revit", "Create line failed.");
return;
}
if (null == level || null == wallType)
{
TaskDialog.Show("Revit", "Please select a level and a wall type.");
return;
}
m_createdWall = Wall.Create(document, line, wallType.Id, level.Id, 10, 0, true, true);
document.Regenerate();
this.DialogResult = DialogResult.OK;
this.Close();
}
catch (Exception ex)
{
TaskDialog.Show("Revit", ex.Message);
}
}
}
}
@@ -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>
@@ -0,0 +1,35 @@
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("TransactionControl")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TransactionControl")]
[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("18f5d6d3-6f43-40cd-b274-b0f286625e08")]
// 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")]
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
<AddIn Type="Command">
<Assembly>TransactionControl.dll</Assembly>
<ClientId>10b2e247-76d9-42a3-acd5-0b5a5fcc4964</ClientId>
<FullClassName>Revit.SDK.Samples.TransactionControl.CS.Command</FullClassName>
<Text>TransactionControl</Text>
<Description>Demonstrate how to use transaction control.</Description>
<VisibilityMode>AlwaysVisible</VisibilityMode>
<VendorId>ADSK</VendorId>
<VendorDescription>Autodesk, www.autodesk.com</VendorDescription>
</AddIn>
</RevitAddIns>
@@ -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>{CABE1E71-BAD8-4B8F-9001-D9D2A484F146}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TransactionControl</RootNamespace>
<AssemblyName>TransactionControl</AssemblyName>
<TargetFrameworkVersion>v4.7</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>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<DocumentationFile>
</DocumentationFile>
</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="CreateWallForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="CreateWallForm.Designer.cs">
<DependentUpon>CreateWallForm.cs</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TransactionForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="TransactionForm.Designer.cs">
<DependentUpon>TransactionForm.cs</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="CreateWallForm.resx">
<SubType>Designer</SubType>
<DependentUpon>CreateWallForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="TransactionForm.resx">
<SubType>Designer</SubType>
<DependentUpon>TransactionForm.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>
@@ -0,0 +1,271 @@
//
// (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 notify appears in all copies and
// that both that copyright notify and the limited warranty and
// restricted rights notify 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.TransactionControl.CS
{
partial class TransactionForm
{
/// <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.btnOK = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.groupBoxTrans = new System.Windows.Forms.GroupBox();
this.btnRollbackTrans = new System.Windows.Forms.Button();
this.btnCommitTrans = new System.Windows.Forms.Button();
this.btnStartTrans = new System.Windows.Forms.Button();
this.groupBoxOperation = new System.Windows.Forms.GroupBox();
this.btnDeleteWall = new System.Windows.Forms.Button();
this.btnMoveWall = new System.Windows.Forms.Button();
this.btnCreateWall = new System.Windows.Forms.Button();
this.transactionsTreeView = new System.Windows.Forms.TreeView();
this.btnRollbackTransGroup = new System.Windows.Forms.Button();
this.groupBoxTransGroup = new System.Windows.Forms.GroupBox();
this.btnCommitTransGroup = new System.Windows.Forms.Button();
this.btnStartTransGroup = new System.Windows.Forms.Button();
this.groupBoxTrans.SuspendLayout();
this.groupBoxOperation.SuspendLayout();
this.groupBoxTransGroup.SuspendLayout();
this.SuspendLayout();
//
// btnOK
//
this.btnOK.Location = new System.Drawing.Point(262, 381);
this.btnOK.Name = "btnOK";
this.btnOK.Size = new System.Drawing.Size(75, 23);
this.btnOK.TabIndex = 7;
this.btnOK.Text = "&OK";
this.btnOK.UseVisualStyleBackColor = true;
this.btnOK.Click += new System.EventHandler(this.okButton_Click);
//
// btnCancel
//
this.btnCancel.Location = new System.Drawing.Point(343, 381);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(75, 23);
this.btnCancel.TabIndex = 8;
this.btnCancel.Text = "&Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new System.EventHandler(this.cancelButton_Click);
//
// groupBoxTrans
//
this.groupBoxTrans.Controls.Add(this.btnRollbackTrans);
this.groupBoxTrans.Controls.Add(this.btnCommitTrans);
this.groupBoxTrans.Controls.Add(this.btnStartTrans);
this.groupBoxTrans.Location = new System.Drawing.Point(13, 131);
this.groupBoxTrans.Name = "groupBoxTrans";
this.groupBoxTrans.Size = new System.Drawing.Size(115, 111);
this.groupBoxTrans.TabIndex = 9;
this.groupBoxTrans.TabStop = false;
this.groupBoxTrans.Text = "Transaction";
//
// btnRollbackTrans
//
this.btnRollbackTrans.Location = new System.Drawing.Point(20, 48);
this.btnRollbackTrans.Name = "btnRollbackTrans";
this.btnRollbackTrans.Size = new System.Drawing.Size(75, 23);
this.btnRollbackTrans.TabIndex = 2;
this.btnRollbackTrans.Text = "&Rollback";
this.btnRollbackTrans.UseVisualStyleBackColor = true;
this.btnRollbackTrans.Click += new System.EventHandler(this.rollbackTransButton_Click);
//
// btnCommitTrans
//
this.btnCommitTrans.Location = new System.Drawing.Point(20, 77);
this.btnCommitTrans.Name = "btnCommitTrans";
this.btnCommitTrans.Size = new System.Drawing.Size(75, 23);
this.btnCommitTrans.TabIndex = 1;
this.btnCommitTrans.Text = "&Commit";
this.btnCommitTrans.UseVisualStyleBackColor = true;
this.btnCommitTrans.Click += new System.EventHandler(this.commitTransButton_Click);
//
// btnStartTrans
//
this.btnStartTrans.Location = new System.Drawing.Point(20, 19);
this.btnStartTrans.Name = "btnStartTrans";
this.btnStartTrans.Size = new System.Drawing.Size(75, 23);
this.btnStartTrans.TabIndex = 0;
this.btnStartTrans.Text = "&Start";
this.btnStartTrans.UseVisualStyleBackColor = true;
this.btnStartTrans.Click += new System.EventHandler(this.startTransButton_Click);
//
// groupBoxOperation
//
this.groupBoxOperation.Controls.Add(this.btnDeleteWall);
this.groupBoxOperation.Controls.Add(this.btnMoveWall);
this.groupBoxOperation.Controls.Add(this.btnCreateWall);
this.groupBoxOperation.Location = new System.Drawing.Point(13, 248);
this.groupBoxOperation.Name = "groupBoxOperation";
this.groupBoxOperation.Size = new System.Drawing.Size(115, 110);
this.groupBoxOperation.TabIndex = 10;
this.groupBoxOperation.TabStop = false;
this.groupBoxOperation.Text = "Operations";
//
// btnDeleteWall
//
this.btnDeleteWall.Location = new System.Drawing.Point(20, 77);
this.btnDeleteWall.Name = "btnDeleteWall";
this.btnDeleteWall.Size = new System.Drawing.Size(75, 23);
this.btnDeleteWall.TabIndex = 2;
this.btnDeleteWall.Text = "&Delete Wall";
this.btnDeleteWall.UseVisualStyleBackColor = true;
this.btnDeleteWall.Click += new System.EventHandler(this.deleteWallButton_Click);
//
// btnMoveWall
//
this.btnMoveWall.Location = new System.Drawing.Point(20, 48);
this.btnMoveWall.Name = "btnMoveWall";
this.btnMoveWall.Size = new System.Drawing.Size(75, 23);
this.btnMoveWall.TabIndex = 1;
this.btnMoveWall.Text = "&Move Wall";
this.btnMoveWall.UseVisualStyleBackColor = true;
this.btnMoveWall.Click += new System.EventHandler(this.moveWallButton_Click);
//
// btnCreateWall
//
this.btnCreateWall.Location = new System.Drawing.Point(20, 19);
this.btnCreateWall.Name = "btnCreateWall";
this.btnCreateWall.Size = new System.Drawing.Size(75, 23);
this.btnCreateWall.TabIndex = 0;
this.btnCreateWall.Text = "C&reate Wall";
this.btnCreateWall.UseVisualStyleBackColor = true;
this.btnCreateWall.Click += new System.EventHandler(this.createWallbutton_Click);
//
// transactionsTreeView
//
this.transactionsTreeView.Location = new System.Drawing.Point(136, 11);
this.transactionsTreeView.Name = "transactionsTreeView";
this.transactionsTreeView.Size = new System.Drawing.Size(282, 347);
this.transactionsTreeView.TabIndex = 11;
//
// btnRollbackTransGroup
//
this.btnRollbackTransGroup.Location = new System.Drawing.Point(20, 49);
this.btnRollbackTransGroup.Name = "btnRollbackTransGroup";
this.btnRollbackTransGroup.Size = new System.Drawing.Size(75, 23);
this.btnRollbackTransGroup.TabIndex = 0;
this.btnRollbackTransGroup.Text = "&Rollback";
this.btnRollbackTransGroup.UseVisualStyleBackColor = true;
this.btnRollbackTransGroup.Click += new System.EventHandler(this.btnRollbackTransGroup_Click);
//
// groupBoxTransGroup
//
this.groupBoxTransGroup.Controls.Add(this.btnCommitTransGroup);
this.groupBoxTransGroup.Controls.Add(this.btnStartTransGroup);
this.groupBoxTransGroup.Controls.Add(this.btnRollbackTransGroup);
this.groupBoxTransGroup.Location = new System.Drawing.Point(13, 11);
this.groupBoxTransGroup.Name = "groupBoxTransGroup";
this.groupBoxTransGroup.Size = new System.Drawing.Size(115, 112);
this.groupBoxTransGroup.TabIndex = 12;
this.groupBoxTransGroup.TabStop = false;
this.groupBoxTransGroup.Text = "Transaction Group";
//
// btnCommitTransGroup
//
this.btnCommitTransGroup.Location = new System.Drawing.Point(20, 78);
this.btnCommitTransGroup.Name = "btnCommitTransGroup";
this.btnCommitTransGroup.Size = new System.Drawing.Size(75, 23);
this.btnCommitTransGroup.TabIndex = 2;
this.btnCommitTransGroup.Text = "&Commit";
this.btnCommitTransGroup.UseVisualStyleBackColor = true;
this.btnCommitTransGroup.Click += new System.EventHandler(this.btnCommitTransGroup_Click);
//
// btnStartTransGroup
//
this.btnStartTransGroup.Location = new System.Drawing.Point(20, 20);
this.btnStartTransGroup.Name = "btnStartTransGroup";
this.btnStartTransGroup.Size = new System.Drawing.Size(75, 23);
this.btnStartTransGroup.TabIndex = 1;
this.btnStartTransGroup.Text = "&Start";
this.btnStartTransGroup.UseVisualStyleBackColor = true;
this.btnStartTransGroup.Click += new System.EventHandler(this.btnStartTransGroup_Click);
//
// TransactionForm
//
this.AcceptButton = this.btnOK;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.btnCancel;
this.ClientSize = new System.Drawing.Size(431, 413);
this.Controls.Add(this.groupBoxTransGroup);
this.Controls.Add(this.transactionsTreeView);
this.Controls.Add(this.groupBoxOperation);
this.Controls.Add(this.groupBoxTrans);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOK);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "TransactionForm";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Transaction";
this.groupBoxTrans.ResumeLayout(false);
this.groupBoxOperation.ResumeLayout(false);
this.groupBoxTransGroup.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.GroupBox groupBoxTrans;
private System.Windows.Forms.Button btnRollbackTrans;
private System.Windows.Forms.Button btnCommitTrans;
private System.Windows.Forms.Button btnStartTrans;
private System.Windows.Forms.GroupBox groupBoxOperation;
private System.Windows.Forms.Button btnDeleteWall;
private System.Windows.Forms.Button btnMoveWall;
private System.Windows.Forms.Button btnCreateWall;
private System.Windows.Forms.TreeView transactionsTreeView;
private System.Windows.Forms.Button btnRollbackTransGroup;
private System.Windows.Forms.GroupBox groupBoxTransGroup;
private System.Windows.Forms.Button btnCommitTransGroup;
private System.Windows.Forms.Button btnStartTransGroup;
}
}
@@ -0,0 +1,760 @@
//
// (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 notify appears in all copies and
// that both that copyright notify and the limited warranty and
// restricted rights notify 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.Drawing;
using System.Text;
using System.Windows.Forms;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace Revit.SDK.Samples.TransactionControl.CS
{
using SystemColor = System.Drawing.Color;
/// <summary>
/// A Form used to deal with transaction and create, move or delete a wall
/// </summary>
public partial class TransactionForm : System.Windows.Forms.Form
{
/// <summary>
/// An enum used to indicate which operation is executed
/// </summary>
private enum OperationType
{
StartTransactionGroup,
RollbackTransactionGroup,
CommitTransactionGroup,
StartTransaction,
CommitTransaction,
RollbackTransaction,
ObjectModification,
ObjectDeletion
}
/// <summary>
/// A reference to the external command data.
/// </summary>
private ExternalCommandData m_commandData;
/// <summary>
/// The active document
/// </summary>
private Document m_document;
/// <summary>
/// The root node of the operation tree
/// </summary>
private TreeNode m_rootNode;
/// <summary>
/// A reference to active transaction group node where sub transaction node will be added
/// </summary>
private TreeNode m_transGroupNode;
/// <summary>
/// A reference to the active sub transaction node
/// </summary>
private TreeNode m_transNode;
/// <summary>
/// fore color of tree node before a transaction is over
/// </summary>
private SystemColor m_startedColor = SystemColor.Green;
/// <summary>
/// fore color of tree node after ending a transaction
/// </summary>
private SystemColor m_committedColor = SystemColor.Black;
/// <summary>
/// fore color of tree node after aborting a transaction
/// </summary>
private SystemColor m_rolledbackColor = SystemColor.Gray;
/// <summary>
/// fore color of a tree node of a created or modified element
/// </summary>
private SystemColor m_normalColor = SystemColor.Blue;
/// <summary>
/// fore color of a tree node of a deleted element
/// </summary>
private SystemColor m_deletedColor = SystemColor.Red;
/// <summary>
/// The currently active transaction group
/// </summary>
private TransactionGroup m_transactionGroup = null;
/// The main, hidden outer transaction group
/// </summary>
private TransactionGroup m_mainTtransactionGroup = null;
/// <summary>
/// The active transaction
/// </summary>
private Transaction m_transaction = null;
/// <summary>
/// The number of transactions
/// </summary>
private int m_transCount = 0;
/// <summary>
/// The number of transaction groups
/// </summary>
private int m_transGroupCount = 0;
/// <summary>
/// The last created wall in the active transaction
/// </summary>
private Wall m_lastCreatedWall = null;
/// <summary>
/// Constructor
/// </summary>
/// <param name="commandData">the external command data</param>
public TransactionForm(ExternalCommandData commandData)
{
m_commandData = commandData;
m_document = m_commandData.Application.ActiveUIDocument.Document;
if (m_document == null)
{
TaskDialog.Show("Revit", "There is no active document.");
}
InitializeComponent();
// created the root node
m_rootNode = new TreeNode("Command history");
this.transactionsTreeView.Nodes.Add(m_rootNode);
// set availability of form buttons
UpdateButtonsStatus();
// start the main transaction group (will be hidden to the user)
m_mainTtransactionGroup = new TransactionGroup(m_document);
m_mainTtransactionGroup.Start();
}
/// <summary>
/// Begin a transaction, append transaction node to tree view
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void startTransButton_Click(object sender, EventArgs e)
{
int transNo = m_transCount + 1;
m_transaction = new Transaction(m_document, "Transaction " + transNo.ToString());
if (m_transaction.Start() == TransactionStatus.Started)
{
m_transCount++;
AddNode(OperationType.StartTransaction);
m_lastCreatedWall = null;
UpdateButtonsStatus();
}
else
{
m_transaction = null;
TaskDialog.Show("Revit", "Starting transaction failed");
}
}
/// <summary>
/// Commit a transaction
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void commitTransButton_Click(object sender, EventArgs e)
{
if ((m_transaction != null) && (m_transaction.GetStatus() == TransactionStatus.Started))
{
m_transaction.Commit();
if (m_transaction.HasEnded())
{
// in theory, committing a transaction can turn out to a be roll-back instead
// depending on how model failures, if any, are resolved by the user
if (m_transaction.GetStatus() == TransactionStatus.Committed)
AddNode(OperationType.CommitTransaction);
else
AddNode(OperationType.RollbackTransaction);
m_transaction = null;
m_lastCreatedWall = null;
UpdateButtonsStatus();
}
else
{
TaskDialog.Show("Revit", "Committing transaction failed");
}
}
}
/// <summary>
/// Rollback a transaction
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void rollbackTransButton_Click(object sender, EventArgs e)
{
if ((m_transaction != null) && (m_transaction.GetStatus() == TransactionStatus.Started))
{
if (m_transaction.RollBack() == TransactionStatus.RolledBack)
{
m_transaction = null;
m_lastCreatedWall = null;
AddNode(OperationType.RollbackTransaction);
UpdateButtonsStatus();
}
else
{
TaskDialog.Show("Revit", "Rolling Back transaction failed");
}
}
}
/// <summary>
/// Create a wall, append a node to tree view
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void createWallbutton_Click(object sender, EventArgs e)
{
// a sub-transaction is not necessary in this case
// it is used for illustration purposes only
using (SubTransaction subTransaction = new SubTransaction(m_document))
{
// if not handled explicitly, the sub-transaction will be rolled back when leaving this block
try
{
if (subTransaction.Start() == TransactionStatus.Started)
{
using (CreateWallForm createWallForm = new CreateWallForm(m_commandData))
{
createWallForm.ShowDialog();
if (DialogResult.OK == createWallForm.DialogResult)
{
updateModel(true); // immediately update the view to see the changes
if (subTransaction.Commit() == TransactionStatus.Committed)
{
m_lastCreatedWall = createWallForm.CreatedWall;
AddNode(OperationType.ObjectModification, "Created wall " + m_lastCreatedWall.Id.IntegerValue.ToString());
UpdateButtonsStatus();
return;
}
}
else
{
subTransaction.RollBack();
return;
}
}
}
}
catch (System.Exception ex)
{
TaskDialog.Show("Revit", "Exception when creating a wall: " + ex.Message);
}
}
TaskDialog.Show("Revit", "Creating wall failed");
}
/// <summary>
/// Move a wall, append a node to tree view
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void moveWallButton_Click(object sender, EventArgs e)
{
if (m_lastCreatedWall == null)
return;
// a sub-transaction is not necessary in this case
// it is used for illustration purposes only
using (SubTransaction subTransaction = new SubTransaction(m_document))
{
// if not handled explicitly, the sub-transaction will be rolled back when leaving this block
try
{
if (subTransaction.Start() == TransactionStatus.Started)
{
Autodesk.Revit.DB.XYZ translationVec = new Autodesk.Revit.DB.XYZ(10, 10, 0);
ElementTransformUtils.MoveElement(m_document, m_lastCreatedWall.Id, translationVec);
updateModel(true); // immediately update the view to see the changes
if (subTransaction.Commit() == TransactionStatus.Committed)
{
AddNode(OperationType.ObjectModification, "Moved wall " + m_lastCreatedWall.Id.IntegerValue.ToString());
return;
}
}
}
catch (System.Exception ex)
{
TaskDialog.Show("Revit", "Exception when moving a wall: " + ex.Message);
}
}
TaskDialog.Show("Revit", "Moving wall failed.");
}
/// <summary>
/// Delete a wall, append a node to tree view
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void deleteWallButton_Click(object sender, EventArgs e)
{
if (m_lastCreatedWall == null)
return;
// a sub-transaction is not necessary in this case
// it is used for illustration purposes only
using (SubTransaction subTransaction = new SubTransaction(m_document))
{
// if not handled explicitly, the sub-transaction will be rolled back when leaving this block
try
{
String wallId = m_lastCreatedWall.Id.IntegerValue.ToString();
if (TaskDialogResult.No ==
TaskDialog.Show("Warning", "Do you really want to delete wall with id " + wallId + "?",
TaskDialogCommonButtons.Yes | TaskDialogCommonButtons.No))
{
return;
}
if (subTransaction.Start() == TransactionStatus.Started)
{
m_document.Delete(m_lastCreatedWall.Id);
updateModel(false); // immediately update the view to see the changes
if (subTransaction.Commit() == TransactionStatus.Committed)
{
AddNode(OperationType.ObjectDeletion, "Deleted wall " + wallId);
m_lastCreatedWall = null;
UpdateButtonsStatus();
return;
}
}
}
catch (System.Exception ex)
{
TaskDialog.Show("Revit", "Exception when deleting a wall: " + ex.Message);
}
}
TaskDialog.Show("Revit", "Deleting wall failed.");
}
/// <summary>
/// Start transaction group button click event
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnStartTransGroup_Click(object sender, EventArgs e)
{
m_transGroupCount++;
m_transactionGroup = new TransactionGroup(m_document, "Transaction Group " + m_transGroupCount.ToString());
m_transactionGroup.Start();
AddNode(OperationType.StartTransactionGroup);
UpdateButtonsStatus();
}
/// <summary>
/// Commit transaction group button click event
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnCommitTransGroup_Click(object sender, EventArgs e)
{
if (m_transactionGroup != null)
{
m_transactionGroup.Commit();
AddNode(OperationType.CommitTransactionGroup);
m_transaction = null;
m_lastCreatedWall = null;
UpdateButtonsStatus();
}
}
/// <summary>
/// Rollback transaction group button click event
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnRollbackTransGroup_Click(object sender, EventArgs e)
{
if (m_transactionGroup != null)
{
m_transactionGroup.RollBack();
AddNode(OperationType.RollbackTransactionGroup);
m_transaction = null;
m_lastCreatedWall = null;
UpdateButtonsStatus();
}
}
/// <summary>
/// Accept the changes and and close this form
/// </summary>
/// <remarks>If any transaction group or the active transaction is still open
/// give the user the option to either commit them or roll them back first.</remarks>
/// <param name="sender"></param>
/// <param name="e"></param>
private void okButton_Click(object sender, EventArgs e)
{
//if any transaction or transaction group is not finished, notify user to deal with it
if (null != m_transaction || null != m_transactionGroup)
{
TaskDialogResult dialogResult =
TaskDialog.Show("Warning", "Some transaction groups or the active transaction is not committed."
+ " Choose Yes to commit them, or No to roll them back.", TaskDialogCommonButtons.Yes | TaskDialogCommonButtons.No | TaskDialogCommonButtons.Cancel);
if (TaskDialogResult.Cancel == dialogResult)
{
return;
}
else if (TaskDialogResult.Yes == dialogResult)
{
if (m_transaction != null && (m_transaction.GetStatus() == TransactionStatus.Started))
{
m_transaction.Commit();
}
HandleNestedTransactionGroups(OperationType.CommitTransactionGroup);
}
else
{
if (m_transaction != null && (m_transaction.GetStatus() == TransactionStatus.Started))
{
m_transaction.RollBack();
}
HandleNestedTransactionGroups(OperationType.RollbackTransactionGroup);
}
}
// silently commit the main (hidden) transaction group
if ((null != m_mainTtransactionGroup) && (m_mainTtransactionGroup.GetStatus() == TransactionStatus.Started))
{
m_mainTtransactionGroup.SetName("SDK Transaction Sample");
m_mainTtransactionGroup.Assimilate();
}
this.DialogResult = DialogResult.OK;
this.Close();
}
/// <summary>
/// Rollback all changes and close this form
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void cancelButton_Click(object sender, EventArgs e)
{
if (m_transCount > 0)
{
if (TaskDialogResult.No ==
TaskDialog.Show("Warning", "By canceling this dialog, all modifications to the model will be discarded."
+ " Do you want to proceed?", TaskDialogCommonButtons.Yes | TaskDialogCommonButtons.No))
{
this.DialogResult = DialogResult.None;
return;
}
}
// if there is still an active transaction, roll it back now, silently
if ((null != m_transaction) && (m_transaction.GetStatus() == TransactionStatus.Started))
{
m_transaction.RollBack();
}
// if there are still transaction groups open, roll them back now, silently
if ((null != m_transactionGroup) && (m_transactionGroup.GetStatus() == TransactionStatus.Started))
{
HandleNestedTransactionGroups(OperationType.RollbackTransactionGroup);
}
// silently roll back the main (hidden) transaction group
if ((null != m_mainTtransactionGroup) && (m_mainTtransactionGroup.GetStatus() == TransactionStatus.Started))
{
m_mainTtransactionGroup.RollBack();
}
this.DialogResult = DialogResult.Cancel;
this.Close();
}
/// <summary>
/// Commit or rollback nested transaction groups
/// </summary>
/// <param name="operationType">The operation type determines whether to commit or to rollback transaction groups</param>
private void HandleNestedTransactionGroups(OperationType operationType)
{
while (m_transactionGroup != null)
{
if (operationType.Equals(OperationType.CommitTransactionGroup))
{
m_transactionGroup.Commit();
}
else
{
m_transactionGroup.RollBack();
}
if (m_transactionGroup.HasEnded())
{
m_transGroupNode = m_transGroupNode.Parent;
if (m_transGroupNode.Equals(m_rootNode))
{
m_transactionGroup = null;
}
else
{
m_transactionGroup = m_transGroupNode.Tag as TransactionGroup;
}
}
else
{
throw new System.ApplicationException("Could not end a transaction group");
}
}
}
/// <summary>
/// Update form buttons depending on the status of existing transaction and groups
/// </summary>
private void UpdateButtonsStatus()
{
// there can be only one active transaction at any given time
btnStartTrans.Enabled = (m_transaction == null);
// only active transaction can be committed
btnCommitTrans.Enabled = ((m_transaction != null) && (m_transaction.GetStatus() == TransactionStatus.Started));
// the same rule applies to rolling back a transaction
btnRollbackTrans.Enabled = btnCommitTrans.Enabled;
// transaction group cannot be started inside an active transaction
btnStartTransGroup.Enabled = (m_transaction == null);
// transaction group cannot be committed while still inside an active transaction
// also, the group must be active in order to be committed
btnCommitTransGroup.Enabled = ((m_transaction == null) && (m_transactionGroup != null) && (m_transactionGroup.GetStatus() == TransactionStatus.Started));
// the same rule applies to rolling back a transaction group
btnRollbackTransGroup.Enabled = btnCommitTransGroup.Enabled;
// wall can be created only in an active transaction
btnCreateWall.Enabled = btnCommitTrans.Enabled;
// the same rule applies to deleting a wall, plus, naturally, the wall must exist
btnDeleteWall.Enabled = (btnCreateWall.Enabled && (m_lastCreatedWall != null));
// the same applies to moving a wall
btnMoveWall.Enabled = btnDeleteWall.Enabled;
}
/// <summary>
/// add node to tree view control
/// </summary>
/// <param name="type">indicate operation type</param>
private void AddNode(OperationType type)
{
AddNode(type, null);
}
/// <summary>
/// add node to tree view control
/// </summary>
/// <param name="type">indicate operation type</param>
/// <param name="info">tree node text</param>
private void AddNode(OperationType type, string info)
{
//add tree node according to operation type
if (type == OperationType.StartTransactionGroup)
{
if (m_transGroupNode == null)
{
m_transGroupNode = new TreeNode(m_transactionGroup.GetName());
int index = m_rootNode.Nodes.Add(m_transGroupNode);
m_rootNode.Nodes[index].Tag = m_transactionGroup;
m_rootNode.Expand();
UpdateTreeNode(m_transGroupNode, type);
}
else
{
TreeNode newTransGroupNode = new TreeNode(m_transactionGroup.GetName());
int index = m_transGroupNode.Nodes.Add(newTransGroupNode);
m_transGroupNode.Nodes[index].Tag = m_transactionGroup;
m_transGroupNode.Expand();
m_transGroupNode = newTransGroupNode;
m_transGroupNode.Expand();
UpdateTreeNode(m_transGroupNode, type);
}
m_transNode = null;
m_transaction = null;
}
else if (type == OperationType.RollbackTransactionGroup)
{
UpdateTreeNode(m_transGroupNode, type);
if (m_transGroupNode.Parent.Equals(m_rootNode))
{
m_rootNode.Expand();
m_transactionGroup = null;
m_transGroupNode = null;
}
else
{
m_transGroupNode = m_transGroupNode.Parent;
m_transGroupNode.Expand();
m_transactionGroup = m_transGroupNode.Tag as TransactionGroup;
}
m_transNode = null;
m_transaction = null;
}
else if (type == OperationType.CommitTransactionGroup)
{
UpdateTreeNode(m_transGroupNode, type);
if (m_transGroupNode.Parent.Equals(m_rootNode))
{
m_rootNode.Expand();
m_transactionGroup = null;
m_transGroupNode = null;
}
else
{
m_transGroupNode.Expand();
m_transGroupNode = m_transGroupNode.Parent;
m_transactionGroup = m_transGroupNode.Tag as TransactionGroup;
}
m_transNode = null;
m_transaction = null;
}
else if (type == OperationType.StartTransaction)
{
m_transNode = new TreeNode(m_transaction.GetName());
m_transNode.ForeColor = m_startedColor;
TreeNode node = m_transGroupNode == null ? m_rootNode : m_transGroupNode;
node.Nodes.Add(m_transNode);
node.Expand();
UpdateTreeNode(m_transNode, type);
}
else if (type == OperationType.CommitTransaction)
{
UpdateTreeNode(m_transNode, type);
TreeNode node = m_transGroupNode == null ? m_rootNode : m_transGroupNode;
node.Expand();
m_transNode = null;
}
else if (type == OperationType.RollbackTransaction)
{
UpdateTreeNode(m_transNode, type);
TreeNode node = m_transGroupNode == null ? m_rootNode : m_transGroupNode;
node.Expand();
m_transNode = null;
}
else
{
string childNodeText = null;
if (String.IsNullOrEmpty(info))
{
childNodeText = "Operation";
}
else
{
childNodeText = info;
}
TreeNode childNode = new TreeNode(childNodeText);
if (type == OperationType.ObjectDeletion)
childNode.ForeColor = m_deletedColor;
else
childNode.ForeColor = m_normalColor;
m_transNode.Nodes.Add(childNode);
m_transNode.Expand();
}
}
/// <summary>
/// Update the color of a tree node
/// </summary>
/// <param name="parentNode">indicate child nodes of which will be updated</param>
/// <param name="type">operation type</param>
private void UpdateTreeNode(TreeNode parentNode, OperationType type)
{
switch (type)
{
case OperationType.StartTransaction:
case OperationType.StartTransactionGroup:
UpdateTreeNode(parentNode, m_startedColor);
break;
case OperationType.RollbackTransaction:
case OperationType.RollbackTransactionGroup:
UpdateTreeNode(parentNode, m_rolledbackColor);
break;
case OperationType.CommitTransaction:
case OperationType.CommitTransactionGroup:
UpdateTreeNode(parentNode, m_committedColor);
break;
default:
UpdateTreeNode(parentNode, m_normalColor);
break;
}
}
/// <summary>
/// Update the color of tree node including all its sub-nodes
/// </summary>
/// <param name="parentNode">the node of which color will be updated</param>
/// <param name="color">Color to change</param>
private void UpdateTreeNode(TreeNode parentNode, SystemColor color)
{
parentNode.ForeColor = color;
foreach (TreeNode childNode in parentNode.Nodes)
{
if (childNode.ForeColor == m_rolledbackColor)
{
continue;
}
UpdateTreeNode(childNode, color);
}
}
/// <summary>
/// Updates the model and refreshes the active view
/// </summary>
/// <param name="autoJoin">Whether to also perform auto-join or not</param>
private void updateModel(bool autoJoin)
{
// in order to be able to see changes to the model before
// the current transaction is committed, we have to regenerate
// the model manually.
m_document.Regenerate();
// auto-joining is optional, but may be necessary to see connection details.
if (autoJoin)
{
m_document.AutoJoinElements();
}
// to see the changes immediately, we need to refresh the view
m_commandData.Application.ActiveUIDocument.RefreshActiveView();
}
}
}
@@ -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>