Share

StructuralConnectionHandlerType.UpdateCustomConnectionType Method

Modifies StructuralConnectionHandlerType of input StructuralConnectionHandler. Adds input elements or subelements. Removes input subelements.The subelements will be erased. Updates any geometrical, parametrical or location changes of existing subelements, regardless of whether elements or subelements are added or removed.


Namespace: Autodesk.Revit.DB.Structure
Assembly: RevitAPI (in RevitAPI.dll) Version: 26.3.0.0 (26.3.0.0)

Syntax

C#

public static void UpdateCustomConnectionType(
	StructuralConnectionHandler structuralConnectionHandler,
	IList<Reference> addReferences,
	IList<Reference> removeReferences
)

Parameters

structuralConnectionHandler  StructuralConnectionHandler
The existing StructuralConnectionHandler having custom StructuralConnectionHandlerType which is about to be modified.
addReferences  IList<Reference>
References to elements or subelements which are to be used to modify custom StructuralConnectionHandlerType by adding them.
removeReferences  IList<Reference>
References to subelements of input StructuralConnectionHandler which are to be used to modify custom StructuralConnectionHandlerType by removing them.

Exceptions

ExceptionCondition
ArgumentException Input StructuralConnectionHandler must have custom type. -or- All the input Elements should be of the following structural categories: framings, columns, profiles, plates, bolts, anchors, shear studs, welds or structural connections. -or- Total number of different input elements of input StructuralConnectionHandlers must be lower or equal to 3. -or- All the input references must belong to input StructuralConnectionHandler. After modification of StructuralConnectionHandlerType there must remain at least one subelement of structural connections category in StructuralConnectionHandler.
ArgumentNullException A non-optional argument was null

Remarks

Elements or subelements added to a custom connection are deleted and transformed in subelements of the connection. They could be:
  • FamilyInstance (structural beams and columns).
  • StructuralConnectionHandler elements associated to the connection.
  • Specific steel connection elements (bolts, anchors, plates, etc). These connection elements will be of type element but with categories related to structural connections, for example:
    • OST_StructConnectionWelds
    • OST_StructConnectionHoles
    • OST_StructConnectionModifiers
    • OST_StructConnectionShearStuds
    • OST_StructConnectionBolts
    • OST_StructConnectionAnchors
    • OST_StructConnectionPlates
You cannot add: elements connected by any connection handler, generic connections, holes and modifiers that are not on the connected elements.

Example

C#

// The transaction and its status, using Revit's Transaction class
Autodesk.Revit.DB.Transaction transaction = new Autodesk.Revit.DB.Transaction(doc, "Modify custom connection subelements");
TransactionStatus ts = TransactionStatus.Uninitialized;
try
{
   // Start the Revit transaction
   transaction.Start();

   // Start detailed steel modeling transaction
   using (FabricationTransaction trans = new FabricationTransaction(doc, false, "Modify custom connection", true))
   {
      // To modify specific selected subelements Prompt to select subelements
      // IList<Reference> customConSubelemetRefs = new List<Reference>();               
      //IList<Reference> refs = activeDoc.Selection.PickObjects(ObjectType.Subelement, "Select subelements:").ToList();
      //filter the selected objects to get only the subelements of this custom connection
      //foreach (Reference subelementRef in refs)
      //{
      //   Subelement subelement = doc.GetSubelement(subelementRef);
      //   if (subelement != null)
      //   {
      //      if (subelement.Element.Id == conn.Id)
      //      {
      //         customConSubelemetRefs.Append(subelementRef);
      //      }
      //   }
      //}
      // For this sample we will get all subelements of selected custom connection               
      IEnumerable<Subelement> subelements = conn.GetSubelements();

      //get the user defined connection instance from the selected connection
      UserDefinedConnectionInstance userConn = Utilities.Functions.GetFilerObject(doc, target) as UserDefinedConnectionInstance;

      foreach (Subelement subelement in subelements)
      {
         FilerObject filerObjForSubelement = Utilities.Functions.GetFilerObject(doc, subelement.GetReference());

         if (null == filerObjForSubelement)
            continue;

         if (filerObjForSubelement is not ConstructionElement)
            continue;

         ConstructionElement ace = filerObjForSubelement as ConstructionElement;
         if (null == ace || !ace.HasDrivingPassiveConstructionObject)
            continue;

         //make sure the subelement is not part of a standard connection (we cannot modify subelements of standard connection)
         PassiveConstructionObject pco = ace.DrivingPassiveConstructionObject;
         if (null == pco || pco is not UserDefinedConnectionInstance)
            continue;

         //need to disable the DeleteRuleOnDeleteDriven becuase some operations like SetOuterContour for plates or changing the bolt pattern may delete some features or objects
         //if DeleteRuleOnDeleteDriven is set to true this would cause the deletion of entire connection and the transaction will fail
         bool bOlddeleteRuleOnDeleteDriven = userConn.DeleteRuleOnDeleteDriven;
         userConn.DeleteRuleOnDeleteDriven = false;
         //for plate subelement modify the contour by expanding it with 100, set the thickness to 100 and move the plate by translation with 100 in z direction
         if (filerObjForSubelement is Plate)
         {
            Plate plate = filerObjForSubelement as Plate;

            Polyline3d newContour = new Polyline3d();
            Polyline3d oldContour;
            plate.GetBaseContourPolygon(1, out oldContour);
            oldContour.Expand(100);
            newContour = oldContour;

            if (newContour.VertexCount <= 0)
            {
               return Result.Failed;
            }

            IEnumerable<ObjectId> deletedFeatures;
            IEnumerable<ObjectId> addedFeatures;
            plate.SetOuterContour(newContour, out deletedFeatures, out addedFeatures);
            plate.Thickness = 100;
            plate.TransformBy(Matrix3d.GetTranslation(new Vector3d(0, 0, 100)));
         }
         //for bolts we will change the bolt pattern from rectangular to circular with 3 screws
         else if (filerObjForSubelement is BoltPattern)
         {
            BoltPattern boltPattern = filerObjForSubelement as BoltPattern;
            if (boltPattern.IsKindOf(FilerObject.eObjectType.kCountableScrewBoltPattern))
            {
               CountableScrewBoltPattern countableScrewBoltPattern = boltPattern as CountableScrewBoltPattern;

               if (null != countableScrewBoltPattern)
               {
                  countableScrewBoltPattern.GetConnectedElements(out IEnumerable<ObjectId> connectedElements, 0);
                  FilerObject[] connectedFilerObjects = new FilerObject[] { };
                  foreach (ObjectId connectedElement in connectedElements)
                  {
                     FilerObject connectedElementObj = FilerObject.GetFilerObjectByHandle(connectedElement.Handle);
                     if (null != connectedElementObj)
                     {
                        connectedFilerObjects.Append(connectedElementObj);
                     }
                  }

                  if (connectedElements.Count() > 0)
                  {
                     //create new circular bolt pattern
                     CircleScrewBoltPattern circScrewBoltPattern = new CircleScrewBoltPattern(countableScrewBoltPattern.CenterPoint, countableScrewBoltPattern.XDirection, countableScrewBoltPattern.YDirection);
                     if (null != circScrewBoltPattern)
                     {
                        circScrewBoltPattern.NumberOfScrews = 3;
                        circScrewBoltPattern.Radius = countableScrewBoltPattern.Length / 2;
                        //transfer bolt pattern properties
                        circScrewBoltPattern.Standard = countableScrewBoltPattern.Standard;
                        circScrewBoltPattern.Grade = countableScrewBoltPattern.Grade;
                        circScrewBoltPattern.BoltAssembly = countableScrewBoltPattern.BoltAssembly;
                        circScrewBoltPattern.ScrewDiameter = countableScrewBoltPattern.ScrewDiameter;
                        circScrewBoltPattern.BindingLength = countableScrewBoltPattern.BindingLength;
                        circScrewBoltPattern.BindingLengthAddition = countableScrewBoltPattern.BindingLengthAddition;
                        circScrewBoltPattern.IsInverted = countableScrewBoltPattern.IsInverted;
                        circScrewBoltPattern.AssemblyLocation = countableScrewBoltPattern.AssemblyLocation;
                        circScrewBoltPattern.Coating = countableScrewBoltPattern.Coating;
                        circScrewBoltPattern.Material = countableScrewBoltPattern.Material;
                        circScrewBoltPattern.IgnoreMaxGap = countableScrewBoltPattern.IgnoreMaxGap;
                        circScrewBoltPattern.HoleTolerance = countableScrewBoltPattern.HoleTolerance;
                        circScrewBoltPattern.Connect(connectedFilerObjects, countableScrewBoltPattern.AssemblyLocation);
                        //exclude rectangular pattern from the custom connection
                        userConn.ExcludeObjectsFromConnection([countableScrewBoltPattern.GetObjectId()]);
                        //transfer the guid from the old object to the new one
                        string strOldHandle = countableScrewBoltPattern.Handle;
                        string strNewHandle = circScrewBoltPattern.Handle;

                        Guid guidToTransfer = countableScrewBoltPattern.GetUniqueId();
                        Guid uidDummy = Guid.NewGuid();
                        countableScrewBoltPattern.SetUniqueId(uidDummy);
                        circScrewBoltPattern.SetUniqueId(guidToTransfer);
                        //save the new bolt pattern
                        circScrewBoltPattern.WriteToDb();
                        //include new pattern in the connection and delete the old one                                 
                        userConn.IncludeObjectsInConnection([circScrewBoltPattern.GetObjectId()]);
                        countableScrewBoltPattern.DelFromDb();

                     }
                  }
               }
            }
         }
         else
            continue;

         //restore the DeleteRuleOnDeleteDriven value
         userConn.DeleteRuleOnDeleteDriven = bOlddeleteRuleOnDeleteDriven;
      }
      trans.Commit();//commit the changes before updating the custom connection type
   }

   // This is critical to call, otehrwise all the above changes will be lost at some point
   StructuralConnectionHandlerType.UpdateCustomConnectionType(conn, [], []);

   // Committing the Revit transaction
   ts = transaction.Commit();

   if (ts != TransactionStatus.Committed)
   {
      message = "Failed to commit the current transaction !";
      transaction.RollBack();
      return Result.Failed;
   }
}

See Also

Reference

Was this information helpful?