dz网站建设,国家开发银行贷款学生在线系统,友情链接出售网,wordpress手机电脑FreeCAD作为一款基于OpenCasCAD内核的开源CAD软件#xff0c;可以在GitHub上下载源代码。阅读源代码#xff0c;有助于我们学习CAD软件架构#xff0c;了解底层几何算法。由博主Caesar卢尚宇自学整理(纯粹出于对三维CAD软件开发的热爱)内容出自FreeCAD官方社区https://wiki.…FreeCAD作为一款基于OpenCasCAD内核的开源CAD软件可以在GitHub上下载源代码。阅读源代码有助于我们学习CAD软件架构了解底层几何算法。由博主Caesar卢尚宇自学整理(纯粹出于对三维CAD软件开发的热爱)内容出自FreeCAD官方社区https://wiki.freecadweb.org/Workbench_creation可以把FreeCAD理解成一个QT界面的容器每次FreeCAD启动时都去Mod文件夹里读取所有工作台。我们在Mod里添加自己的工作台文件夹里面放三个文件。Init.py这个是FreeCAD启动的时候执行的不与界面交互的后台执行。(一般做界面工具开发这个文件为空就行了)InitGui.py这个是FreeCAD启动的时候执行的与界面交互的代码。LSY.py这个是我们存放命令功能的文件。InitGui.pyclassMyWorkbench ( Workbench ):MenuText My Workbench1ToolTip A description of my workbenchIcon paste here the contents of a 16x16 xpm icondefInitialize(self):This function is executed when FreeCAD startsimport LSY #import here all the needed files that create your FreeCAD commandsself.list [‘MySecondCommand‘, ‘MySecondCommand1‘] #A list of command names created in the line aboveself.appendToolbar(‘My Commands‘,self.list) #creates a new toolbar with your commandsself.appendMenu(‘My New Menu‘,self.list) #creates a new menuself.appendMenu([An existing Menu, My submenu], self.list) #appends a submenu to an existing menudefActivated(self):This function is executed when the workbench is activatedreturndefDeactivated(self):This function is executed when the workbench is deactivatedreturndefContextMenu(self, recipient):This is executed whenever the user right-clicks on screen#recipient will be either view or treeself.appendContextMenu(My commands, self.list) #add commands to the context menudefGetClassName(self):#this function is mandatory if this is a full python workbenchreturn Gui::PythonWorkbenchGui.addWorkbench(MyWorkbench())Caesar卢尚宇2020年3月24日LSY.pyimportFreeCADimportFreeCADGuifrom PySide importQtGui, QtCoreclassMySecondCommand:defGetResources(self):return {‘Pixmap‘: ‘freecad‘, ‘MenuText‘: ‘show Message1‘, ‘ToolTip‘: ‘Print show Message1‘}def Activated(self): #点击按钮执行的动作Do something herereply QtGui.QMessageBox.information(None,,Houston, we have a problem)returndefIsActive(self):Here you can define if the command must be active or not (greyed) if certain conditionsare met or not. This function is optional.returnTrueFreeCADGui.addCommand(‘MySecondCommand‘, MySecondCommand())classMySecondCommand1:defGetResources(self):return {‘Pixmap‘: ‘freecad‘, ‘MenuText‘: ‘show Message2‘, ‘ToolTip‘: ‘Print show Message2‘}def Activated(self): #点击按钮执行的动作Do something herereply QtGui.QMessageBox.question(None, , This is your chance to answer, what do you think?,QtGui.QMessageBox.Yes |QtGui.QMessageBox.No, QtGui.QMessageBox.No)if reply QtGui.QMessageBox.Yes:#this is where the code relevant to a ‘Yes‘ answer goespassif reply QtGui.QMessageBox.No:#this is where the code relevant to a ‘No‘ answer goespassreturndefIsActive(self):Here you can define if the command must be active or not (greyed) if certain conditionsare met or not. This function is optional.returnTrueFreeCADGui.addCommand(‘MySecondCommand1‘, MySecondCommand1())Caesar卢尚宇2020年3月24日这两个文件里的代码也是从社区里找到的。但是原封不动的复制下来去做会出错。一定要修改它的代码。我试了两个小时在找到一些有问题的地方。(使用的话直接复制我上面的代码就行了我修改过了)第一处第二处第三处演示附加参考资料https://www.jianshu.com/p/8a0a2b0e4aeaCaesar卢尚宇2020年3月24日原文https://www.cnblogs.com/nxopen2018/p/12563018.html