0

我正在为 Solidworks 制作插件。我想根据打开的文档(零件、装配体或绘图)更改插件任务窗格的内容。我怎样才能做到这一点?当 SldWrks 启动时,它运行 TaskpaneHostUI 中描述的形式。在我看来,我应该为其他形式制作其他课程。对于打开的零件文档,我创建了 PartUI 类。应该更改内容,当事件触发时,我明白这一点。但是如何更改内容,我找不到。

namespace SldWrksWorkAddin
{
    /// <summary>
    /// Our SolidWorks taskpane add-in
    /// </summary>
    public class TaskpaneIntegration : ISwAddin
    {
        #region Private Members

        /// <summary>
        /// The taskpane view for our add-in
        /// </summary>
        private TaskpaneView mTaskpaneView;

        /// <summary>
        /// The UI control that is going to be inside the SolidWorks taskpane view
        /// </summary>
        private SldWrksWorkAddin.TaskpaneHostUI mTaskpaneHost;

        private SldWrksWorkAddin.PartUI mPartUI;

        /// <summary>
        /// The current instance of the SolidWorks application
        /// </summary>
        private SldWorks mSolidWorksApplication;

        #endregion

        #region Public Members

        /// <summary>
        /// The unique Id to the taskpane used for registration in COM
        /// </summary>
        public const string SWTASKPANE_PROGID = "SldWrksWorkAddin.Taskpane";

        public ModelDoc2 swModel;
            
        #endregion

        #region SolidWorks Add-in Callbacks

        /// <summary>
        /// Called when SolidWorks has loaded our add-in and wants us to do our connection logic
        /// </summary>
        /// <param name="ThisSW">The current SolidWorks instance</param>
        /// <param name="Cookie">The current SolidWorks cookie Id</param>
        /// <returns></returns>
        public bool ConnectToSW(object ThisSW, int Cookie)
        {
            // Store a reference to the current SolidWorks instance
            mSolidWorksApplication = (SldWorks)ThisSW;

            // Store cookie Id
            mSwCookie = Cookie;

            // Setup callback info
            var ok = mSolidWorksApplication.SetAddinCallbackInfo2(0, this, mSwCookie);

            // Create our UI
            LoadUI();

            // Return ok
            return true;
        }  
           
        #endregion

        #region Create UI

        /// <summary>
        /// Create our Taskpane and inject our host UI
        /// </summary>
        private void LoadUI()
        {
            // Find location to our taskpane icon
            var imagePath = Path.Combine(Path.GetDirectoryName(typeof(TaskpaneIntegration).Assembly.CodeBase).Replace(@"file:\res\", string.Empty), "logo.png");

            // Create our Taskpane
            mTaskpaneView = mSolidWorksApplication.CreateTaskpaneView2(imagePath, string.Empty);

            // Load our UI into the taskpane
            mTaskpaneHost = (TaskpaneHostUI)mTaskpaneView.AddControl(SWTASKPANE_PROGID, string.Empty);
        }      

        #endregion
4

0 回答 0