/// <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> /// 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> /// 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> /// 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> /// 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> /// 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); }