PowerMill HelloWorld

方法1:通过工具从pmill.exe类型库中编译出来我们要二开的引用,通过创建类库添加引用,在进行注册表注册让powermill识别 ,
这种方式笔者尝试识别了。

1、添加微软SDK工具添加到PATH环境变量(里面有sn.exe文件)
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\x64

2、切换到PowerMill2023安装目录
 
2、使用强名称工具 sn.exce l生成强名称密钥文件
sn.exe -k key_pair.snk


3、查看powermill的版本号
wmic datafile where name="D:\\Program Files\\PowerMill 2023\\sys\\exec64\\pmill.exe" get version


4、从类型库中创建PowerMILL.dll
tlbimp.exe pmill.exe /keyfile:key_pair.snk /asmversion:20230.8.0.0

5、移动PowerMILL.dll到解决方案下面的bin目录下


6、添加PowerMILL.dll的引用


7、进入到bin目录,打开cmd执行脚本 添加插件到注册表

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe BasePlugin.dll   /register /codebase


8、注册插件 类名称不要改

 reg.exe ADD "HKCR\CLSID\{24FC6F19-753D-4AD6-940E-C1B79D68E386}\Implemented Categories\{311b0135-1826-4a8c-98de-f313289f815e}" /reg:64 /f

9、卸载插件
 reg.exe DELETE "HKCR\CLSID\{24FC6F19-753D-4AD6-940E-C1B79D68E386}\Implemented Categories\{311b0135-1826-4a8c-98de-f313289f815e}" /reg:64 /f

方法2:
powerMill安装目录下有对应的示例工程,我们可以通过示例工程进行修改。
在这里插入图片描述

修改dll的名称、工程名。然后拷贝示例工程的powerMill.dll引用。

//=============================================================================
//D The SamplePlugin class.
//
// For this plugin to be usuable by PowerMILL (minimum version 2012 R2), two things must be done:
// 
// 1. Register the class for COM interop. From the 'bin\Debug' directory in a command window, type:
//
//    C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\regasm.exe WNXPluginCS.dll /register /codebase 
//
// 2. Add PowerMILL's component category to the plugin.  This involves adding a single registry key:
// 
//    reg.exe ADD "HKCR\CLSID\{24FC6F19-753D-4AD6-940E-C1B79D68E386}\Implemented Categories\{311b0135-1826-4a8c-98de-f313289f815e}" /reg:64 /f
//
// These steps need only to be performed once, and do not need repeating each time the plugin
// is rebuilt.
//
// PowerMILL must not be running when the plugin is rebuilt, as it the DLL will be locked.
//
// ----------------------------------------------------------------------------
// Copyright 2012 Delcam plc., Birmingham, UK
// ----------------------------------------------------------------------------
//
// History.
// DICC  Who When     What
// ----- --- -------- ---------------------------------------------------------
// 95792 PSL 29/02/12 Written.
//-----------------------------------------------------------------------------
using Delcam.Plugins.Framework;
using PowerMILL;
using System;
using System.Runtime.InteropServices; // For Guid and ComVisible attributes
using System.Windows.Forms;           // For Message boxes and WinForms
using System.Windows.Interop;         // For WindowInteropHelper
using Delcam.Plugins.Framework;
using Delcam.Plugins.Localisation;

namespace SamplePluginCS
{
    // Attributes that allow the SamplePlugin class to be created as a COM object
    // Note: regenerate this guid for each new plugin you create - it must be unique!
    [Guid("24FC6F19-753D-4AD6-940E-C1B79D68E386")]
    [ClassInterface(ClassInterfaceType.None)]
    [ComVisible(true)]
    public class SamplePlugin : PluginFrameworkWithPanes, PowerMILL.IPowerMILLPlugin
    {
        // Private member data
        private string m_token;
        private PowerMILL.PluginServices m_plugin_services;
        private int m_parent_window;

        // Implementation of the IPowerMILLPlugin interface
        #region IPowerMILLPlugin Members

        //=============================================================================
        /// <summary>
        /// Gets the author of the plugin.
        /// </summary>
        //
        // History.
        // DICC  Who When     What
        // ----- --- -------- ---------------------------------------------------------
        // 95792 PSL 29/02/12 Written.
        //-----------------------------------------------------------------------------
        public string Author
        {
            // This is displayed on the plugin manager in PowerMILL
            get { return "王乃醒"; }
        }

        //=============================================================================
        /// <summary>
        /// Gets a description of the plugin.
        /// </summary>
        //
        // History.
        // DICC  Who When     What
        // ----- --- -------- ---------------------------------------------------------
        // 95792 PSL 29/02/12 Written.
        //-----------------------------------------------------------------------------
        public string Description
        {
            // This is displayed on the plugin manager in PowerMILL
            get { return "这是王乃醒开发的一个PowerMill插件"; }
        }

        //=============================================================================
        /// <summary>
        /// Called to display the plugin's option form, if it has one.
        /// </summary>
        //
        // History.
        // DICC  Who When     What
        // ----- --- -------- ---------------------------------------------------------
        // 95792 PSL 29/02/12 Written.
        //-----------------------------------------------------------------------------
        public void DisplayOptions()
        {
            // We don't have an options form, but throw up a message box just to demonstrate the principal
            MessageBox.Show("This plugin doesn't currently have any options.");
        }

        //=============================================================================
        /// <summary>
        /// Gets whether the plugin has an options form.
        /// </summary>
        //
        // History.
        // DICC  Who When     What
        // ----- --- -------- ---------------------------------------------------------
        // 95792 PSL 29/02/12 Written.
        //-----------------------------------------------------------------------------
        public bool HasOptions
        {
            // We can display an options form (albeit, a very simple and useless one)
            get { return true; }
        }

        //=============================================================================
        /// <summary>
        /// Called to initialise the plugin.
        /// </summary>
        /// <param name="Token">The identifier that PowerMILL uses to distinguish between different plugins.</param>
        /// <param name="pServices">The interface the plugin uses to communicate with PowerMILL</param>
        /// <param name="ParentWindow">The HWND of PowerMILL's main window.</param>
        //
        // History.
        // DICC  Who When     What
        // ----- --- -------- ---------------------------------------------------------
        // 95792 PSL 29/02/12 Written.
        //-----------------------------------------------------------------------------
        public void Initialise(string Token, PowerMILL.PluginServices pServices, int ParentWindow)
        {
            // Cache the arguments, as we'll need them to communicate with PowerMILL and to correctly parent forms
            m_token = Token;
            m_plugin_services = pServices;
            m_parent_window = ParentWindow;
           
        }

        //=============================================================================
        /// <summary>
        /// Gets the minimum supported PowerMILL version.
        /// </summary>
        //
        // History.
        // DICC  Who When     What
        // ----- --- -------- ---------------------------------------------------------
        // 95792 PSL 29/02/12 Written.
        //-----------------------------------------------------------------------------
        public void MinPowerMILLVersion(out int pMajor, out int pMinor, out int pIssue)
        {
            // We require a minimum of PowerMILL v14, i.e. 2012 R2
            pMajor = 14;
            pMinor = 0;
            pIssue = 0;
        }

        //=============================================================================
        /// <summary>
        /// Gets the name of the plugin.
        /// </summary>
        //
        // History.
        // DICC  Who When     What
        // ----- --- -------- ---------------------------------------------------------
        // 95792 PSL 29/02/12 Written.
        //-----------------------------------------------------------------------------
        public string Name
        {
            // This is displayed on the plugin manager in PowerMILL
            get { return "WNX First Plugin"; }
        }

        //=============================================================================
        /// <summary>
        /// Gets the icon that is used on the plugin manager form.
        /// </summary>
        /// <param name="pFormat">The pixel format.</param>
        /// <param name="pPixelData">The pixel array</param>
        /// <param name="pWidth">The width of the icon.  Should be 32 if valid.</param>
        /// <param name="pHeight">The width of the icon.  Should be 32 if valid.</param>
        //
        // History.
        // DICC  Who When     What
        // ----- --- -------- ---------------------------------------------------------
        // 95792 PSL 29/02/12 Written.
        //-----------------------------------------------------------------------------
        public void PluginIconBitmap(out PowerMILL.PluginBitmapFormat pFormat, out byte[] pPixelData, out int pWidth, out int pHeight)
        {
            // We don't support an icon, so we'll get the default one
            pFormat = PowerMILL.PluginBitmapFormat.PMILL_BITMAP_FORMAT_FAIL;
            pPixelData = null;
            pWidth = 0;
            pHeight = 0;
        }

        //=============================================================================
        /// <summary>
        /// Called before Initialise() to set locale that the plugin should use.
        /// </summary>
        /// <param name="locale"></param>
        //
        // History.
        // DICC  Who When     What
        // ----- --- -------- ---------------------------------------------------------
        // 95792 PSL 29/02/12 Written.
        //-----------------------------------------------------------------------------
        public void PreInitialise(string locale)
        {
            // We're not translating the GUI, so we don't care about the locale
        }

        //=============================================================================
        /// <summary>
        /// Called to request the plugin process a command.
        /// </summary>
        /// <param name="Command"></param>
        //
        // History.
        // DICC  Who When     What
        // ----- --- -------- ---------------------------------------------------------
        // 95792 PSL 29/02/12 Written.
        //-----------------------------------------------------------------------------
        public void ProcessCommand(string Command)
        {
            // We wish to handle a few simple commands...

            // Strip any white space, and convert  to uppercase
            Command = Command.Trim().ToUpper();

            // Handle known commands starting with:
            // PLUGIN {12C35AEC-C187-41AA-A7C8-7712695D65E8} ...
            switch (Command)
            {
                case "WPF_FORM":
                    RaiseWpfForm();
                    break;
                case "WIN_FORM":
                    RaiseWinForm();
                    break;
                default:
                    break;
            }
        }

        //=============================================================================
        /// <summary>
        /// Called to request the plugin process an event.
        /// </summary>
        /// <param name="EventData"></param>
        //
        // History.
        // DICC  Who When     What
        // ----- --- -------- ---------------------------------------------------------
        // 95792 PSL 29/02/12 Written.
        //-----------------------------------------------------------------------------
        public void ProcessEvent(string EventData)
        {

            // We don't support events
        }

        //=============================================================================
        /// <summary>
        /// Called when PowerMILL is opening or saving a project.
        /// </summary>
        /// <param name="Path"></param>
        /// <param name="Saving"></param>
        //
        // History.
        // DICC  Who When     What
        // ----- --- -------- ---------------------------------------------------------
        // 95792 PSL 29/02/12 Written.
        //-----------------------------------------------------------------------------
        public void SerializeProjectData(string Path, bool Saving)
        {
            // We don't need to load or save data in the project directory
        }

        //=============================================================================
        /// <summary>
        /// Called when the plugin is about to be terminated.
        /// </summary>
        //
        // History.
        // DICC  Who When     What
        // ----- --- -------- ---------------------------------------------------------
        // 95792 PSL 29/02/12 Written.
        //-----------------------------------------------------------------------------
        public void Uninitialise()
        {
            // We should always force a garbage collection, to clear away any orphaned references 
            // to PowerMILL that could prevent it from shutting down as a COM server
            GC.Collect();
        }

        //=============================================================================
        /// <summary>
        /// Called to ascertain the plugin's version.
        /// </summary>
        //
        // History.
        // DICC  Who When     What
        // ----- --- -------- ---------------------------------------------------------
        // 95792 PSL 29/02/12 Written.
        //-----------------------------------------------------------------------------
        public void Version(out int pMajor, out int pMinor, out int pIssue)
        {
            // This is the first version of the plugin
            pMajor = 1;
            pMinor = 0;
            pIssue = 0;
        }

        #endregion

        //=============================================================================
        /// <summary>
        /// Raise a WPF form.
        /// </summary>
        //
        // History.
        // DICC  Who When     What
        // ----- --- -------- ---------------------------------------------------------
        // 95792 PSL 29/02/12 Written.
        //-----------------------------------------------------------------------------
        private void RaiseWpfForm()
        {
            // Create the new window
            WPFForm wpf_form = new WPFForm(m_token, m_plugin_services);

            // Attempt to parent the window with PowerMILL
            WindowInteropHelper wih = new WindowInteropHelper(wpf_form);
            wih.Owner = new IntPtr(m_parent_window);

            // Show the new window
            wpf_form.Show();
        }

        //=============================================================================
        /// <summary>
        /// Raise a WinForm form
        /// </summary>
        //
        // History.
        // DICC  Who When     What
        // ----- --- -------- ---------------------------------------------------------
        // 95792 PSL 29/02/12 Written.
        //-----------------------------------------------------------------------------
        private void RaiseWinForm()
        {
            // Create a new WinForms form
            WinForm win_form = new WinForm();

            // Attempt to parent the window with PowerMILL
            WinFormWrapper wfw = new WinFormWrapper(m_parent_window);

            // Show the new window
            win_form.Show(wfw);
        }

        public void PluginIconBitmap(out PluginBitmapFormat pFormat, out Array pPixelData, out int pWidth, out int pHeight)
        {
            throw new NotImplementedException();
        }

      
    }
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值