Beispiel #1
0
import FreeCAD as App
if App.GuiUp:
    import FreeCADGui as Gui
from PartOMagic.Gui.Utils import Transaction
from PartOMagic.Base import Containers


def CreatePart():
    with Transaction("Create Part"):
        Gui.doCommand("f = App.ActiveDocument.addObject('App::Part','Part')")
        Gui.doCommand("PartOMagic.Gui.Observer.activateContainer(f)")
    Gui.doCommand("Gui.Selection.clearSelection()")

from PartOMagic.Gui.AACommand import AACommand, CommandError
commands = []
class CommandPart(AACommand):
    "Command to create a Part container"
    def GetResources(self):
        import PartDesignGui        
        return {'CommandName': "PartOMagic_Part",
                'Pixmap'  : self.getIconPath("Tree_Annotation.svg"),
                'MenuText': "New Part container",
                'Accel': "",
                'ToolTip': "New Part container. Creates an empty Part container."}        
    def RunOrTest(self, b_run):
        if b_run: CreatePart()
commands.append(CommandPart())

exportedCommands = AACommand.registerCommands(commands)
Beispiel #2
0
    def RunOrTest(self, b_run):
        if b_run:
            sel = Gui.Selection.getSelectionEx()
            buf = self.buffer
            Gui.Selection.clearSelection()
            for it in buf:
                try:
                    it.Object  #throws if the object has been deleted
                except Exception:
                    continue
                subs = it.SubElementNames
                pts = it.PickedPoints
                if subs:
                    for isub in range(len(subs)):
                        Gui.Selection.addSelection(it.Object, subs[isub],
                                                   *pts[isub])
                else:
                    Gui.Selection.addSelection(it.Object)
            self.buffer = sel


commands.append(CommandSelectMem())
AACommand.registerCommands(commands)

Gui.addCommand(
    'PartOMagic_SelectGroupCommand',
    GroupCommand(list_of_commands=[cmd.command_name for cmd in commands],
                 menu_text="Select",
                 tooltip=""))

exportedCommands = lambda: ['PartOMagic_SelectGroupCommand']
Beispiel #3
0
def CreateModule(name):
    App.ActiveDocument.openTransaction("Create Module")
    Gui.addModule("PartOMagic.Features.Module")
    Gui.doCommand("f = PartOMagic.Features.Module.makeModule(name = '"+name+"')")
    Gui.doCommand("PartOMagic.Base.Containers.setActiveContainer(f)")
    Gui.doCommand("Gui.Selection.clearSelection()")
    App.ActiveDocument.commitTransaction()


# -------------------------- /common stuff --------------------------------------------------

# -------------------------- Gui command --------------------------------------------------
from PartOMagic.Gui.AACommand import AACommand, CommandError
commands = []
class CommandModule(AACommand):
    "Command to create Module feature"
    def GetResources(self):
        import PartDesignGui #needed for icon
        return {'CommandName': 'PartOMagic_Module',
                'Pixmap'  : self.getIconPath("PartDesign_Body_Create_New.svg"),
                'MenuText': "New Module container",
                'Accel': "",
                'ToolTip': "New Module container. Module is like PartDesign Body, but for Part workbench and friends."}
        
    def RunOrTest(self, b_run):
        if b_run: CreateModule(name = "Module")
commands.append(CommandModule())
# -------------------------- /Gui command --------------------------------------------------

exportedCommands = AACommand.registerCommands(commands)
    def RunOrTest(self, b_run):
        if b_run: 
            sel = Gui.Selection.getSelectionEx()
            buf = self.buffer
            Gui.Selection.clearSelection()
            for it in buf:
                try:
                    it.Object #throws if the object has been deleted
                except Exception:
                    continue
                subs = it.SubElementNames
                pts = it.PickedPoints
                if subs:
                    for isub in range(len(subs)):
                        Gui.Selection.addSelection(it.Object, subs[isub], *pts[isub])
                else:
                    Gui.Selection.addSelection(it.Object)
            self.buffer = sel
commands.append(CommandSelectMem())
AACommand.registerCommands(commands)


Gui.addCommand('PartOMagic_SelectGroupCommand',
 GroupCommand(
    list_of_commands= [cmd.command_name for cmd in commands],
    menu_text= "Select",
    tooltip= ""
 )
)

exportedCommands = lambda:['PartOMagic_SelectGroupCommand']