应用程序名称: GenericStructuralConnection

Revit 平台: 所有版本

Revit 版本: 2017.0

首次发布版本: 2017.0

编程语言: C#

技能等级: 初级

类别: 结构

类型: 外部命令

主题: 通用结构连接工具

摘要:

演示了在通用/详细结构连接上进行基本的创建、读取、更新和删除操作。

类别:

Autodesk.Revit.UI.IExternalCommand

Autodesk.Revit.UI.Selection.ISelectionFilter

Autodesk.Revit.DB.ElementTransformUtils

Autodesk.Revit.DB.ExtensibleStorage.Entity

Autodesk.Revit.DB.ExtensibleStorage.Schema

Autodesk.Revit.DB.Structure.StructuralConnectionHandler

Autodesk.Revit.DB.Structure.StructuralConnectionHandlerType

项目文件:

Command.cs

此文件包含从接口IExternalCommand继承并实现Execute方法的命令类。

 

CommandOptions.cs

此文件包含用户命令的枚举。

 

GenericStructuralConnectionOps.cs

此文件包含了一个类,该类公开了一组静态方法,用于基本通用结构连接操作。

 

DetailedStructuralConnectionOps.cs

此文件包含了一个类,该类公开了一组静态方法,用于基本详细结构连接操作。

 

StructuralConnectionSelectionFilter.cs

此文件包含了一个类,该类实现了用于选择操作的ISelectionFilter

 

StructualConnectionSelectionUtils.cs

此文件包含选择适当元素用于结构连接的方法。

 

StructuralConnectionForm.cs

此文件包含用于提示用户命令的表单。

描述:

此示例提供以下功能。

-创建、读取、更新、删除通用结构连接。

-创建、更改、复制、匹配属性、重置详细结构连接。

说明:

打开Revit应用程序,创建一个新的结构分析项目或打开现有的结构分析项目。

确保“结构连接”及其所有子类别在当前视图中可见。为此,从视图属性调色板打开“可见性/图形覆盖”对话框。

 

在当前项目中,您应该有一些有效的结构元素作为结构连接输入(框架、柱子、墙壁、地板或地基)。

执行命令(从“添加”选项卡)。

从对话框中选择一个选项并按“确定”。

 

1. 创建通用结构连接。

a. 执行命令。

b. 选择要连接的一些相邻的结构元素。

预期结果:为所选的结构元素创建一个通用结构连接。

 

2. 删除通用结构连接。

a. 执行命令。

b. 在当前项目中选择某些结构连接元素。

预期结果:结构连接应该被删除,原来连接的元素应该变成独立的。

 

3. 读取通用结构连接信息。

a. 执行命令。

b. 选择一个结构连接元素。

预期结果:屏幕上会出现一个显示连接信息的对话框。

 

4. 更新通用结构连接信息。

a. 执行命令。

b. 在提示时选择一个连接。

c. 选择要添加到现有连接的一个或多个元素。这些元素应该要遵守距离限制。

预期结果:结构连接将更新以包括额外选择的元素。

 

以下命令演示详细结构连接的使用。

为此,您需要安装Steel Connection插件。

您还需要将详细级别更改为“精细”,以便查看结果。

 

5. 创建详细结构连接。

a. 执行命令。

b. 选择一个结构柱和一个相邻的结构框架。

预期结果:应创建一个精细结构连接(剪切角)。

 

6. 复制详细结构连接。

a. 选择一个详细连接和它的输入元素。

b. 执行命令。

预期结果:结构连接和连接的元素应该被复制到当前项目中的另一个位置。

 

7. 在详细结构连接上匹配属性。

a. 执行命令。

b. 选择源详细结构连接。

c. 选择应该与源连接匹配的类型相似的详细结构连接。

预期结果:目标连接的属性应匹配到源连接。

 

8. 更改详细结构连接。

a. 执行命令。

b. 选择一个详细的剪切角结构连接。

预期结果:详细结构连接的类型和图形表示应从“剪切角”更改为“剪力板”。

 

9. 重置详细结构连接。

a. 执行命令。

b. 选择详细结构连接。

预期结果:详细结构连接的类型和图形表示应从“剪切角”更改为通用连接。

源代码:

完整的源代码请加入QQ群649037449,在群文件中下载RevitSDK.exe,解压后在文件夹中搜索本文中应用程序名称即可获得完整源码

CommandOptions.cs

//
// (C) Copyright 2003-2015 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;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace Revit.SDK.Samples.GenericStructuralConnection.CS
{
    /// <summary>
    /// Enum for user commands. 
    /// </summary>
    public enum CommandOption
    {
        /// <summary>
        /// Create generic connection. 
        /// </summary>
        CreateGeneric,
        /// <summary>
        /// Delete generic connection. 
        /// </summary>
        DeleteGeneric,
        /// <summary>
        /// Read generic connection. 
        /// </summary>
        ReadGeneric,
        /// <summary>
        /// Update generic connection. 
        /// </summary>
        UpdateGeneric,
        /// <summary>
        /// Create detailed connection. 
        /// </summary>
        CreateDetailed,
        /// <summary>
        /// Change detailed connection. 
        /// </summary>
        ChangeDetailed,
        /// <summary>
        /// Copy detailed connection. 
        /// </summary>
        CopyDetailed,
        /// <summary>
        /// Match properties of detailed connections. 
        /// </summary>
        MatchPropDetailed,
        /// <summary>
        /// Reset detailed connection. 
        /// </summary>
        ResetDetailed
    }
}

DetailedStructuralConnectionOps.cs

//
// (C) Copyright 2003-2015 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//


using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

using Autodesk.Revit;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.DB.ExtensibleStorage;

namespace Revit.SDK.Samples.GenericStructuralConnection.CS
{
    /// <summary>
    /// Performs basic operations on detailed structural connections.
    /// </summary>
    public class DetailedStructuralConnectionOps
    {
        /// <summary>
        /// Create detailed structural connection.
        /// </summary>
        /// <param name="activeDoc">The active document.</param>
        /// <param name="message">Set message on failure.</param>
        /// <returns>Returns the status of the operation.</returns>
        public static Result CreateDetailedStructuralConnection(UIDocument activeDoc, ref string message)
        {
            Result ret = Result.Succeeded;

            // Selected the elements to be connected.
            List<ElementId> ids = StructuralConnectionSelectionUtils.SelectConnectionElements(activeDoc);
            if (ids.Count() > 0)
            {
                // Start a new transaction.
                using (Transaction transaction = new Transaction(activeDoc.Document, "Create detailed structural connection"))
                {
                    transaction.Start();

                    // The type is from the SteelConnectionsData.xml file.
                    StructuralConnectionHandlerType connectionType = StructuralConnectionHandlerType.Create(activeDoc.Document, "usclipangle", new Guid("A42C5CE5-91C5-47E4-B445-D053E5BD66DB"), "usclipangle");
                    if (connectionType != null)
                    {
                        StructuralConnectionHandler.Create(activeDoc.Document, ids, connectionType.Id);
                    }

                    TransactionStatus ts = transaction.Commit();
                    if (ts != TransactionStatus.Committed)
                    {
                        message = "Failed to commit the current transaction !";
                        ret = Result.Failed;
                    }
                }
            }
            else
            {
                message = "There is no element selected!";
                ret = Result.Failed;
            }

            return ret;
        }

        /// <summary>
        /// Change detailed structural connection.
        /// </summary>
        /// <param name="activeDoc">The active document.</param>
        /// <param name="message">Set message on failure.</param>
        /// <returns>Returns the status of the operation.</returns>
        public static Result ChangeDetailedStructuralConnection(UIDocument activeDoc, ref string message)
        {
            Result ret = Result.Succeeded;

            // Prompt to select a structural connection.
            StructuralConnectionHandler conn = StructuralConnectionSelectionUtils.SelectConnection(activeDoc);
            if (conn != null)
            {
                using (Transaction tran = new Transaction(activeDoc.Document, "Change detailed connection type"))
                {
                    tran.Start();

                    // The type is from the SteelConnectionsData.xml file.
                    StructuralConnectionHandlerType connectionType = StructuralConnectionHandlerType.Create(activeDoc.Document, "shearplatenew", new Guid("B490A703-5B6D-4B7A-8471-752133527925"), "shearplatenew");
                    if (connectionType != null)
                    {
                        // The replacement type should be valid on the connected elements.
                        conn.ChangeTypeId(connectionType.Id);
                    }

                    TransactionStatus ts = tran.Commit();
                    if (ts != TransactionStatus.Committed)
                    {
                        message = "Failed to commit the current transaction !";
                        ret = Result.Failed;
                    }
                }
            }
            else
            {
                message = "There is no connection selected!";
                ret = Result.Failed;
            }

            return ret;
        }

        /// <summary>
        /// Copy detailed structural connection.
        /// </summary>
        /// <param name="activeDoc">The active document.</param>
        /// <param name="message">Set message on failure.</param>
        /// <returns>Returns the status of the operation.</returns>
        public static Result CopyDetailedStructuralConnection(UIDocument activeDoc, ref string message)
        {
            Result ret = Result.Succeeded;

            // Select a connection and the connected elements.
            List<ElementId> ids = activeDoc.Selection.GetElementIds().ToList();
            if (ids.Count() > 0)
            {
                // Create transform
                Transform transform = Transform.CreateTranslation(new XYZ(0, 20, 0));

                // Copy selection
                using (Transaction tran = new Transaction(activeDoc.Document, "Copy elements"))
                {
                    tran.Start();
                    ICollection<ElementId> copyResult = ElementTransformUtils.CopyElements(activeDoc.Document, ids, activeDoc.Document, transform, null);
                    TransactionStatus ts = tran.Commit();
                    if (ts != TransactionStatus.Committed)
                    {
                        message = "Failed to commit the current transaction !";
                        ret = Result.Failed;
                    }
                }
            }
            else
            {
                message = "There is no element selected!";
                ret = Result.Failed;
            }

            return ret;
        }

        /// <summary>
        /// Match properties for detailed structural connections.
        /// </summary>
        /// <param name="activeDoc">The active document.</param>
        /// <param name="message">Set message on failure.</param>
        /// <returns>Returns the status of the operation.</returns>
        public static Result MatchPropertiesDetailedStructuralConnection(UIDocument activeDoc, ref string message)
        {
            Result ret = Result.Succeeded;

            // Prompt to select a structural connection
            StructuralConnectionHandler srcConn = StructuralConnectionSelectionUtils.SelectConnection(activeDoc);
            StructuralConnectionHandler destConn = StructuralConnectionSelectionUtils.SelectConnection(activeDoc);

            if (srcConn != null && destConn != null)
            {
                using (Transaction tran = new Transaction(activeDoc.Document, "Match properties"))
                {
                    tran.Start();

                    // Do the properties match.
                    Schema masterSchema = GetSchema(activeDoc.Document, srcConn);
                    Entity masterEnt = srcConn.GetEntity(masterSchema);

                    // You could also access and modify the connection parameters.
                    IList<Field> fields = masterSchema.ListFields();
                    foreach (Field field in fields)
                    {
                        if (field.ValueType == typeof(string))
                        {
                            IList<string> parameters = masterEnt.Get<IList<string>>(field);
                            foreach (string str in parameters)
                            {
                                // Do something.
                            }
                        }
                    }

                    destConn.SetEntity(masterEnt);

                    TransactionStatus ts = tran.Commit();
                    if (ts != TransactionStatus.Committed)
                    {
                        message = "Failed to commit the current transaction !";
                        ret = Result.Failed;
                    }
                }
            }
            else
            {
                message = "There must be two connections selected !";
                ret = Result.Failed;
            }


            return ret;
        }

        /// <summary>
        /// Reset detailed structural connection type to generic.
        /// </summary>
        /// <param name="activeDoc">The active document.</param>
        /// <param name="message">Set message on failure.</param>
        /// <returns>Returns the status of the operation.</returns>
        public static Result ResetDetailedStructuralConnection(UIDocument activeDoc, ref string message)
        {
            Result ret = Result.Succeeded;

            // Prompt to select a structural connection.

            StructuralConnectionHandler conn = StructuralConnectionSelectionUtils.SelectConnection(activeDoc);
            if (conn != null)
            {
                using (Transaction tran = new Transaction(activeDoc.Document, "Change detailed connection type"))
                {
                    tran.Start();

                    ElementId genericTypeId = StructuralConnectionHandlerType.GetDefaultConnectionHandlerType(activeDoc.Document);
                    if (genericTypeId == ElementId.InvalidElementId)
                    {
                        genericTypeId = StructuralConnectionHandlerType.CreateDefaultStructuralConnectionHandlerType(activeDoc.Document);                        
                    }

                    conn.ChangeTypeId(genericTypeId);

                    TransactionStatus ts = tran.Commit();
                    if (ts != TransactionStatus.Committed)
                    {
                        message = "Failed to commit the current transaction !";
                        ret = Result.Failed;
                    }
                }
            }
            else
            {
                message = "There is no connection selected !";
                ret = Result.Failed;
            }

            return ret; ;
        }

        /// <summary>
        /// Get the Extensible storage schema
        /// </summary>
        private static Schema GetSchema(Document doc, StructuralConnectionHandler connection)
        {
            Schema schema = null;

            Guid guid = GetConnectionHandlerTypeGuid(connection, doc);
            if (guid != null && guid != Guid.Empty)
                schema = Schema.ListSchemas().Where(x => x.GUID == guid).FirstOrDefault();

            return schema;
        }

        /// <summary>
        /// Get the unique identifier of the structural steel connection type
        /// </summary>
        /// <param name="conn">structural connection</param>
        /// <param name="doc">current document</param>
        /// <returns>returns the unique identifier of the input connection type</returns>
        private static Guid GetConnectionHandlerTypeGuid(StructuralConnectionHandler conn, Document doc)
        {
            if (conn == null || doc == null)
                return Guid.Empty;

            ElementId typeId = conn.GetTypeId();
            if (typeId == ElementId.InvalidElementId)
                return Guid.Empty;

            StructuralConnectionHandlerType connType = (StructuralConnectionHandlerType)doc.GetElement(typeId);
            if (connType == null || connType.ConnectionGuid == null)
                return Guid.Empty;

            return connType.ConnectionGuid;
        }
    }
}

GenericStructuralConnectionOps.cs

//
// (C) Copyright 2003-2015 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//


using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

using Autodesk.Revit;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;

namespace Revit.SDK.Samples.GenericStructuralConnection.CS
{
    /// <summary>
    /// Performs basic operations on generic structural connections.
    /// </summary>
    public class GenericStructuralConnectionOps
    {
        /// <summary>
        /// Create generic structural connection.
        /// </summary>
        /// <param name="activeDoc">The active document.</param>
        /// <param name="message">Set message on failure.</param>
        /// <returns>Returns the status of the operation.</returns>
        public static Result CreateGenericStructuralConnection(UIDocument activeDoc, ref string message)
        {
            Result ret = Result.Succeeded;

            List<ElementId> ids = StructuralConnectionSelectionUtils.SelectConnectionElements(activeDoc);
            if (ids.Count() > 0)
            {
                // Start a new transaction.
                using (Transaction tran = new Transaction(activeDoc.Document, "Create generic structural connection"))
                {
                    tran.Start();

                    StructuralConnectionHandler conn = StructuralConnectionHandler.Create(activeDoc.Document, ids);

                    TransactionStatus ts = tran.Commit();
                    if (ts != TransactionStatus.Committed)
                    {
                        message = "Failed to commit the current transaction !";
                        ret = Result.Failed;
                    }
                }
            }
            else
            {
                message = "There is no element selected !";
                ret = Result.Failed;
            }

            return ret;
        }

        /// <summary>
        /// Delete generic structural connection.
        /// </summary>
        /// <param name="activeDoc">The active document.</param>
        /// <param name="message">Set message on failure.</param>
        /// <returns>Returns the status of the operation.</returns>
        public static Result DeleteGenericStructuralConnection(UIDocument activeDoc, ref string message)
        {
            Result ret = Result.Succeeded;

            // Select a structural connection.
            StructuralConnectionHandler conn = StructuralConnectionSelectionUtils.SelectConnection(activeDoc);

            if (conn != null)
            {
                // Start a new transaction.
                using (Transaction tran = new Transaction(activeDoc.Document, "Delete generic structural connection"))
                {
                    tran.Start();

                    // Delete selected structural connection.
                    activeDoc.Document.Delete(conn.Id);

                    TransactionStatus ts = tran.Commit();
                    if (ts != TransactionStatus.Committed)
                    {
                        message = "Failed to commit the current transaction !";
                        return Result.Failed;
                    }
                }
            }
            else
            {
                message = "There is no connection selected !";
                ret = Result.Failed;
            }

            return ret;
        }

        /// <summary>
        /// Read information from generic structural connection.
        /// </summary>
        /// <param name="activeDoc">The active document.</param>
        /// <param name="message">Set message on failure.</param>
        /// <returns>Returns the status of the operation.</returns>
        public static Result ReadGenericStructuralConnection(UIDocument activeDoc, ref string message)
        {
            Result ret = Result.Succeeded;

            // Select structural connection.
            StructuralConnectionHandler conn = StructuralConnectionSelectionUtils.SelectConnection(activeDoc);
            if (conn != null)
            {
                // Get information from structural connection.
                StringBuilder msgBuilder = new StringBuilder();
                msgBuilder.AppendLine(string.Format("Connection id : {0}", conn.Id));

                StructuralConnectionHandlerType connType = activeDoc.Document.GetElement(conn.GetTypeId()) as StructuralConnectionHandlerType;
                if (connType != null)
                    msgBuilder.AppendLine(string.Format("Type : {0}", connType.Name));

                msgBuilder.Append("Connected elements ids : ");
                IList<ElementId> connectedElemIds = conn.GetConnectedElementIds();
                foreach (var connId in connectedElemIds)
                {
                    msgBuilder.Append(connId.ToString());
                    if (connId != connectedElemIds.Last())
                        msgBuilder.Append(", ");
                }
                TaskDialog.Show("Info", msgBuilder.ToString());
            }
            else
            {
                message = "There is no connection selected !";
                ret = Result.Failed;
            }

            return ret;
        }

        /// <summary>
        /// Update generic structural connection.
        /// </summary>
        /// <param name="activeDoc">The active document.</param>
        /// <param name="message">Set message on failure.</param>
        /// <returns>Returns the status of the operation.</returns>
        public static Result UpdateGenericStructuralConnection(UIDocument activeDoc, ref string message)
        {
            Result ret = Result.Succeeded;

            // Prompt to select a structural connection.
            StructuralConnectionHandler conn = StructuralConnectionSelectionUtils.SelectConnection(activeDoc);
            if (conn != null)
            {
                // Select elements to add to connection.
                List<ElementId> ids = StructuralConnectionSelectionUtils.SelectConnectionElements(activeDoc);
                if (ids.Count() > 0)
                {
                    // Start a new transaction.
                    using (Transaction transaction = new Transaction(activeDoc.Document, "Update generic structural connection"))
                    {
                        transaction.Start();

                        conn.AddElementIds(ids);

                        TransactionStatus ts = transaction.Commit();
                        if (ts != TransactionStatus.Committed)
                        {
                            message = "Failed to commit the current transaction !";
                            ret = Result.Failed;
                        }
                    }
                }
                else
                {
                    message = "There are no connection input elements selected !";
                }
            }

            return ret;
        }

    }
}

StructuralConnectionForm.cs

namespace Revit.SDK.Samples.GenericStructuralConnection.CS
{
    partial class StructuralConnectionForm
    {
        /// <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.buttonOK = new System.Windows.Forms.Button();
            this.buttonCancel = new System.Windows.Forms.Button();
            this.rbCreateGeneric = new System.Windows.Forms.RadioButton();
            this.rbDeleteGeneric = new System.Windows.Forms.RadioButton();
            this.rbReadGeneric = new System.Windows.Forms.RadioButton();
            this.gbCommands = new System.Windows.Forms.GroupBox();
            this.rbUpdateGeneric = new System.Windows.Forms.RadioButton();
            this.rbCreateDetailed = new System.Windows.Forms.RadioButton();
            this.rbChangedDetail = new System.Windows.Forms.RadioButton();
            this.rbCopyDetailed = new System.Windows.Forms.RadioButton();
            this.rbMatchPropDetailed = new System.Windows.Forms.RadioButton();
            this.rbResetDetailed = new System.Windows.Forms.RadioButton();
            this.gbCommands.SuspendLayout();
            this.SuspendLayout();
            // 
            // buttonOK
            // 
            this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.buttonOK.Location = new System.Drawing.Point(162, 281);
            this.buttonOK.Name = "buttonOK";
            this.buttonOK.Size = new System.Drawing.Size(75, 23);
            this.buttonOK.TabIndex = 0;
            this.buttonOK.Text = "&OK";
            this.buttonOK.UseVisualStyleBackColor = true;
            this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
            // 
            // buttonCancel
            // 
            this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.buttonCancel.Location = new System.Drawing.Point(243, 281);
            this.buttonCancel.Name = "buttonCancel";
            this.buttonCancel.Size = new System.Drawing.Size(75, 23);
            this.buttonCancel.TabIndex = 1;
            this.buttonCancel.Text = "&Cancel";
            this.buttonCancel.UseVisualStyleBackColor = true;
            // 
            // rbCreateGeneric
            // 
            this.rbCreateGeneric.AutoSize = true;
            this.rbCreateGeneric.Checked = true;
            this.rbCreateGeneric.Location = new System.Drawing.Point(6, 19);
            this.rbCreateGeneric.Name = "rbCreateGeneric";
            this.rbCreateGeneric.Size = new System.Drawing.Size(196, 17);
            this.rbCreateGeneric.TabIndex = 2;
            this.rbCreateGeneric.TabStop = true;
            this.rbCreateGeneric.Text = "Create generic structural connection";
            this.rbCreateGeneric.UseVisualStyleBackColor = true;
            // 
            // rbDeleteGeneric
            // 
            this.rbDeleteGeneric.AutoSize = true;
            this.rbDeleteGeneric.Location = new System.Drawing.Point(6, 43);
            this.rbDeleteGeneric.Name = "rbDeleteGeneric";
            this.rbDeleteGeneric.Size = new System.Drawing.Size(196, 17);
            this.rbDeleteGeneric.TabIndex = 3;
            this.rbDeleteGeneric.Text = "Delete generic structural connection";
            this.rbDeleteGeneric.UseVisualStyleBackColor = true;
            // 
            // rbReadGeneric
            // 
            this.rbReadGeneric.AutoSize = true;
            this.rbReadGeneric.Location = new System.Drawing.Point(6, 67);
            this.rbReadGeneric.Name = "rbReadGeneric";
            this.rbReadGeneric.Size = new System.Drawing.Size(191, 17);
            this.rbReadGeneric.TabIndex = 4;
            this.rbReadGeneric.Text = "Read generic structural connection";
            this.rbReadGeneric.UseVisualStyleBackColor = true;
            // 
            // gbCommands
            // 
            this.gbCommands.Controls.Add(this.rbResetDetailed);
            this.gbCommands.Controls.Add(this.rbMatchPropDetailed);
            this.gbCommands.Controls.Add(this.rbCopyDetailed);
            this.gbCommands.Controls.Add(this.rbChangedDetail);
            this.gbCommands.Controls.Add(this.rbCreateDetailed);
            this.gbCommands.Controls.Add(this.rbUpdateGeneric);
            this.gbCommands.Controls.Add(this.rbReadGeneric);
            this.gbCommands.Controls.Add(this.rbCreateGeneric);
            this.gbCommands.Controls.Add(this.rbDeleteGeneric);
            this.gbCommands.Location = new System.Drawing.Point(13, 13);
            this.gbCommands.Name = "gbCommands";
            this.gbCommands.Size = new System.Drawing.Size(305, 247);
            this.gbCommands.TabIndex = 5;
            this.gbCommands.TabStop = false;
            this.gbCommands.Text = "Commands";
            // 
            // rbUpdateGeneric
            // 
            this.rbUpdateGeneric.AutoSize = true;
            this.rbUpdateGeneric.Location = new System.Drawing.Point(6, 91);
            this.rbUpdateGeneric.Name = "rbUpdateGeneric";
            this.rbUpdateGeneric.Size = new System.Drawing.Size(200, 17);
            this.rbUpdateGeneric.TabIndex = 5;
            this.rbUpdateGeneric.TabStop = true;
            this.rbUpdateGeneric.Text = "Update generic structural connection";
            this.rbUpdateGeneric.UseVisualStyleBackColor = true;
            // 
            // rbCreateDetailed
            // 
            this.rbCreateDetailed.AutoSize = true;
            this.rbCreateDetailed.Location = new System.Drawing.Point(7, 115);
            this.rbCreateDetailed.Name = "rbCreateDetailed";
            this.rbCreateDetailed.Size = new System.Drawing.Size(198, 17);
            this.rbCreateDetailed.TabIndex = 6;
            this.rbCreateDetailed.TabStop = true;
            this.rbCreateDetailed.Text = "Create detailed structural connection";
            this.rbCreateDetailed.UseVisualStyleBackColor = true;
            // 
            // rbChangedDetail
            // 
            this.rbChangedDetail.AutoSize = true;
            this.rbChangedDetail.Location = new System.Drawing.Point(7, 139);
            this.rbChangedDetail.Name = "rbChangedDetail";
            this.rbChangedDetail.Size = new System.Drawing.Size(204, 17);
            this.rbChangedDetail.TabIndex = 7;
            this.rbChangedDetail.TabStop = true;
            this.rbChangedDetail.Text = "Change detailed structural connection";
            this.rbChangedDetail.UseVisualStyleBackColor = true;
            // 
            // rbCopyDetailed
            // 
            this.rbCopyDetailed.AutoSize = true;
            this.rbCopyDetailed.Location = new System.Drawing.Point(7, 162);
            this.rbCopyDetailed.Name = "rbCopyDetailed";
            this.rbCopyDetailed.Size = new System.Drawing.Size(191, 17);
            this.rbCopyDetailed.TabIndex = 8;
            this.rbCopyDetailed.TabStop = true;
            this.rbCopyDetailed.Text = "Copy detailed structural connection";
            this.rbCopyDetailed.UseVisualStyleBackColor = true;
            // 
            // rbMatchPropDetailed
            // 
            this.rbMatchPropDetailed.AutoSize = true;
            this.rbMatchPropDetailed.Location = new System.Drawing.Point(7, 187);
            this.rbMatchPropDetailed.Name = "rbMatchPropDetailed";
            this.rbMatchPropDetailed.Size = new System.Drawing.Size(258, 17);
            this.rbMatchPropDetailed.TabIndex = 9;
            this.rbMatchPropDetailed.TabStop = true;
            this.rbMatchPropDetailed.Text = "Match properties of detailed structural connection";
            this.rbMatchPropDetailed.UseVisualStyleBackColor = true;
            // 
            // rbResetDetailed
            // 
            this.rbResetDetailed.AutoSize = true;
            this.rbResetDetailed.Location = new System.Drawing.Point(6, 210);
            this.rbResetDetailed.Name = "rbResetDetailed";
            this.rbResetDetailed.Size = new System.Drawing.Size(245, 17);
            this.rbResetDetailed.TabIndex = 10;
            this.rbResetDetailed.TabStop = true;
            this.rbResetDetailed.Text = "Reset detailed structural connection to generic";
            this.rbResetDetailed.UseVisualStyleBackColor = true;
            // 
            // StructuralConnectionForm
            // 
            this.AcceptButton = this.buttonOK;
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.CancelButton = this.buttonCancel;
            this.ClientSize = new System.Drawing.Size(330, 316);
            this.Controls.Add(this.buttonCancel);
            this.Controls.Add(this.buttonOK);
            this.Controls.Add(this.gbCommands);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "StructuralConnectionForm";
            this.ShowIcon = false;
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
            this.Text = "Structural connection operations";
            this.gbCommands.ResumeLayout(false);
            this.gbCommands.PerformLayout();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.Button buttonOK;
        private System.Windows.Forms.Button buttonCancel;
        private System.Windows.Forms.RadioButton rbCreateGeneric;
        private System.Windows.Forms.RadioButton rbDeleteGeneric;
        private System.Windows.Forms.RadioButton rbReadGeneric;
        private System.Windows.Forms.GroupBox gbCommands;
        private System.Windows.Forms.RadioButton rbUpdateGeneric;
        private System.Windows.Forms.RadioButton rbCreateDetailed;
        private System.Windows.Forms.RadioButton rbChangedDetail;
        private System.Windows.Forms.RadioButton rbCopyDetailed;
        private System.Windows.Forms.RadioButton rbResetDetailed;
        private System.Windows.Forms.RadioButton rbMatchPropDetailed;
    }
}

StructuralConnectionSelectionFilter.cs

//
// (C) Copyright 2003-2015 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;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;

namespace Revit.SDK.Samples.GenericStructuralConnection.CS
{
    /// <summary>
    /// Define filter for generic structural connection input elements. 
    /// </summary>
    class StructuralConnectionSelectionFilter : ISelectionFilter
    {
        LogicalOrFilter _filter;
        /// <summary>
        /// Initialize the filter with the accepted element types.
        /// </summary>
        /// <param name="elemTypesAllowed">Logical filter containing accepted element types.</param>
        /// <returns></returns>
        public StructuralConnectionSelectionFilter(LogicalOrFilter elemTypesAllowed)
        {
            _filter = elemTypesAllowed;
        }

        /// <summary>
        /// Allows an element to be selected
        /// </summary>
        /// <param name="element">A candidate element in the selection operation.</param>
        /// <returns>Return true to allow the user to select this candidate element.</returns>
        public bool AllowElement(Element element)
        {
            return _filter.PassesFilter(element);
        }
        /// <summary>
        /// Allows a reference to be selected.
        /// </summary>
        /// <param name="refer"> A candidate reference in the selection operation.</param>
        /// <param name="point">The 3D position of the mouse on the candidate reference.</param>
        /// <returns>Return true to allow the user to select this candidate reference.</returns>
        public bool AllowReference(Reference refer, XYZ point)
        {
            return true;
        }
    }
}

StructuralConnectionSelectionUtils.cs

//
// (C) Copyright 2003-2015 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;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.DB.Structure;

namespace Revit.SDK.Samples.GenericStructuralConnection.CS
{
    /// <summary>
    /// Utility class to select connections or connection input elements. 
    /// </summary>
    class StructuralConnectionSelectionUtils
    {
        /// <summary>
        /// Static method to select structural connections.
        /// </summary>
        /// <returns>Returns the id of the connection.</returns>
        public static StructuralConnectionHandler SelectConnection(UIDocument document)
        {
            StructuralConnectionHandler conn = null;
            // Create a filter for structural connections.
            LogicalOrFilter types = new LogicalOrFilter(new List<ElementFilter> { new ElementCategoryFilter(BuiltInCategory.OST_StructConnections) });
            StructuralConnectionSelectionFilter filter = new StructuralConnectionSelectionFilter(types);
            Reference target = document.Selection.PickObject(ObjectType.Element, filter, "Select connection element :");
            if (target != null)
            {
                Element targetElement = document.Document.GetElement(target);
                if (targetElement != null)
                {
                    conn = targetElement as StructuralConnectionHandler;
                }
            }

            return conn;
        }
        /// <summary>
        /// Static method o select valid input element for the structural connection.
        /// </summary>
        /// <param name="document"> Current document. </param>
        /// <returns>Returns a list of element ids.</returns>
        public static List<ElementId> SelectConnectionElements(UIDocument document)
        {
            List<ElementId> elemIds = new List<ElementId>();

            // Create a filter for the allowed structural connection inputs.
            LogicalOrFilter connElemTypes = new LogicalOrFilter(new List<ElementFilter>{
            new ElementCategoryFilter(BuiltInCategory.OST_StructuralFraming),
            new ElementCategoryFilter(BuiltInCategory.OST_StructuralColumns),
            new ElementCategoryFilter(BuiltInCategory.OST_StructuralFoundation),
            new ElementCategoryFilter(BuiltInCategory.OST_Floors),
            new ElementCategoryFilter(BuiltInCategory.OST_Walls)});
            StructuralConnectionSelectionFilter elemFilter = new StructuralConnectionSelectionFilter(connElemTypes);
            
            List<Reference> refs = document.Selection.PickObjects(ObjectType.Element, elemFilter, "Select elements to add to connection :").ToList();
            elemIds = refs.Select(e => e.ElementId).ToList();

            return elemIds;
        }
    }
}