Delete a constrain from cpp?

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
paddle
Veteran
Posts: 1392
Joined: Mon Feb 03, 2020 4:47 pm

Delete a constrain from cpp?

Post by paddle »

I'm making a tool creating constrains. But if the user exit the tool without validating then I want to delete the constraint. How to do that?

I'm trying :

Code: Select all

            Sketcher::SketchObject* Obj = sketchgui->getSketchObject();
            Obj->Constraints.setSize(Obj->Constraints.getSize() - numberOfConstraintsCreated);
            Obj->solve(true);
            sketchgui->draw(false, false); // Redraw
Which works but creates an illegal storage access (_onselectionchanged in selection.cpp).
I tried to

Code: Select all

Gui::Selection().clearSelection();
first but doesn't seem effective.

Is it wrong to use the class destructor? Should my code be somewhere else? In deactivate function?

Edit : Using deactivated function of the DrawSketchHandler instead of the class destructor fixed the issue.
Post Reply