Click or drag to resize
CTInterfaceOnAfterButtonFunction Event
Notification is sent after user has clicked a button representing a button function that is associated with a property in CUSTOMTOOLS Properties pane. Event is triggered when user has closed the dialog box associated with the button function.

Namespace: ATR.CT.CTInterface
Assembly: CTInterface (in CTInterface.dll)
Syntax
public event EventHandler<CTInterfaceButtonFuncArgs> OnAfterButtonFunction

Value

Type: SystemEventHandlerCTInterfaceButtonFuncArgs
Examples
This example shows how you can use OnAfterButtonFunction event to modify custom properties after user has taken action by executing a button function associated with a CUSTOMTOOLS custom property. To use this example, download and use Job Stages CUSTOMTOOLS profile. In the profile there's is custom property called Manufacturing time (s) in the Item group. It has a button function GetUserScopeData associated with it opening a separate dialog box allowing designer to enter needed job stages to manufacture designed part. In this example, required attributes for a job stage for simplicity are name of the job stage and required processing time in seconds. After user has entered job stages the total processing (manufacturing) time needed to make designed part is calculated to Manufacturing time (s) property. The script example below takes benefit of OnAfterButtonFunction event to sum up entered time and display it in the Properties pane.

C#
// @auto-reference {[CT_INSTALL_PATH]\CTInterface.dll}
// @auto-reference {[CT_INSTALL_PATH]\Interop.CTEngineLib.dll}
// @auto-reference {C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Data.dll}
// @auto-reference {C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Windows.Forms.dll}


using System;
using System.IO;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using System.Windows.Forms;

using ATR.CT.CTInterface;
using CTEngineLib;

namespace CUSTOMTOOLS.APIExample
{
  public class ManufacturingTime
  {
    private CTInterface _ctInterface;

    public ManufacturingTime(ATR.CT.CTInterface.CTInterface ctInterface)
    {
      _ctInterface = ctInterface;
      _ctInterface.OnAfterButtonFunction += _ctInterface_OnAfterButtonFunction;
    }

    /// <summary>
    /// Called after the dialog box associated with button function is closed by user.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e">Information about button function and properties having "Allow scripting"
    /// set in CUSTOMTOOLS</param>
    void _ctInterface_OnAfterButtonFunction(object sender, CTInterface.ButtonFuncArgs e)
    {
      // We are only interested in user scope custom 1 data which has job stages defined
      // in CUSTOMTOOLS profile we are using
      if(e.ButtonFunctionResult == ButtonFunctionResult.DialogOk && 
        e.ButtonFunction == ctButtonFunction.ctButtonFunctionGetUserScopeData)
      {
        // Job stages are in XML form in matrix data
        string totalManufacturingTime = GetTotalManufacturingTime(e.Property.MatrixData).ToString();
        // Value needs to be changed through e.Properties in order to update it in UI
        ICustomProperty manuTime = e.Properties.SingleOrDefault(p => p.Property.ID == e.Property.Property.ID);
        if(manuTime != null && manuTime.OriginalValue != totalManufacturingTime)
        {
          manuTime.Value = totalManufacturingTime;
        }
      }
    }

    /// <summary>
    /// Calculates total manufacturing time for item by summing up time on each job stage row
    /// </summary>
    /// <param name="jobStages">Defined job stages as XML</param>
    /// <returns>Summed up manufacturing time when successful; otherwise 0</returns>
    private int GetTotalManufacturingTime(string jobStages)
    {
      try
      {
        int totalTime = 0;

        XDocument jobStagesXML = XDocument.Parse(jobStages);

        IEnumerable<XElement> jobTimes =  
          from field in jobStagesXML.Descendants("field")  
          where (string)field.Attribute("name") == "job_time"  
          select field;
        foreach(var time in jobTimes)
        {
          int stageTime = 0;
          if(int.TryParse(time.Value, out stageTime))
          {
            totalTime += int.Parse(time.Value);
          }
        }

        return totalTime;
      }
      catch(Exception ex)
      {
        MessageBox.Show(string.Format("An error occurred while calculating manufacturing time:{0}{1}",
          Environment.NewLine, ex.Message));
      }
      return 0; // Default
    }
  }
}
Availability

CUSTOMTOOLS 2016 SP4


See Also