My idea is to have a context menu depend on the type of the object that is selected. So for example if a line is selected, I would like to have a context menu with commands like: edit, move, rotate, stretch and maybe a couple of more. And if I select a wall or something else I would have a different context menu with some other commands. Something similar to the context menu that is used in sketcher, but with only five or six commands avalible. So it would be something like "If line is selected when you right click somewhere in the viewport you get a coressponding context menu.".
My end goal would be to have something like this in FreeCAD.
I looked into the code that vocx mentioned
Code: Select all
def ContextMenu(self, recipient):
if recipient == "View":
if FreeCAD.activeDraftCommand is None:
if FreeCADGui.Selection.getSelection():
self.appendContextMenu("Draft", self.cmdList + self.modList)
self.appendContextMenu("Utilities", self.treecmdList)
else:
self.appendContextMenu("Draft", self.cmdList)
else:
if FreeCAD.activeDraftCommand.featureName == "Line":
self.appendContextMenu("", self.lineList)
else:
if FreeCADGui.Selection.getSelection():
self.appendContextMenu("Utilities", self.treecmdList)
Code: Select all
self.linemodList = ["Draft_Edit", "Draft_Move", "Draft_Rotate", "Draft_Upgrade",
"Draft_Downgrade", "Draft_Stretch"]
Code: Select all
def ContextMenu(self, recipient):
if recipient == "View":
if FreeCAD.activeDraftCommand is None:
if FreeCADGui.Selection.getSelection():
self.appendContextMenu("Draft", self.cmdList + self.modList)
self.appendContextMenu("Utilities", self.treecmdList)
self.appendContextMenu("Modify", self.linemodList)
else:
self.appendContextMenu("Draft", self.cmdList)
else:
if FreeCAD.activeDraftCommand.featureName == "Line":
self.appendContextMenu("", self.lineList)
else:
if FreeCADGui.Selection.getSelection():
self.appendContextMenu("Utilities", self.treecmdList)
Code: Select all
def ContextMenu(self, recipient):
if recipient == "View":
if FreeCAD.activeDraftCommand is None:
if FreeCADGui.Selection.getSelection():
self.appendContextMenu("Draft", self.cmdList + self.modList)
self.appendContextMenu("Utilities", self.treecmdList)
if "selection.type" == "wire object or similar":
self.appendContextMenu("Modify", self.linemodList)
else:
self.appendContextMenu("Draft", self.cmdList)
else:
if FreeCAD.activeDraftCommand.featureName == "Line":
self.appendContextMenu("", self.lineList)
else:
if FreeCADGui.Selection.getSelection():
self.appendContextMenu("Utilities", self.treecmdList)
I hope can help me with this.