Sketcher ConstrainCoincident: Difference between revisions

From FreeCAD Documentation
No edit summary
(Moved Python scripting advice for constraints in general to Scritping Sketcher constraints in Python, added alternatives to the coincident constraint for straight line midpoint and co-linear cases, and made small improvements)
Line 48: Line 48:
{{Emphasis|Note:}} In order to make two points coincident, FreeCAD must out of necessity move one (or both) of the original points.
{{Emphasis|Note:}} In order to make two points coincident, FreeCAD must out of necessity move one (or both) of the original points.


==Scripting== <!--T:8-->
==Scripting== <!--T:14-->

===General scripting=== <!--T:14-->
The constraint can be created from macros and from the python console by using the following command:
The constraint can be created from macros and from the python console by using the following command:
</translate>
</translate>
Line 59: Line 57:
* {{incode|Sketch}} is a sketch object
* {{incode|Sketch}} is a sketch object
* {{incode|LineFixed}} is the number of the line, that will not move by applying the constraint
* {{incode|LineFixed}} is the number of the line, that will not move by applying the constraint
* {{incode|PointOfLineFixed}} is the number of the vertex of the line {{incode|LineFixed}} that has to fulfilled the constraint
* {{incode|PointOfLineFixed}} indicates which vertex of {{incode|LineFixed}} has to fulfill the constraint
* {{incode|LineMoving}} is the number of the line, that will move by applying the constraint
* {{incode|LineMoving}} is the number of the line, that will move by applying the constraint
* {{incode|PointOfLineMoving}} is the number of the line {{incode|LineMoving}}, that has to fulfilled the constraint
* {{incode|PointOfLineMoving}} indicates which vertex of {{incode|LineMoving}} has to fulfill the constraint

<!--T:10-->
The main issue by using this function is to identify correctly the line number and the vertex number of the lines you want to process.

<!--T:11-->
The next paragraph will explain you how to identify the numbering of a line and of a vertex of a line.

===Identifying the numbering of a line=== <!--T:15-->

<!--T:12-->
I have drawn three lines as shown in the following figure.

<!--T:16-->
[[File:PartDesignConstraintPointOnPointScriptingFigure1.jpg|600px]]

<!--T:17-->
By moving the cursor of the mouse above the line you can see the line number at the bottom left of the FreeCAD windows, see next figure.

<!--T:18-->
[[File:PartDesignConstraintPointOnPointScriptingFigure2.jpg|600px]]

<!--T:19-->
Unfortunately the numbering displayed on the FreeCAD windows start from 1 whereas the numbering of the line used to script start from 0: this means that you have to retrieve one each time you want to refer to a line.

===Identifying the numbering of the vertices of a line=== <!--T:20-->

<!--T:21-->
The vertices of one line can only have the value 1 or 2. (Note that the vertices numbering does not start from 0, this is because with regards to Constraints 0= Edge hence not a vertex, 1 = starting point vertex, 2 = end point vertex, 3 = midpoint which is not a vertex) The vertices are numbered according to their order of creation. To find out the order of their creation (If you have a lot of lines, you cannot remember which vertex you have created first), you just have to move the cursor of your mouse above the two vertices of one line, see following figure.

<!--T:22-->
[[File:PartDesignConstraintPointOnPointScriptingFigure3.jpg|600px]]

<!--T:23-->
If you read e.g. 4 and 5, it means that the vertex 4 will be referenced by using the number 1 in the script command and the vertex 5 will be referenced by using the number 2 in the script command. Etc.

=== Example === <!--T:24-->

<!--T:25-->
Let us take the previous example of the three lines. The subsequent figure indicates the numbering of each line and their vertices according to the convention for scripting.

<!--T:26-->
[[Image:PartDesignConstraintPointOnPointScriptingFigure3Bis.jpg|600px]]
{{Caption|<b>blue text:</b> numbering of line, <b>black text:</b> numbering of vertices}}

<!--T:27-->
The command {{incode|Sketch.addConstraint(Sketcher.Constraint('Coincident',1,2,2,1))}} yields following result:

<!--T:29-->
[[Image:PartDesignConstraintPointOnPointScriptingFigure4.jpg|600px|center]]


The [[Scritping Sketcher constraints in Python]] page explains the values which can be used for {{incode|PointOfLineFixed}} and {{incode|PointOfLineMoving}}, and contains further examples on how to create constraints from Python scripts.
<!--T:30-->
The command {{incode|Sketch.addConstraint(Sketcher.Constraint('Coincident',0,2,2,2))}} yields following result:


The two constrained items must be starting point (1) or end point (2) vertices, or center points (3). The coincident constraint cannot be used directly with edges (0), and straight lines do not have a center point. The other combinations can be emulated using other constraints:
<!--T:38-->
* The [[File:Sketcher_ConstrainSymmetric.svg|32px]][[Sketcher ConstrainSymmetric|Symmetric]] constraint can be used to place an extremity on the midpoint of a straight line. This emulates 3 (center) for straight lines.
[[Image:PartDesignConstraintPointOnPointScriptingFigure5.jpg|600px|center]]
* A midpoint-to-midpoint placement can be achieved by creating a new [[File:Sketcher_CreatePoint.svg|32px]][[Sketcher CreatePoint|Point]] and using two [[File:Sketcher_ConstrainSymmetric.svg|32px]][[Sketcher ConstrainSymmetric|Symmetric]] constraints so that it lays on the midpoint of both edges. This emulates 3 (center) for straight lines.
* Instead of using the values 1 or 2 (vertex) and 0 (edge), a vertex can be constrained to lie along on an edge using a [[File:Sketcher_ConstrainPointOnObject.svg|32px]][[Sketcher ConstrainPointOnObject|PointOnObject]] constraint. Note that with this constraint, the point can lie anywhere on the full extension of a segment or curve (i.e. before the start point or outside of the end point).
* Instead of using the values 0 (edge) and 0 (edge), a co-linear placement can be obtained by combining a [[File:Sketcher_ConstrainPointOnObject.svg|32px]][[Sketcher ConstrainPointOnObject|PointOnObject]] constraint and a [[File:Sketcher_ConstrainParallel.svg|32px]][[Sketcher ConstrainParallel|Parallel]] constraint
* Instead of using the values 0 (edge) and 0 (edge), two edges can be made identical by using two [[File:Sketcher_ConstrainCoincident.svg|32px]][[Sketcher ConstrainCoincident|Coincident]] constraint, one for each pair of extremities.
* Instead of using the values 0 (edge) and 0 (edge), two [[File:Sketcher_CreateCircle.svg|32px]][[Sketcher CompCreateCircle|Circle]] can be made identical by creating a new [[File:Sketcher_CreateLine.svg|32px]][[Sketcher CreateLine|Line]] and using two [[File:Sketcher_ConstrainCoincident.svg|32px]][[Sketcher ConstrainCoincident|Coincident]] constraint to place both centers on one extremity of the line, and two [[File:Sketcher_ConstrainPointOnObject.svg|32px]][[Sketcher ConstrainPointOnObject|PointOnObject]] constraints to place the other extremity on the circumference of both circles. To get rid of the extra degree of freedom, a horizontal or vertical constraint can be used to lock the line in place.


<!--T:33-->
<!--T:33-->

Revision as of 02:10, 18 January 2021

Sketcher ConstrainCoincident

Menu location
Sketch → Sketcher constraints → Constrain coincident
Workbenches
Sketcher
Default shortcut
C
Introduced in version
-
See also
Sketcher Constrain Lock, Sketcher Constrain Point onto Object

Description

Create a coincident constraint on the selected item

This constraint tool takes two points as its argument and serves to make the two points coincident. (Meaning to make them as-one-point).

In practical terms this constraint tool is useful when there is a break in a profile for example - where two lines end near each other and need to be joined - a coincident constraint on their end-points will close the gap.

Usage

As stated above, this tool takes two arguments - both are points.

  1. First, it is necessary to highlight two distinct points. (Note: this will not work if, for example, you attempt to select the start and end point of the same line).
  2. Highlighting of a drawing item is achieved by moving the mouse over the item and clicking the left-mouse-button.
  3. A highlighted item will change its color to green. (This color can be customized in Editing → Preference → Display → Colors → Selection)
  4. Subsequent items can be highlighted by repeating the above procedure(s). Note: it's unnecessary to hold-down any special key like Ctrl to achieve multiple item selection in a drawing.
  5. Once you have two points highlighted, you can invoke the command using several methods:
    • Pressing on the Coinstrain coincident constraint button in the toolbar.
    • Using the C keyboard shortcut.
    • Using the Sketch → Sketcher constraints → Constrain coincident entry in the top menu.

Result: the command will cause the two points to become coincident and be replaced by a single point.

Note: In order to make two points coincident, FreeCAD must out of necessity move one (or both) of the original points.

Scripting

The constraint can be created from macros and from the python console by using the following command:

Sketch.addConstraint(Sketcher.Constraint('Coincident',LineFixed,PointOfLineFixed,LineMoving,PointOfLineMoving))

where :

  • Sketch is a sketch object
  • LineFixed is the number of the line, that will not move by applying the constraint
  • PointOfLineFixed indicates which vertex of LineFixed has to fulfill the constraint
  • LineMoving is the number of the line, that will move by applying the constraint
  • PointOfLineMoving indicates which vertex of LineMoving has to fulfill the constraint

The Scritping Sketcher constraints in Python page explains the values which can be used for PointOfLineFixed and PointOfLineMoving, and contains further examples on how to create constraints from Python scripts.

The two constrained items must be starting point (1) or end point (2) vertices, or center points (3). The coincident constraint cannot be used directly with edges (0), and straight lines do not have a center point. The other combinations can be emulated using other constraints:

  • The Symmetric constraint can be used to place an extremity on the midpoint of a straight line. This emulates 3 (center) for straight lines.
  • A midpoint-to-midpoint placement can be achieved by creating a new Point and using two Symmetric constraints so that it lays on the midpoint of both edges. This emulates 3 (center) for straight lines.
  • Instead of using the values 1 or 2 (vertex) and 0 (edge), a vertex can be constrained to lie along on an edge using a PointOnObject constraint. Note that with this constraint, the point can lie anywhere on the full extension of a segment or curve (i.e. before the start point or outside of the end point).
  • Instead of using the values 0 (edge) and 0 (edge), a co-linear placement can be obtained by combining a PointOnObject constraint and a Parallel constraint
  • Instead of using the values 0 (edge) and 0 (edge), two edges can be made identical by using two Coincident constraint, one for each pair of extremities.
  • Instead of using the values 0 (edge) and 0 (edge), two Circle can be made identical by creating a new Line and using two Coincident constraint to place both centers on one extremity of the line, and two PointOnObject constraints to place the other extremity on the circumference of both circles. To get rid of the extra degree of freedom, a horizontal or vertical constraint can be used to lock the line in place.