 | 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.CTInterfaceAssembly: CTInterface (in CTInterface.dll) Version: 25.0
Syntaxpublic event EventHandler<CTInterfaceButtonFuncArgs> OnAfterButtonFunction
Public Event OnAfterButtonFunction As EventHandler(Of CTInterfaceButtonFuncArgs)
Value
EventHandlerCTInterfaceButtonFuncArgs
Example
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.

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;
}
void _ctInterface_OnAfterButtonFunction(object sender, CTInterface.ButtonFuncArgs e)
{
if(e.ButtonFunctionResult == ButtonFunctionResult.DialogOk &&
e.ButtonFunction == ctButtonFunction.ctButtonFunctionGetUserScopeData)
{
string totalManufacturingTime = GetTotalManufacturingTime(e.Property.MatrixData).ToString();
ICustomProperty manuTime = e.Properties.SingleOrDefault(p => p.Property.ID == e.Property.Property.ID);
if(manuTime != null && manuTime.OriginalValue != totalManufacturingTime)
{
manuTime.Value = totalManufacturingTime;
}
}
}
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;
}
}
}
Revision HistoryDate | Version | Description |
---|
- | 2016 SP4 | First Release |
See Also