@@ -88,26 +88,31 @@ void StdCmdRandomColor::activated(int iMsg)
8888
8989 // get the complete selection
9090 std::vector<SelectionSingleton::SelObj> sel = Selection ().getCompleteSelection ();
91+
92+ Command::openCommand (QT_TRANSLATE_NOOP (" Command" , " Set Random Color" ));
9193 for (const auto & it : sel) {
9294 auto fMax = (float )RAND_MAX;
9395 auto fRed = (float )rand ()/fMax ;
9496 auto fGrn = (float )rand ()/fMax ;
9597 auto fBlu = (float )rand ()/fMax ;
98+ auto objColor = App::Color (fRed , fGrn , fBlu );
9699
97100 ViewProvider* view = Application::Instance->getDocument (it.pDoc )->getViewProvider (it.pObject );
98101 auto vpLink = dynamic_cast <ViewProviderLink*>(view);
99102 if (vpLink) {
100103 if (!vpLink->OverrideMaterial .getValue ())
101- cmdGuiObjectArgs (it. pObject , " OverrideMaterial = True " );
102- cmdGuiObjectArgs (it. pObject , " ShapeMaterial.DiffuseColor=(%.2f,%.2f,%.2f) " , fRed , fGrn , fBlu );
104+ vpLink-> OverrideMaterial . setValue ( true );
105+ vpLink-> ShapeMaterial .setDiffuseColor (objColor );
103106 continue ;
104107 }
105108 auto color = dynamic_cast <App::PropertyColor*>(view->getPropertyByName (" ShapeColor" ));
106109 if (color) {
107110 // get the view provider of the selected object and set the shape color
108- cmdGuiObjectArgs (it. pObject , " ShapeColor=(%.2f,%.2f,%.2f) " , fRed , fGrn , fBlu );
111+ color-> setValue (objColor );
109112 }
110113 }
114+
115+ Command::commitCommand ();
111116}
112117
113118bool StdCmdRandomColor::isActive ()
0 commit comments