From 3b9bfdf9f81e8baeaace4214fb2f7519b78bbeb2 Mon Sep 17 00:00:00 2001 From: Renaud NEDELEC Date: Wed, 4 Nov 2015 11:26:57 +0100 Subject: [PATCH] [PythonAPI / sketcher] added rigid constraint and the corresponding test --- src/PythonAPI/Test/TestSketcherSetRigid.py | 15 +++++++++++++++ src/PythonAPI/model/sketcher/sketch.py | 8 +++++++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/PythonAPI/Test/TestSketcherSetRigid.py diff --git a/src/PythonAPI/Test/TestSketcherSetRigid.py b/src/PythonAPI/Test/TestSketcherSetRigid.py new file mode 100644 index 000000000..4e3e1b666 --- /dev/null +++ b/src/PythonAPI/Test/TestSketcherSetRigid.py @@ -0,0 +1,15 @@ +import unittest +import model +from TestSketcher import SketcherTestCase + +class SketcherSetRigid(SketcherTestCase): + def runTest(self): + circle = self.sketch.addCircle(0, 10, 20) + self.sketch.setRigid(circle.result()) + model.do() + with self.assertRaises(Exception): + circle.setCenter(0, 0) + model.do() + +if __name__ == "__main__": + unittest.main(verbosity=2) \ No newline at end of file diff --git a/src/PythonAPI/model/sketcher/sketch.py b/src/PythonAPI/model/sketcher/sketch.py index b787f5e9f..98bf39b84 100644 --- a/src/PythonAPI/model/sketcher/sketch.py +++ b/src/PythonAPI/model/sketcher/sketch.py @@ -249,7 +249,13 @@ class Sketch(Interface): constraint.data().refattr("ConstraintEntityA").setObject(line_1) constraint.data().reflist("ConstraintEntityB").clear constraint.data().reflist("ConstraintEntityB").append(line_1) - + self.execute() + return constraint + + def setRigid(self, object_): + """Set a rigid constraint on a given object.""" + constraint = self._feature.addFeature("SketchConstraintRigid") + constraint.data().refattr("ConstraintEntityA").setObject(object_) self.execute() return constraint -- 2.39.2