mirror of
https://github.com/jeremytammik/RevitSdkSamples.git
synced 2026-08-15 18:14:02 +00:00
added Revit 2020 SDK files
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
namespace Revit.SDK.Samples.UIAPI.CS
|
||||
{
|
||||
partial class FurnitureFamilyDragAndDropForm
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem("Content 1");
|
||||
System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem("Content 2");
|
||||
this.listView1 = new System.Windows.Forms.ListView();
|
||||
this.listBox1 = new System.Windows.Forms.ListBox();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// listView1
|
||||
//
|
||||
this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
|
||||
listViewItem1,
|
||||
listViewItem2});
|
||||
this.listView1.Location = new System.Drawing.Point(12, 38);
|
||||
this.listView1.MultiSelect = false;
|
||||
this.listView1.Name = "listView1";
|
||||
this.listView1.Size = new System.Drawing.Size(729, 380);
|
||||
this.listView1.TabIndex = 1;
|
||||
this.listView1.UseCompatibleStateImageBehavior = false;
|
||||
this.listView1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.listView_MouseMove);
|
||||
//
|
||||
// listBox1
|
||||
//
|
||||
this.listBox1.FormattingEnabled = true;
|
||||
this.listBox1.Location = new System.Drawing.Point(757, 38);
|
||||
this.listBox1.Name = "listBox1";
|
||||
this.listBox1.Size = new System.Drawing.Size(216, 381);
|
||||
this.listBox1.TabIndex = 2;
|
||||
this.listBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.listBox1_MouseMove);
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(12, 13);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(153, 13);
|
||||
this.label1.TabIndex = 3;
|
||||
this.label1.Text = "Loaded furniture family symbols";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(757, 13);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(132, 13);
|
||||
this.label2.TabIndex = 4;
|
||||
this.label2.Text = "Load new furniture families";
|
||||
//
|
||||
// FurnitureFamilyDragAndDropForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1004, 430);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Controls.Add(this.listBox1);
|
||||
this.Controls.Add(this.listView1);
|
||||
this.Name = "FurnitureFamilyDragAndDropForm";
|
||||
this.Text = "DragAndDrop";
|
||||
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.FurnitureFamilyDragAndDropForm_FormClosed);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.ListView listView1;
|
||||
private System.Windows.Forms.ListBox listBox1;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.Label label2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
//
|
||||
// (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.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI;
|
||||
|
||||
namespace Revit.SDK.Samples.UIAPI.CS
|
||||
{
|
||||
public partial class FurnitureFamilyDragAndDropForm : System.Windows.Forms.Form
|
||||
{
|
||||
public static BuiltInCategory FamilyCategory
|
||||
{
|
||||
get
|
||||
{
|
||||
return BuiltInCategory.OST_Furniture;
|
||||
}
|
||||
}
|
||||
|
||||
private static FurnitureFamilyDragAndDropForm s_form;
|
||||
public static FurnitureFamilyDragAndDropForm GetTheForm(Document document)
|
||||
{
|
||||
if (s_form == null)
|
||||
{
|
||||
s_form = new FurnitureFamilyDragAndDropForm(document);
|
||||
}
|
||||
s_form.UpdateLoadedFamilies();
|
||||
return s_form;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display class for the external family file listbox.
|
||||
/// </summary>
|
||||
private class FamilyListBoxMember
|
||||
{
|
||||
public string FullPath;
|
||||
public string Name;
|
||||
public FamilyListBoxMember(string fullPath, string name)
|
||||
{
|
||||
FullPath = fullPath;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public override String ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
|
||||
private Document m_document;
|
||||
|
||||
/// <summary>
|
||||
/// Construct and populate the form.
|
||||
/// </summary>
|
||||
/// <param name="document"></param>
|
||||
private FurnitureFamilyDragAndDropForm(Document document)
|
||||
{
|
||||
InitializeComponent();
|
||||
m_document = document;
|
||||
|
||||
UpdateFamilyFileList();
|
||||
}
|
||||
|
||||
private void UpdateFamilyFileList()
|
||||
{
|
||||
// Visit each Revit library looking for Furniture families
|
||||
IDictionary<String, String> libraryPaths = m_document.Application.GetLibraryPaths();
|
||||
foreach (String libraryPath in libraryPaths.Values)
|
||||
{
|
||||
foreach (String directory in System.IO.Directory.EnumerateDirectories(libraryPath, "*Furniture", SearchOption.AllDirectories))
|
||||
{
|
||||
foreach (String familyFile in System.IO.Directory.EnumerateFiles(directory, "*.rfa", SearchOption.AllDirectories))
|
||||
{
|
||||
// Add each Furniture family to the listbox
|
||||
String fileName = Path.GetFileName(familyFile);
|
||||
FamilyListBoxMember member = new FamilyListBoxMember(familyFile, fileName);
|
||||
listBox1.Items.Add(member);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateLoadedFamilies()
|
||||
{
|
||||
ListView.ListViewItemCollection collection = listView1.Items;
|
||||
collection.Clear();
|
||||
|
||||
// Setup list view with loaded families
|
||||
ImageList imageList = new ImageList();
|
||||
Size size = new Size(50, 50);
|
||||
imageList.ImageSize = size;
|
||||
|
||||
FilteredElementCollector collector = new FilteredElementCollector(m_document);
|
||||
collector.OfCategory(FamilyCategory);
|
||||
collector.OfClass(typeof(FamilySymbol));
|
||||
|
||||
foreach (FamilySymbol familySymbol in collector.Cast<FamilySymbol>())
|
||||
{
|
||||
ListViewItem item = new ListViewItem();
|
||||
item.Tag = familySymbol.Id;
|
||||
item.Text = familySymbol.Family.Name + "::" + familySymbol.Name;
|
||||
item.ToolTipText = "Drag to place instances of " + item.Text + " in the active document.";
|
||||
|
||||
Bitmap bitmap = familySymbol.GetPreviewImage(size);
|
||||
|
||||
if (bitmap != null)
|
||||
{
|
||||
imageList.Images.Add(bitmap);
|
||||
int index = imageList.Images.Count - 1;
|
||||
item.ImageIndex = index;
|
||||
}
|
||||
|
||||
collection.Add(item);
|
||||
}
|
||||
|
||||
listView1.LargeImageList = imageList;
|
||||
}
|
||||
|
||||
// Drag action from list view
|
||||
private void listView_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (System.Windows.Forms.Control.MouseButtons == MouseButtons.Left)
|
||||
{
|
||||
ListViewItem selectedItem = this.listView1.SelectedItems.Cast<ListViewItem>().FirstOrDefault<ListViewItem>();
|
||||
|
||||
if (selectedItem != null)
|
||||
{
|
||||
// Use custom Revit drag and drop behavior
|
||||
LoadedFamilyDropHandler myhanlder = new LoadedFamilyDropHandler();
|
||||
UIApplication.DoDragDrop(selectedItem.Tag, myhanlder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Drag action from list box
|
||||
private void listBox1_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (System.Windows.Forms.Control.MouseButtons == MouseButtons.Left)
|
||||
{
|
||||
FamilyListBoxMember member = (FamilyListBoxMember)listBox1.SelectedItem;
|
||||
|
||||
// Use standard Revit drag and drop behavior
|
||||
List<String> data = new List<String>();
|
||||
data.Add(member.FullPath);
|
||||
UIApplication.DoDragDrop(data);
|
||||
}
|
||||
}
|
||||
|
||||
private void FurnitureFamilyDragAndDropForm_FormClosed(object sender, FormClosedEventArgs e)
|
||||
{
|
||||
s_form = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Custom handler for placement of loaded family types
|
||||
/// </summary>
|
||||
public class LoadedFamilyDropHandler : IDropHandler
|
||||
{
|
||||
public void Execute(UIDocument document, object data)
|
||||
{
|
||||
try
|
||||
{
|
||||
ElementId familySymbolId = (ElementId)data;
|
||||
|
||||
FamilySymbol symbol = document.Document.GetElement(familySymbolId) as FamilySymbol;
|
||||
|
||||
if (symbol != null)
|
||||
{
|
||||
document.PromptForFamilyInstancePlacement(symbol);
|
||||
}
|
||||
}
|
||||
catch (Autodesk.Revit.Exceptions.OperationCanceledException)
|
||||
{
|
||||
// user canceled the operation
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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>
|
||||
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// (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;
|
||||
|
||||
|
||||
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 DragAndDropCommand : IExternalCommand
|
||||
{
|
||||
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
|
||||
{
|
||||
// show the form
|
||||
FurnitureFamilyDragAndDropForm form = FurnitureFamilyDragAndDropForm.GetTheForm(commandData.View.Document);
|
||||
form.Show();
|
||||
form.BringToFront();
|
||||
return Result.Succeeded;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user