Revit.SDK.Samples.NewRebar.CS.RebarShapeDef.Commit C# (CSharp) Method

Commit() public method

Submit RebarShapeDefinition. All the parameters and constraints will be added to RebarShape. The RebarShape will be added to Revit document after successfully submitted.
public Commit ( System.Windows.Forms.Document rvtDoc, DefinitionGroup defGroup ) : void
rvtDoc System.Windows.Forms.Document
defGroup DefinitionGroup Parameter definition group
return void
        public void Commit(Document rvtDoc, DefinitionGroup defGroup)
        {
            // Submit all the parameters.
            foreach (RebarShapeParameter param in m_parameters)
            {
                param.Commit(rvtDoc, defGroup);
            }

            // Submit all the constraints.
            foreach (ConstraintOnRebarShape constraint in m_constraints)
            {
                constraint.Commit();
            }

            // Submit the RebarShape.
            if (m_rebarshapeDefinition.Complete)
            {
                m_rebarshapeDefinition.CheckDefaultParameterValues(0, 0);
            }
            else
            {
                throw new Exception("The Rebar shape definition is not completed.");
            }
        }

Usage Example

        /// <summary>
        /// OK Button, commit the RebarShapeDef, if there are not any exception,
        /// The RebarShape will be added to Revit Document successfully.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void okButton_Click(object sender, EventArgs e)
        {
            try
            {
                m_rebarShapeDef.Commit(m_rvtDoc, GetOrCreateDefinitionGroup());
            }
            catch (Exception ex)
            {
                MessageBox.Show("Rebar shape creation failed:" + ex.ToString());
                return;
            }

            DialogResult = DialogResult.OK;
            Close();
        }