Pm插件最重要的优势,就是能够使界面实时响应PM数据变化
下面展示PM 插件可订阅的事件。
其中有一些事件是无效的,例如"ProcessedCommand"命令输出事件。
<?xml version="1.0" encoding="utf-8"?>
<!-- PowerMill 可订阅事件汇总-->
<PowerMILLEvents>
<!-- 应用事件 events -->
<!-- 项目打开失败 events -->
<ProjectOpenFailed event_group="Application">
<Path/>
</ProjectOpenFailed>
<!-- 项目关闭时 events -->
<ProjectClosing event_group="Application"/>
<!-- 归档文件插入完成 -->
<ArchiveInserted event_group="Application">
<Path/>
</ArchiveInserted>
<!-- 归档文件插入时 -->
<ArchiveInserting event_group="Application">
<Path/>
</ArchiveInserting>
<SessionInserted event_group="Application">
<Path/>
</SessionInserted>
<ModeChanged event_group="Application">
<Mode/>
<PreviousMode/>
</ModeChanged>
<ProjectOpening event_group="Application">
<Path/>
<ReadOnly/>
</ProjectOpening>
<ArchiveOpened event_group="Application">
<Path/>
</ArchiveOpened>
<ProcessedCommand event_group="Application">
<Command/>
</ProcessedCommand>
<ElectrodeProjectOpened event_group="Application">
<Project/>
<TrodeFile/>
<TrodeName/>
</ElectrodeProjectOpened>
<FormRaised event_group="Application">
<FormName/>
</FormRaised>
<LocaleChanged event_group="Application">
<Locale/>
</LocaleChanged>
<ProjectSaved event_group="Application">
<AutoSave/>
<Path/>
</ProjectSaved>
<ProjectClosed event_group="Application"/>
<ToolbarMaximised event_group="Application">
<ToolbarName/>
</ToolbarMaximised>
<ProjectOpened event_group="Application">
<Path/>
<ReadOnly/>
</ProjectOpened>
<TemplateInserting event_group="Application">
<Path/>
</TemplateInserting>
<ProjectSavedAs event_group="Application">
<Path/>
<PreviousPath/>
</ProjectSavedAs>
<ProjectInserted event_group="Application">
<Path/>
</ProjectInserted>
<ToolbarMinimised event_group="Application">
<ToolbarName/>
</ToolbarMinimised>
<ArchiveOpening event_group="Application">
<Path/>
</ArchiveOpening>
<ArchiveSaved event_group="Application">
<Path/>
</ArchiveSaved>
<SessionInserting event_group="Application">
<Path/>
</SessionInserting>
<ToolbarLowered event_group="Application">
<ToolbarName/>
</ToolbarLowered>
<UnitsChanged event_group="Application">
<Units/>
</UnitsChanged>
<TemplateSaved event_group="Application">
<Path/>
</TemplateSaved>
<ToolbarRaised event_group="Application">
<ToolbarName/>
</ToolbarRaised>
<TemplateInserted event_group="Application">
<Path/>
</TemplateInserted>
<FormLowered event_group="Application">
<FormName/>
</FormLowered>
<!-- Boundary events -->
<BoundaryGeometryModified event_group="Boundary">
<Name/>
</BoundaryGeometryModified>
<BoundaryCalculationStarted event_group="Boundary">
<Name/>
<Process/>
</BoundaryCalculationStarted>
<BoundaryCalculationFinished event_group="Boundary">
<Name/>
<Process/>
<Status/>
</BoundaryCalculationFinished>
<!-- EntityManager events -->
<EntityActivated event_group="EntityManager">
<Deactivated/>
<EntityType/>
<Name/>
</EntityActivated>
<EntityDeleted event_group="EntityManager">
<EntityType/>
<Name/>
</EntityDeleted>
<EntityCreated event_group="EntityManager">
<EntityType/>
<Name/>
</EntityCreated>
<EntityDeactivated event_group="EntityManager">
<Activated/>
<EntityType/>
<Name/>
<Reason/>
</EntityDeactivated>
<EntityDrawn event_group="EntityManager">
<EntityType/>
<Name/>
</EntityDrawn>
<EntityRenamed event_group="EntityManager">
<EntityType/>
<Name/>
<PreviousName/>
</EntityRenamed>
<EntityUndrawn event_group="EntityManager">
<EntityType/>
<Name/>
</EntityUndrawn>
<!-- FeatureSet events -->
<FeatureSetGeometryModified event_group="FeatureSet">
<Name/>
</FeatureSetGeometryModified>
<FeatureSetFeatureRemoved event_group="FeatureSet">
<FeatureName/>
<Name/>
</FeatureSetFeatureRemoved>
<FeatureSetFeatureRenamed event_group="FeatureSet">
<FeatureName/>
<Name/>
<PreviousFeatureName/>
</FeatureSetFeatureRenamed>
<FeatureSetFeatureAdded event_group="FeatureSet">
<FeatureName/>
<Name/>
</FeatureSetFeatureAdded>
<!-- Group events -->
<GroupEntityAdded event_group="Group">
<EntityName/>
<EntityType/>
<Name/>
</GroupEntityAdded>
<GroupEntityRemoved event_group="Group">
<EntityName/>
<EntityType/>
<Name/>
</GroupEntityRemoved>
<!-- LevelsAndSets events -->
<LevelGeometryAcquired event_group="LevelsAndSets">
<Name/>
</LevelGeometryAcquired>
<SetGeometryAcquired event_group="LevelsAndSets">
<Name/>
</SetGeometryAcquired>
<SetGeometryRemoved event_group="LevelsAndSets">
<Name/>
</SetGeometryRemoved>
<!-- MachineTool events -->
<MachineToolCollisionTypeChanged event_group="MachineTool">
<MachineToolCollisionType/>
</MachineToolCollisionTypeChanged>
<MachineToolMovement event_group="MachineTool">
<AuxI/>
<AuxJ/>
<AuxK/>
<CollisionState/>
<ComponentType/>
<ComponentTypeChanged/>
<DirI/>
<DirJ/>
<DirK/>
<Feed/>
<FeedChanged/>
<MoveType/>
<MoveTypeChanged/>
<Name/>
<PointGeometry/>
<PointGeometryChanged/>
<PosX/>
<PosY/>
<PosZ/>
<SpindleSpeed/>
<SpindleSpeedChanged/>
<Time/>
<TimeValid/>
<Tool/>
<ToolChanged/>
</MachineToolMovement>
<!-- NX程序 事件 -->
<NCProgramItemAdded event_group="NCProgram">
<InsertedItemName/>
<InsertedItemType/>
<Name/>
</NCProgramItemAdded>
<NCProgramItemRemoved event_group="NCProgram">
<Name/>
<RemovedItemName/>
<RemovedItemType/>
</NCProgramItemRemoved>
<NCProgramWritten event_group="NCProgram">
<Name/>
<OutputFormat/>
<OutputPath/>
<OutputType/>
</NCProgramWritten>
<!-- 参数事件 -->
<CurrentParameterChanged event_group="Parameter">
<ParameterName/>
<PreviousValue/>
<Value/>
</CurrentParameterChanged>
<SimulationStateParameterChanged event_group="Parameter">
<ParameterName/>
<PreviousValue/>
<Value/>
</SimulationStateParameterChanged>
<EntityParameterChanged event_group="Parameter">
<EntityName/>
<EntityType/>
<ParameterName/>
<PreviousValue/>
<Value/>
</EntityParameterChanged>
<SystemParameterChanged event_group="Parameter">
<ParameterName/>
<PreviousValue/>
<Value/>
</SystemParameterChanged>
<!-- Pattern events -->
<PatternGeometryModified event_group="Pattern">
<Name/>
</PatternGeometryModified>
<!-- 设置 events -->
<SetupToolpathsReordered event_group="Setup">
<Name/>
</SetupToolpathsReordered>
<SetupToolpathRemoved event_group="Setup">
<Name/>
<ToolpathName/>
</SetupToolpathRemoved>
<SetupToolpathAdded event_group="Setup">
<Name/>
<ToolpathName/>
</SetupToolpathAdded>
<!-- 仿真事件 events -->
<SimulatePlay event_group="Simulate">
<Speed/>
</SimulatePlay>
<SimulateSearch event_group="Simulate">
<Direction/>
</SimulateSearch>
<SimulateIssueDetected event_group="Simulate">
<Issue/>
</SimulateIssueDetected>
<SimulatePause event_group="Simulate"/>
<SimulateActionComplete event_group="Simulate">
<Action/>
</SimulateActionComplete>
<SimulateJump event_group="Simulate">
<Target/>
</SimulateJump>
<SimulateStep event_group="Simulate">
<Direction/>
<Speed/>
</SimulateStep>
<!-- 残留模型事件 events -->
<StockModelStateInvalidated event_group="StockModel">
<Name/>
<StateName/>
<StateType/>
</StockModelStateInvalidated>
<StockModelCalculationFinished event_group="StockModel">
<Name/>
<Process/>
<Status/>
</StockModelCalculationFinished>
<StockModelStateCalculated event_group="StockModel">
<Name/>
<StateName/>
<StateType/>
</StockModelStateCalculated>
<StockModelStateRemoved event_group="StockModel">
<Name/>
<StateName/>
<StateType/>
</StockModelStateRemoved>
<StockModelStateAdded event_group="StockModel">
<Name/>
<StateName/>
<StateType/>
</StockModelStateAdded>
<!-- 刀具事件 -->
<!---->
<ToolHolderGeometryModified event_group="Tool">
<Name/>
</ToolHolderGeometryModified>
<ToolCutterGeometryModified event_group="Tool">
<Name/>
</ToolCutterGeometryModified>
<ToolShankGeometryModified event_group="Tool">
<Name/>
</ToolShankGeometryModified>
<!-- 刀轨事件 events -->
<!--刀轨计算开始-->
<ToolpathCalculationStarted event_group="Toolpath">
<Name/>
<Process/>
</ToolpathCalculationStarted>
<!--刀轨计算结束-->
<ToolpathCalculationFinished event_group="Toolpath">
<Name/>
<Process/>
<Status/>
</ToolpathCalculationFinished>
</PowerMILLEvents>
举个例子:
假如需要在项目打开完毕后执行某个操作
第一步:要找到是否有对应可订阅事件,经过在上述事件列表中的寻找,可知如下事件符合要求
<ProjectOpened event_group="Application">
<Path/>
<ReadOnly/>
</ProjectOpened>
第二步:构造委托函数
委托函数原型如下
/// <summary>
/// The delegate for event callbacks.
/// </summary>
/// <param name="event_name">The name of the event that was subscribed to.</param>
/// <param name="event_arguments">A dictionary of key/values, which conatins the list of event fields and corresponding data.</param>
public delegate void EventCallback(string event_name, Dictionary<string, string> event_arguments);
据此:
//响应项目打开
private void OnProjectOpened(string event_name, Dictionary<string, string> event_arguments)
{
//该事件携带两个参数
//event_arguments["ReadOnly"] 是否是可读的
//event_arguments["Path"] 图档路径
}
第三步:订阅事件
注册主要是用到了EventSubscription类
它有两个构造函数
//=============================================================================
/// <summary>
/// Constructs an event subscription object without filtering.
/// </summary>
/// <param name="event_name">The name of the event being subscribed to.</param>
/// <param name="callback">The function delgate that will be called when a matching event occurs, with all the event data.</param>
//
// History.
// DICC Who When What
// ----- --- -------- ---------------------------------------------------------
// 93978 PSL 10/11/11 Written.
//-----------------------------------------------------------------------------
public EventSubscription(string event_name, EventCallback callback)
{
m_event_name = event_name;
m_callback_function = callback;
}
//=============================================================================
/// <summary>
/// Constructs an event subscription object without filtering.
/// </summary>
/// <param name="event_name">The name of the event being subscribed to.</param>
/// <param name="filter_field">The name of the filter field.</param>
/// <param name="filter_value">The data within the specified field that must match the event.</param>
/// <param name="callback">The function delgate that will be called when a matching event occurs, with all the event data.</param>
//
// History.
// DICC Who When What
// ----- --- -------- ---------------------------------------------------------
// 93978 PSL 10/11/11 Written.
//-----------------------------------------------------------------------------
public EventSubscription(string event_name, string filter_field, string filter_value, EventCallback callback)
{
m_event_name = event_name;
m_filter_field = filter_field;
m_filter_value = filter_value;
m_callback_function = callback;
}
简单来说:第一种是直接注册,第二种是参数过滤
在这里只用第一种注册
var even = new EventSubscription("ProjectOpened", OnProjectOpened);
EventUtil.Subscribe(even);
而后PM,打开一个项目后,这个函数就被调用