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
@@ -0,0 +1,84 @@
//
// (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.Linq;
using System.Text;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using RApplication = Autodesk.Revit.ApplicationServices.Application;
namespace Revit.SDK.Samples.UIAPI.CS
{
/// <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>
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class PreviewCommand : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
_dbdocument = commandData.Application.ActiveUIDocument.Document;
TransactionGroup outerGroup = new TransactionGroup(_dbdocument, "preview control");
outerGroup.Start();
try
{
PreviewModel form = new PreviewModel(commandData.Application.Application, new ElementId(-1));
form.ShowDialog();
}
catch (Exception e)
{
throw e;
}
finally
{
outerGroup.RollBack();
}
return Result.Succeeded;
}
private Document _dbdocument = null;
}
}
@@ -0,0 +1,142 @@
namespace Revit.SDK.Samples.UIAPI.CS
{
partial class PreviewModel
{
/// <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.panel1 = new System.Windows.Forms.Panel();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this._cbDocuments = new System.Windows.Forms.ComboBox();
this._cbViews = new System.Windows.Forms.ComboBox();
this._elementHostWPF = new System.Windows.Forms.Integration.ElementHost();
this.panel2 = new System.Windows.Forms.Panel();
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.Controls.Add(this._elementHostWPF);
this.panel1.Controls.Add(this.panel2);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(467, 452);
this.panel1.TabIndex = 0;
//
// label2
//
this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(266, 20);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(38, 13);
this.label2.TabIndex = 4;
this.label2.Text = "Views:";
//
// label1
//
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(9, 20);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(64, 13);
this.label1.TabIndex = 3;
this.label1.Text = "Documents:";
//
// _cbDocuments
//
this._cbDocuments.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this._cbDocuments.FormattingEnabled = true;
this._cbDocuments.Location = new System.Drawing.Point(12, 56);
this._cbDocuments.Name = "_cbDocuments";
this._cbDocuments.Size = new System.Drawing.Size(183, 21);
this._cbDocuments.TabIndex = 2;
this._cbDocuments.SelectedIndexChanged += new System.EventHandler(this.cbDocs_SelIdxChanged);
//
// _cbViews
//
this._cbViews.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this._cbViews.FormattingEnabled = true;
this._cbViews.Location = new System.Drawing.Point(269, 56);
this._cbViews.Name = "_cbViews";
this._cbViews.Size = new System.Drawing.Size(183, 21);
this._cbViews.TabIndex = 1;
this._cbViews.SelectedIndexChanged += new System.EventHandler(this.cbViews_SelIdxChanged);
//
// _elementHostWPF
//
this._elementHostWPF.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this._elementHostWPF.Location = new System.Drawing.Point(0, 0);
this._elementHostWPF.Name = "_elementHostWPF";
this._elementHostWPF.Size = new System.Drawing.Size(467, 367);
this._elementHostWPF.TabIndex = 0;
this._elementHostWPF.Text = "elementHost1";
this._elementHostWPF.Child = null;
//
// panel2
//
this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel2.Controls.Add(this._cbViews);
this.panel2.Controls.Add(this.label2);
this.panel2.Controls.Add(this._cbDocuments);
this.panel2.Controls.Add(this.label1);
this.panel2.Location = new System.Drawing.Point(3, 363);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(461, 89);
this.panel2.TabIndex = 5;
//
// PreviewModel
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(467, 452);
this.Controls.Add(this.panel1);
this.Name = "PreviewModel";
this.Text = "PreviewModel";
this.panel1.ResumeLayout(false);
this.panel2.ResumeLayout(false);
this.panel2.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.ComboBox _cbViews;
private System.Windows.Forms.Integration.ElementHost _elementHostWPF;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ComboBox _cbDocuments;
private System.Windows.Forms.Panel panel2;
}
}
@@ -0,0 +1,247 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using RView = Autodesk.Revit.DB.View;
using RApplication = Autodesk.Revit.ApplicationServices.Application;
namespace Revit.SDK.Samples.UIAPI.CS
{
public partial class PreviewModel : System.Windows.Forms.Form
{
public PreviewModel(RApplication application, ElementId viewId)
{
InitializeComponent();
_application = application;
_uiApplication = new UIApplication(application);
_dbDocument = _uiApplication.ActiveUIDocument.Document;
updateDocumentList(_dbDocument);
updateViewsList(_uiApplication.ActiveUIDocument.ActiveView.Id);
}
private void updateViewsList(ElementId viewId)
{
// fill the combobox with printable views <name + id>
FilteredElementCollector collecotr = new FilteredElementCollector(_dbDocument);
collecotr.OfClass(typeof(Autodesk.Revit.DB.View));
IEnumerable<Autodesk.Revit.DB.View> secs = from Element f in collecotr where (f as Autodesk.Revit.DB.View).CanBePrinted == true select f as Autodesk.Revit.DB.View;
_cbViews.Items.Clear();
DBViewItem activeItem = null;
foreach (Autodesk.Revit.DB.View dbView in secs)
{
if (viewId == null || viewId.IntegerValue < 0)
{
activeItem = new DBViewItem(dbView, _dbDocument);
viewId = dbView.Id;
}
if (dbView.Id == viewId)
{
activeItem = new DBViewItem(dbView, _dbDocument);
_cbViews.Items.Add(activeItem);
}
else
_cbViews.Items.Add(new DBViewItem(dbView, _dbDocument));
}
_cbViews.SelectedItem = activeItem;
}
private void updateDocumentList(Document selectedDocument)
{
// fill the documents to the comboxbox _cbDocuments.
DBDocumentItem activeItem = null;
_cbDocuments.Items.Clear();
DocumentSetIterator docIter = _application.Documents.ForwardIterator();
docIter.Reset();
while (docIter.MoveNext())
{
Document dbDoc = docIter.Current as Document;
String documentName = null;
DBDocumentItem item = null;
if (dbDoc != null)
{
if (dbDoc.IsFamilyDocument)
{
item = new DBDocumentItem(dbDoc.PathName, dbDoc);
}
else
{
String projName = dbDoc.ProjectInformation.Name;
if (String.IsNullOrEmpty(projName) || projName.ToLower().CompareTo("project name") == 0)
{
if (String.IsNullOrEmpty(dbDoc.PathName))
documentName = projName;
else
documentName = new System.IO.FileInfo(dbDoc.PathName).Name;
}
else
documentName = projName;
item = new DBDocumentItem(documentName, dbDoc);
}
if (dbDoc.Equals(selectedDocument))
{
_dbDocument = selectedDocument;
activeItem = item;
}
_cbDocuments.Items.Add(item);
}
}
_cbDocuments.Items.Add(new DBDocumentItem());
_cbDocuments.SelectedItem = activeItem;
}
private void cbViews_SelIdxChanged(object sender, EventArgs e)
{
System.Windows.Forms.ComboBox cb = sender as System.Windows.Forms.ComboBox;
if (cb == null)
return;
DBViewItem dbItem = cb.SelectedItem as DBViewItem;
if (dbItem == null)
return;
//if (_currentDBViewId == null)
// return;
//RView currentView = _dbDocument.get_Element(_currentDBViewId) as RView;
//if(currentView == null)
// return;
//if (dbItem.UniqueId.ToLower().CompareTo(currentView.UniqueId.ToLower()) != 0)
// return;
PreviewControl vc = _elementHostWPF.Child as PreviewControl;
if (vc != null)
vc.Dispose();
_elementHostWPF.Child = new PreviewControl(_dbDocument, dbItem.Id);
_currentDBViewId = dbItem.Id;
}
private ElementId _currentDBViewId = null;
private Document _dbDocument = null;
private RApplication _application = null;
private UIApplication _uiApplication = null;
private void cbDocs_SelIdxChanged(object sender, EventArgs e)
{
DBDocumentItem documentItem = _cbDocuments.SelectedItem as DBDocumentItem;
if (documentItem.Document == _dbDocument)
return;
if (documentItem.IsNull)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.DefaultExt = "rvt";
ofd.Filter = "Revit project files (*.rvt)|*.rvt|Revit family files (*.rfa)|*.rfa|Revit family template files (*.rft)|*.rft";
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
try
{
_dbDocument = _application.OpenDocumentFile(ofd.FileName);
}
catch (System.Exception)
{
}
if (_dbDocument != null)
{
updateDocumentList(_dbDocument);
updateViewsList(null);
}
}
else
{
// the combobox should show the current document item.
String documentName;
String projName = _dbDocument.ProjectInformation.Name;
if (String.IsNullOrEmpty(projName) || projName.ToLower().CompareTo("project name") == 0)
{
if (String.IsNullOrEmpty(_dbDocument.PathName))
documentName = projName;
else
documentName = new System.IO.FileInfo(_dbDocument.PathName).Name;
}
else
documentName = projName;
foreach (DBDocumentItem dbItem in _cbDocuments.Items)
{
if (dbItem.Name.ToLower().CompareTo(documentName.ToLower()) == 0)
{
_cbDocuments.SelectedItem = dbItem;
break;
}
}
}
}
else
{
_dbDocument = documentItem.Document;
updateViewsList(null);
}
}
}
public class DBViewItem
{
public DBViewItem(RView dbView, Document dbDoc)
{
ElementType viewType = dbDoc.GetElement(dbView.GetTypeId()) as ElementType;
Name = viewType.Name + " " + dbView.Name;
Id = dbView.Id;
UniqueId = dbView.UniqueId;
}
public override String ToString()
{
return Name;
}
public String Name { get; set; }
public ElementId Id { get; set; }
public String UniqueId { get; set; }
}
public class DBDocumentItem
{
public DBDocumentItem(String name, Document doc)
{
Name = name;
Document = doc;
IsNull = false;
}
public DBDocumentItem()
{
IsNull = true;
}
public override string ToString()
{
if (IsNull)
return "<Open Document...>";
return Name;
}
public bool IsNull { get; set; }
public String Name { get; set; }
public Document Document { get; set; }
}
}
@@ -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=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>