Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        public static void PlaceCustomConnection(Document doc)
        {
            StructuralConnectionHandlerType connectionType = new FilteredElementCollector(doc)
                                                             .OfCategory(BuiltInCategory.OST_StructConnections)
                                                             .WhereElementIsElementType()
                                                             .Where(e => e.Name == "Base Plate - Custom")
                                                             .Cast <StructuralConnectionHandlerType>()
                                                             .FirstOrDefault();

            FamilyInstance column = new FilteredElementCollector(doc)
                                    .OfCategory(BuiltInCategory.OST_StructuralColumns)
                                    .WhereElementIsNotElementType()
                                    .Cast <FamilyInstance>()
                                    .FirstOrDefault();

            if (column == null || connectionType == null)
            {
                return;
            }

            var connection = StructuralConnectionHandler.Create(doc, new List <ElementId>()
            {
                column.Id
            }, connectionType.Id);
        }
Ejemplo n.º 3
0
        /// <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);
        }