diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index 5b8f7777c..885d96a0a 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -103,28 +103,30 @@ void CmdPartDesignBody::activated(int iMsg) openCommand("Add a body feature"); std::string FeatName = getUniqueObjectName("Body"); - // first check if Part is already created: - App::Part *actPart = getDocument()->Tip.getValue(); - std::string PartName; - if(!actPart){ - // if not, creating a part and set it up by calling the appropiated function in Workbench - PartName = getUniqueObjectName("Part"); - doCommand(Doc,"App.activeDocument().Tip = App.activeDocument().addObject('App::Part','%s')",PartName.c_str()); - doCommand(Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr(PartName.c_str()).toStdString().c_str()); - PartDesignGui::Workbench::setUpPart(dynamic_cast(getDocument()->getObject(PartName.c_str()))); - }else - PartName = actPart->getNameInDocument(); - - // add the Body feature itself, and make it active - doCommand(Doc,"App.activeDocument().addObject('PartDesign::Body','%s')",FeatName.c_str()); - //doCommand(Doc,"App.activeDocument().%s.Model = []",FeatName.c_str()); - //doCommand(Doc,"App.activeDocument().%s.Tip = None",FeatName.c_str()); - addModule(Gui,"PartDesignGui"); // import the Gui module only once a session - doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", PDBODYKEY, FeatName.c_str()); - // Make the "Create sketch" prompt appear in the task panel - doCommand(Gui,"Gui.Selection.clearSelection()"); - doCommand(Gui,"Gui.Selection.addSelection(App.ActiveDocument.%s)", FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.addObject(App.ActiveDocument.%s)",PartName.c_str(),FeatName.c_str()); + // first check if Part is already created: + App::Part *actPart = getDocument()->Tip.getValue(); + std::string PartName; + + if(!actPart){ + // if not, creating a part and set it up by calling the appropiated function in Workbench + //if we create a new part we automaticly get a new body, there is no need to create a second one + PartName = getUniqueObjectName("Part"); + doCommand(Doc,"App.activeDocument().Tip = App.activeDocument().addObject('App::Part','%s')",PartName.c_str()); + doCommand(Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr(PartName.c_str()).toStdString().c_str()); + PartDesignGui::Workbench::setUpPart(dynamic_cast(getDocument()->getObject(PartName.c_str()))); + } else { + PartName = actPart->getNameInDocument(); + // add the Body feature itself, and make it active + doCommand(Doc,"App.activeDocument().addObject('PartDesign::Body','%s')",FeatName.c_str()); + //doCommand(Doc,"App.activeDocument().%s.Model = []",FeatName.c_str()); + //doCommand(Doc,"App.activeDocument().%s.Tip = None",FeatName.c_str()); + addModule(Gui,"PartDesignGui"); // import the Gui module only once a session + doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", PDBODYKEY, FeatName.c_str()); + // Make the "Create sketch" prompt appear in the task panel + doCommand(Gui,"Gui.Selection.clearSelection()"); + doCommand(Gui,"Gui.Selection.addSelection(App.ActiveDocument.%s)", FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.addObject(App.ActiveDocument.%s)",PartName.c_str(),FeatName.c_str()); + } updateActive(); }