一个简单例子,实现鼠标点击个位置,点击开发的按钮,在此处XYZ坐标点创建一个红色的球
class MyMouseCreatePointCommand: def GetResources(self): return {'Pixmap': 'a2p_Solver', 'MenuText': '鼠标创建点', 'ToolTip': '监听鼠标创建点'} def Activated(self): #点击按钮执行的动作 """Do something here""" import Draft import Part from FreeCAD import Base # 遍历选择的对象 for o in FreeCADGui.Selection.getSelectionEx(): o.PickedPoints[0] # 创建点 Draft.makePoint(o.PickedPoints[0]) # 打印点坐标 print(o.PickedPoints[0]) # 指定半径 b=Part.makeSphere(0.1, o.PickedPoints[0]) # 显示对象 Part.show(b) # 设置颜色 FreeCADGui.ActiveDocument.ActiveObject.ShapeColor=(0.76, 0.19, 0.73) def IsActive(self): """Here you can define if the command must be active or not (greyed) if certain conditions are met or not. This function is optional.""" return True FreeCADGui.addCommand('MyMouseCreatePointCommand', MyMouseCreatePointCommand()) 程序员阿飞 2021年4月21日
程序员阿飞
2021年4月21日、、