From b6abbeb9cc50707ce1ea74136b351777d016f394 Mon Sep 17 00:00:00 2001 From: Kurt Kremitzki Date: Thu, 3 Aug 2017 19:03:56 -0500 Subject: [PATCH] PDN: Automatically activate body if document has only 1 --- src/Mod/PartDesign/Gui/Utils.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Mod/PartDesign/Gui/Utils.cpp b/src/Mod/PartDesign/Gui/Utils.cpp index 0b0ed74581..2fff0a4925 100644 --- a/src/Mod/PartDesign/Gui/Utils.cpp +++ b/src/Mod/PartDesign/Gui/Utils.cpp @@ -63,15 +63,23 @@ PartDesign::Body *getBody(bool messageIfNot) { PartDesign::Body * activeBody = nullptr; Gui::MDIView *activeView = Gui::Application::Instance->activeView(); + bool singleBodyDocument = activeView->getAppDocument()-> + countObjectsOfType(PartDesign::Body::getClassTypeId()) == 1; if (activeView) { if ( PartDesignGui::assureModernWorkflow ( activeView->getAppDocument() ) ) { activeBody = activeView->getActiveObject(PDBODYKEY); + if (!activeBody && singleBodyDocument) { + Gui::Command::doCommand( Gui::Command::Gui, + "Gui.activeView().setActiveObject('pdbody',App.ActiveDocument.findObjects('PartDesign::Body')[0])"); + activeBody = activeView->getActiveObject(PDBODYKEY); + return activeBody; + } if (!activeBody && messageIfNot) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No active Body"), QObject::tr("In order to use PartDesign you need an active Body object in the document. " - "Please make one active (double click) or create one. If you have a legacy document " + "Please make one active (double click) or create one.\n\nIf you have a legacy document " "with PartDesign objects without Body, use the transfer function in " "PartDesign to put them into a Body." ));