C# SolidWorks 二次开发 -各种菜单命令增加方式
今天给大家讲一讲solidworks中各种菜单界面,如下图,大概有13处,也许还不完整哈。
- 1.CommandManager选项卡
- 2.下拉选项卡
- 3.菜单栏
- 4.下级菜单
- 5.浮动工具栏
- 6.快捷方式工具栏
- 7.FeatureManager工具栏区域
- 8.MontionManager区域 ModelView?
- 9.任务窗格
- 10.前导视图工具栏
- 11.定制三方工具条
- 12.PMP界面
- 13.右键菜单





我们来看一下每个方式的创建方式及核心代码:
1+3+5.
CommandManager选项卡上 + 菜单栏
//菜单List<int> cmdIndexs = new List<int>();//API提示的信息有误//第一个参数是菜单里面的名称//第三个参数是提示信息//第四个参数是工具条上的名称var tempCmdIndex1 = cmdGroup.AddCommandItem2("Cmd1", -1, "Cmd Tooltip1", "Cmd-1", 0, $"FunctionProxy({mainItemIds[0]})", $@"EnableFunction({mainItemIds[0]})", mainItemIds[0], menuToolbarOption);var tempCmdIndex2 = cmdGroup.AddCommandItem2("Cmd2", -1, "Cmd Tooltip2", "Cmd-2", 1, $"FunctionProxy({mainItemIds[1]})", $@"EnableFunction({mainItemIds[1]})", mainItemIds[1], menuToolbarOption);var tempCmdIndex3 = cmdGroup.AddCommandItem2("Cmd3", -1, "Cmd Tooltip3", "Cmd-3", 2, $"FunctionProxy({mainItemIds[2]})", $@"EnableFunction({mainItemIds[2]})", mainItemIds[2], menuToolbarOption);cmdIndexs.Add(tempCmdIndex1);cmdIndexs.Add(tempCmdIndex2);cmdIndexs.Add(tempCmdIndex3);cmdGroup.HasToolbar = true; //(浮动工具栏)cmdGroup.HasMenu = true;//(菜单栏)cmdGroup.Activate();//增加到工具条,是通过每个文档对象来增加的。 比如零件 装配 工程图bool bResult;foreach (int type in docTypes){CommandTab cmdTab;cmdTab = iCmdMgr.GetCommandTab(type, Title);//如果已经存在,并且id命令有变化,需要移除之后 ,重新增加。if (cmdTab != null & !getDataResult && ignorePrevious){bool res = iCmdMgr.RemoveCommandTab(TabToRemove: cmdTab);cmdTab = null;}//工具栏为空时,重新增加if (cmdTab == null){cmdTab = iCmdMgr.AddCommandTab(type, Title);CommandTabBox cmdBox = cmdTab.AddCommandTabBox();List<int> cmdIDs = new List<int>();//工具栏样式,List<int> showTextType = new List<int>();for (int i = 0; i < cmdIndexs.Count; i++){cmdIDs.Add(cmdGroup.get_CommandID(i));showTextType.Add((int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow);}//把下拉式工具栏加到菜单里。cmdIDs.Add(flyGroup1.CmdID);showTextType.Add((int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow);cmdIDs.Add(flyGroup2.CmdID);showTextType.Add((int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow);bResult = cmdBox.AddCommands(cmdIDs.ToArray(), showTextType.ToArray());CommandTabBox cmdBox1 = cmdTab.AddCommandTabBox();//这个是加分割线,记得从后往前,因为分割后最前的id集变少了。//cmdTab.AddSeparator(cmdBox1, cmdIDs[0]);}}

工具栏上的下拉+快捷方式工具栏

FlyoutGroup flyGroup1 = iCmdMgr.CreateFlyoutGroup2(flyoutGroupID1, "FlyoutGroup1", "可下拉1", "工具栏说明",cmdGroup.MainIconList, cmdGroup.IconList, $"FlyoutCallback(6000)", "FlyoutEnable");flyGroup1.FlyoutType = (int)swCommandFlyoutStyle_e.swCommandFlyoutStyle_Simple;var addResult = flyGroup1.AddContextMenuFlyout((int)swDocumentTypes_e.swDocPART, (int)swSelectType_e.swSelFACES);FlyoutGroup flyGroup2 = iCmdMgr.CreateFlyoutGroup2(flyoutGroupID2, "FlyoutGroup2", "可下拉2", "工具栏说明2",cmdGroup.MainIconList, cmdGroup.IconList, $"FlyoutCallback(7000)", "FlyoutEnable");flyGroup2.FlyoutType = (int)swCommandFlyoutStyle_e.swCommandFlyoutStyle_Simple;public void FlyoutCallback(int gId){if (gId==flyoutGroupID1){FlyoutGroup flyGroup1 = iCmdMgr.GetFlyoutGroup(gId);flyGroup1.RemoveAllCommandItems();flyGroup1.AddCommandItem("AAA", "test", 0, $"FlyoutCommandItem1({gId+1})", $"FlyoutEnableCommandItem1({gId+1})");flyGroup1.AddCommandItem("BBB", "test", 0, $"FlyoutCommandItem1({gId+2})", $"FlyoutEnableCommandItem1({gId+2})");flyGroup1.AddCommandItem("CCC", "test", 0, $"FlyoutCommandItem1({gId+3})", $"FlyoutEnableCommandItem1({gId+3})");}if (gId == flyoutGroupID2){FlyoutGroup flyGroup2 = iCmdMgr.GetFlyoutGroup(gId);flyGroup2.RemoveAllCommandItems();flyGroup2.AddCommandItem("XXX", "test", 0, $"FlyoutCommandItem1({gId + 1})", $"FlyoutEnableCommandItem1({gId+1})");flyGroup2.AddCommandItem("YYY", "test", 0, $"FlyoutCommandItem1({gId + 2})", $"FlyoutEnableCommandItem1({gId+2})");}if (gId==7000){SwApp.SendMsgToUser("id==7000");}}
4.下级菜单

var cmdGroupSub = iCmdMgr.CreateCommandGroup2(mainSubCmdGroupID, $"Addin Study\\SubMenu", ToolTip, "", -1, ignorePrevious, ref cmdGroupErr);cmdGroupSub.MainIconList = mainIcons;cmdGroupSub.IconList = icons;cmdGroupSub.AddCommandItem2($@"SubCmd4", -1, "Cmd Tooltip4", "Cmd-4", 2, $"FunctionProxy({mainItemIds[2]})", $@"EnableFunction({mainItemIds[2]})", mainItemIds[2], menuToolbarOption);cmdGroupSub.Activate();

#region 工具菜单栏下面显示新菜单项var menuId = iSwApp.AddMenuItem5((int)swDocumentTypes_e.swDocPART, addinCookieID, "子菜单1@新菜单1", 0, "FlyoutCallback(7000)", "FlyoutEnable", "My menu item", icons);var menuId2 = iSwApp.AddMenuItem5((int)swDocumentTypes_e.swDocPART, addinCookieID, "子菜单3@子菜单2@新菜单1", 0, "FlyoutCallback(7000)", "FlyoutEnable", "My menu item", icons);var menuId3 = iSwApp.AddMenuItem5((int)swDocumentTypes_e.swDocPART, addinCookieID, "子菜单4@Addin Study", 0, "FlyoutCallback(7000)", "FlyoutEnable", "My menu item", icons);#endregion
8.ModelView
IModelDoc2 pDoc;pDoc = (IModelDoc2)iSwApp.ActiveDoc;IModelViewManager swModelViewMgr;swModelViewMgr = pDoc.ModelViewManager;ModelView1Control = new UserControl1();swModelViewMgr.DisplayWindowFromHandlex64("用户控件1", ModelView1Control.Handle.ToInt64(), false);
9.任务窗格
ITaskpaneView pTaskPanView;pTaskPanView = iSwApp.CreateTaskpaneView2("", "我的窗口");TaskPanWinFormControl = new Form1();pTaskPanView.DisplayWindowFromHandlex64(TaskPanWinFormControl.Handle.ToInt64());
10.前导视图工具栏 未找到接口
11.


#region 新上下文菜单IFrame frame = (IFrame)SwApp.Frame();var imgPath1 = $@"{RegDllPath()}\icons\Pic1 (1).png";var imgPath2 = $@"{RegDllPath()}\icons\Pic1 (2).png";var imgPath3 = $@"{RegDllPath()}\icons\Pic1 (3).png";var imgPath4 = $@"{RegDllPath()}\icons\Pic1 (4).png";var imgPath5 = $@"{RegDllPath()}\icons\Pic1 (5).png";var imgPath6 = $@"{RegDllPath()}\icons\Pic1 (6).png";var resultCode = frame.AddMenuPopupIcon2((int)swDocumentTypes_e.swDocPART, (int)swSelectType_e.swSelNOTHING, "新上下文菜单", addinCookieID, "PopupCallbackFunction", "PopupEnable", "", imgPath1);// create and register the third party menu 创建并注册第三方组菜单registerID = SwApp.RegisterThirdPartyPopupMenu();// add a menu break at the top of the menu 在组菜单最上方增加一个不能点击的菜单resultCode = SwApp.AddItemToThirdPartyPopupMenu2(registerID, (int)swDocumentTypes_e.swDocPART, "我的菜单", addinCookieID, "", "", "", "", "", (int)swMenuItemType_e.swMenuItemType_Break);// add a couple of items to to the menu 增加菜单内的命令集resultCode = SwApp.AddItemToThirdPartyPopupMenu2(registerID, (int)swDocumentTypes_e.swDocPART, "命令测试1", addinCookieID, "FlyoutCallback(7000)", "FlyoutEnable", "", "Test1", imgPath2, (int)swMenuItemType_e.swMenuItemType_Default);resultCode = SwApp.AddItemToThirdPartyPopupMenu2(registerID, (int)swDocumentTypes_e.swDocPART, "命令测试2", addinCookieID, "FlyoutCallback(7000)", "FlyoutEnable", "", "Test4", imgPath3, (int)swMenuItemType_e.swMenuItemType_Default);// add a separator bar to the menu 增加分割线resultCode = SwApp.AddItemToThirdPartyPopupMenu2(registerID, (int)swDocumentTypes_e.swDocPART, "", addinCookieID, "", "", "", "", "", (int)swMenuItemType_e.swMenuItemType_Separator);//继续增加个命令resultCode = SwApp.AddItemToThirdPartyPopupMenu2(registerID, (int)swDocumentTypes_e.swDocPART, "命令测试3", addinCookieID, "FlyoutCallback(7000)", "FlyoutEnable", "", "Test5", imgPath4, (int)swMenuItemType_e.swMenuItemType_Default);// add an icon to the menu bar 给菜单条上面再加图标按钮resultCode = SwApp.AddItemToThirdPartyPopupMenu2(registerID, (int)swDocumentTypes_e.swDocPART, "", addinCookieID, "FlyoutCallback(7000)", "FlyoutEnable", "", "NoOp", imgPath5, (int)swMenuItemType_e.swMenuItemType_Default);#endregion
- PMP界面–请参考插件里的CreatePropertyManagerPage
- 对象的右键菜单

#region 右键菜单//右键菜单 (好像没看到图标的定义方式) --选中草后 右键显示var popItem1 = SwApp.AddMenuPopupItem4((int)swDocumentTypes_e.swDocPART, addinCookieID, "ProfileFeature", "右键菜单","FlyoutCallback(7000)", "FlyoutEnable", "我的右键菜单", "");SwApp.AddMenuPopupItem4((int)swDocumentTypes_e.swDocPART, addinCookieID, "ProfileFeature", "子菜单For草图@右键子菜单","FlyoutCallback(7000)", "FlyoutEnable", "子菜单@右键菜单", "");#endregion
上面是我收集的到一些关于solidworks中二次开发里常用的一些增加自己的菜单或者命令的办法,当然也可能不是太准确。希望对大家有帮助。
代码还是保持开源风格,各位家人们自取
https://gitee.com/painezeng/SolidWorksAddinStudy
相关文章:
C# SolidWorks 二次开发 -各种菜单命令增加方式
今天给大家讲一讲solidworks中各种菜单界面,如下图,大概有13处,也许还不完整哈。 1.CommandManager选项卡2.下拉选项卡3.菜单栏4.下级菜单5.浮动工具栏6.快捷方式工具栏7.FeatureManager工具栏区域8.MontionManager区域 ModelView?9.任务窗…...
分布式架构-Spring技术如何能实现分布式事务
在Spring技术栈中实现分布式事务,可通过多种成熟方案实现跨服务或跨数据库的事务一致性管理。以下是主要实现方式及技术要点: 一、基于Seata框架的AT模式 核心组件 TC (Transaction Coordinator):全局事务协调器(独立部署…...
【RocketMQRocketMQ Dashbord】Springboot整合RocketMQ
【RocketMQ&&RocketMQ Dashbord】Springboot整合RocketMQ 【一】Mac安装RocketMQ和RocketMQ Dashbord【1】安装RocketMQ(1)下载(2)修改 JVM 参数(3)启动测试(4)关闭测试&…...
vue 3 深度指南:从基础到全栈开发实践
目录 一、环境搭建与项目初始化 1. 前置依赖安装 2. 项目初始化与结构解析 二、核心概念与语法深度解析 1. MVVM 模式与响应式原理 2. 模板语法与指令进阶 3. 组件化开发 三、进阶开发与全栈集成 1. 路由管理(Vue Router) 2. 状态管理…...
《白帽子讲 Web 安全》之跨站请求伪造
引言 在数字化时代,网络已深度融入人们生活的方方面面,Web 应用如雨后春笋般蓬勃发展,为人们提供着便捷高效的服务。然而,繁荣的背后却潜藏着诸多安全隐患,跨站请求伪造(CSRF)便是其中极为隐蔽…...
K8S学习之基础五十:k8s中pod时区问题并通过kibana查看日志
k8s中pod默认时区不是中国的,挂载一个时区可以解决 vi pod.yaml apiVersion: v1 kind: Pod metadata:name: counter spec:containers:- name: countimage: 172.16.80.140/busybox/busybox:latestimagePullPolicy: IfNotPresentargs: [/bin/sh,-c,i0;while true;do …...
nginx代理前端请求
一,项目配置 我在 ip 为 192.168.31.177 的机器上使用 vue3 开发前端项目,项目中使用 axios 调用后端接口。 这是 axios 的配置: import axios from axios;const request axios.create({baseURL: http://192.168.31.177:8001,// 设置请求…...
LibVLC —— 《基于Qt的LibVLC专业开发技术》视频教程
🔔 LibVLC/VLC 相关技术、疑难杂症文章合集(掌握后可自封大侠 ⓿_⓿)(记得收藏,持续更新中…) 《基于Qt的LibVLC专业开发技术》课程视频,(CSDN课程主页、51CTO课程主页) 适合具有一些C++/Qt编程基础,想要进一步提高或涉足音视频行业的。本课程分7章节,共计35小节。…...
Android生态大变革,谷歌调整开源政策,核心开发不再公开
“开源”这个词曾经是Android的护城河,如今却成了谷歌的烫手山芋。最近谷歌宣布调整Android的开源政策,核心开发将全面转向私有分支。翻译成人话就是:以后Android的核心更新,不再公开共享了。 这操作不就是开源变节吗,…...
Android Gradle 插件问题:The option ‘android.useDeprecatedNdk‘ is deprecated.
问题与处理策略 问题描述 在 Android 项目中,报如下警告 The option android.useDeprecatedNdk is deprecated. The current default is false. It has been removed from the current version of the Android Gradle plugin. NdkCompile is no longer supported…...
【web应用安全】关于web应用安全的几个主要问题的思考
文章目录 防重放攻击1. **Token机制(一次性令牌)**2. **时间戳 超时验证**3. **Nonce(一次性随机数)**4. **请求签名(如HMAC)**5. **HTTPS 安全Cookie**6. **幂等性设计****综合防御策略建议****注意事项…...
Git 基础入门:从概念到实践的版本控制指南
一、Git 核心概念解析 1. 仓库(Repository) Git 的核心存储单元,包含项目所有文件及其完整历史记录。分为本地仓库(开发者本地副本)和远程仓库(如 GitHub、GitLab 等云端存储),支持…...
银行分布式新核心的部署架构(两地三中心)
银行的核心系统对可用性和性能要求均非常严苛,所以一般都采用两地三中心部署模式。 其中: 同城两个主数据中心各自部署一套热备,平时两个中心同时在线提供服务,进行负载均衡假如其中一个数据中心出现异常,则由另外一个…...
Spring 及 Spring Boot 条件化注解(15个)完整列表及示例
Spring 及 Spring Boot 条件化注解完整列表及示例 1. 所有条件化注解列表 Spring 和 Spring Boot 提供了以下条件化注解(共 15 个),用于在配置类或方法上实现条件化注册 Bean 或配置: 注解名称作用来源框架Conditional自定义条件…...
MantisBT在Windows10上安装部署详细步骤
MantisBT 是一款基于 Web 的开源缺陷跟踪系统,以下是在 Windows 10 上安装部署 MantisBT 的详细步骤: 1. 安装必要的环境 MantisBT 是一个基于 PHP 的 Web 应用程序,因此需要安装 Web 服务器(如 Apache)、PHP 和数据…...
9.4分漏洞!Next.js Middleware鉴权绕过漏洞安全风险通告
今日,亚信安全CERT监控到安全社区研究人员发布安全通告,Next.js 存在一个授权绕过漏洞,编号为 CVE-2025-29927。攻击者可能通过发送精心构造的 x-middleware-subrequest 请求头绕过中间件安全控制,从而在未授权的情况下访问受保护…...
处理json,将接口返回的数据转成list<T>,和几个时间处理方法的工具类
接口或者其他方式返回json格式,也可以直接处理里边只有list的json数据 //第一种json格式,包含分页信息 {"code": 200,"msg": null,"data": {"records": [{"风速": "0.0","电流"…...
OpenCV图像拼接(5)图像拼接模块的用于创建权重图函数createWeightMap()
操作系统:ubuntu22.04 OpenCV版本:OpenCV4.9 IDE:Visual Studio Code 编程语言:C11 算法描述 cv::detail::createWeightMap 是 OpenCV 库中用于图像拼接模块的一个函数,主要用于创建权重图。这个权重图在图像拼接过程中扮演着重…...
linux 运行脚本命令区别
文章目录 chmod 赋予权限运行sh script.sh适用场景 bash script.shsource 或 . 脚本 chmod 赋予权限运行 chmod x script.sh # 赋予执行权限 ./script.sh # 直接执行创建新的子进程,不会影响当前 shell 的环境变量。#!(Shebang) 指…...
【01】噩梦终结flutter配安卓android鸿蒙harmonyOS 以及next调试环境配鸿蒙和ios真机调试环境-flutter项目安卓环境配置
噩梦终结:Flutter 配安卓、鸿蒙、iOS 真机调试环境 问题背景 很多开发者在配置 Flutter 项目环境时遇到困难,尤其是在处理 Android、鸿蒙和 iOS 真机调试环境时。卓伊凡最近接手了一个项目,发现很多“专业程序员”在环境搭建上花费了大量时…...
C++11QT复习 (六)
类型转换函数和类域 **Day6-3 类型转换函数和类域****1. 类型转换函数(Type Conversion Functions)****1.1 概述****1.2 代码示例****1.3 关键优化** **2. 类域(Class Scope)****2.1 作用域 vs 可见域****2.2 代码示例****2.3 关键…...
区块链技术在投票系统中的应用:安全、透明与去中心化
区块链技术在投票系统中的应用:安全、透明与去中心化 【引言】 近年来,电子投票系统因其便捷性受到广泛关注,但随之而来的安全问题也屡见不鲜,如选票篡改、重复投票、数据泄露等。如何确保投票的公平性、透明度和安全性? 区块链技术或许是解决方案之一! 区块链的 去中…...
CTF类题目复现总结-[MRCTF2020]ezmisc 1
一、题目地址 https://buuoj.cn/challenges#[MRCTF2020]ezmisc二、复现步骤 1、下载附件,得到一张图片; 2、利用010 Editor打开图片,提示CRC值校验错误,flag.png应该是宽和高被修改了,导致flag被隐藏掉;…...
MetInfo6.0.0目录遍历漏洞原理分析
所需进行代码审计的文件路径: C:\phpStudy\WWW\MetInfo6.0.0\include\thumb.php C:\phpStudy\WWW\MetInfo6.0.0\app\system\entrance.php C:\phpStudy\WWW\MetInfo6.0.0\app\system\include\class\load.class.php C:\phpStudy\WWW\MetInfo6.0.0\app\system\include…...
linux打包前端vue,后端springboot项目
第一步先对整个项目进行通过maven进行clean在进行compile 第二步直接进行打包package和install都可以 第三部把对应的jar放到服务器上 把jar包放到服务器上某个地址下,然后cd到这个目录下,然后执行命令 nohup java -jar ruoyi-admin.jar > springbo…...
Elasticsearch:使用 AI SDK 和 Elastic 构建 AI 代理
作者:来自 Elastic Carly Richmond 你是否经常听到 AI 代理(AI agents)这个词,但不太确定它们是什么,或者如何在 TypeScript(或 JavaScript)中构建一个?跟我一起深入了解 AI 代理的概…...
SQLAlchemy 支持特殊字符
postgresql 实践 pydantic 实践(一)基础 pydantic 实践(二)数据校验 SQLAlchemy 介绍与实践 SQLAlchemy 支持特殊字符 SQLAlchemy 支持特殊字符 1. 字符集介绍分析2. MySQL 支持特殊字符2.1. 更新 MySQL 字符集为 utf8mb42.2 更新…...
Docker 快速入门指南
Docker 快速入门指南 1. Docker 常用指令 Docker 是一个轻量级的容器化平台,可以帮助开发者快速构建、测试和部署应用程序。以下是一些常用的 Docker 命令。 1.1 镜像管理 # 搜索镜像 docker search <image_name># 拉取镜像 docker pull <image_name>…...
计算机网络 - OSI 七层模型
OSI 七层模型 OSI(Open System Interconnection,开放系统互联)模型由 ISO(国际标准化组织) 制定,目的是为不同计算机网络系统之间的通信提供一个标准化的框架。它将网络通信划分为 七个层次,每…...
如何调整yarn.nodemanager.vmem-pmem-ratio参数?
调整 yarn.nodemanager.vmem-pmem-ratio 参数的步骤如下: 1. 打开 YARN 配置文件 找到 yarn-site.xml 文件,该文件通常位于 Hadoop 配置目录中,例如 /etc/hadoop/conf 或 /opt/module/hadoop-3.1.3/etc/hadoop。 2. 找到并修改 yarn.nodemana…...
