Difference between revisions of "Draft Draft2Sketch/hr"

From FreeCAD Documentation
Jump to navigation Jump to search
(Updating to match new version of source page)
(Updating to match new version of source page)
Line 1: Line 1:
{{Page_in_progress}}
 
 
<languages/>
 
<languages/>
  
Line 15: Line 14:
 
|MenuLocation=Modification → Draft to Sketch
 
|MenuLocation=Modification → Draft to Sketch
 
|Workbenches=[[Draft_Module|Draft]], [[Arch_Module|Arch]]
 
|Workbenches=[[Draft_Module|Draft]], [[Arch_Module|Arch]]
|SeeAlso=[[Sketcher_Workbench|Sketcher]], [[PartDesign_Workbench|PartDesign]]
 
 
}}
 
}}
  
 
==Description==  
 
==Description==  
  
The {{Button|[[Image:Draft Draft2Sketch.svg|16px]] [[Draft_Draft2Sketch|Draft Draft2Sketch]]}} tool converts {{Button|[[Image:Workbench_Draft.svg|16px]] [[Draft_Module|Draft objects]]}} to {{Button|[[Image:Workbench_Sketcher.svg|16px]] [[Sketcher_Module|Sketcher Sketches]]}}, and vice-versa.
+
The [[Image:Draft_Draft2Sketch.svg|24px]] '''Draft Draft2Sketch''' command converts Draft objects to [[Sketcher_NewSketch|Sketcher Sketches]] and vice versa.
  
[[Image:Draft Draft2Sketch example.jpg||480px]]
+
[[Image:Draft_Draft2Sketch_example.png]]
{{Caption|Converting Draft shapes into Sketcher shapes with constraints}}
+
{{Caption|Converting Draft objects to Sketcher Sketches}}
  
 
==Usage==  
 
==Usage==  
  
# Select a Draft object or a Sketch.
+
# Optionally select one or more Draft objects or [[Sketcher_NewSketch|Sketcher Sketches]].
# Press the {{Button|[[Image:Draft Draft2Sketch.svg|16px]] [[Draft_Draft2Sketch|Draft Draft2Sketch]]}} button.
+
# There are several ways to invoke the command:
 +
#* Press the {{Button|[[Image:Draft_Draft2Sketch.svg|16px]] [[Draft_Draft2Sketch|Draft Draft2Sketch]]}} button.
 +
#* Select the {{MenuCommand|Modification → [[Image:Draft_Draft2Sketch.svg|16px]] Draft to Sketch}} option from the menu.
 +
# If you have not yet selected an object: select an object in the [[3D_view|3D view]].
 +
# A new object is created.
  
Notes:
+
==Notes==
* If you convert a [[Image:Draft_Wire.svg|16px]] [[Draft_Wire|Draft Wire]], the resulting sketch will use point constraints for the nodes.
 
* If you convert a [[Image:Draft_Rectangle.svg|16px]] [[Draft_Rectangle|Draft Rectangle]], the resulting sketch will use point constraints for the corners, and horizontal and vertical constraints for the edges.
 
* If you convert a [[Image:Draft_BezCurve.svg|16px]] [[Draft_BezCurve|Draft BezCurve]], the resulting sketch will be approximated by a [[Image:Sketcher_CreateBSpline.svg|16px]] [[Sketcher_CreateBSpline|Sketcher BSpline]], as the [[Sketcher_Workbench|Sketcher Workbench]] doesn't support Bezier curves currently.
 
* Non-Draft objects that are totally planar will also get converted to sketches.
 
  
===Limitations===
+
* Non-Draft objects that are totally planar can also be converted.
 +
* The command can only handle objects made up out of straight lines, circular arcs, elliptical arcs, B-Splines and Bézier curves.
 +
* [[Draft_BezCurve|Draft BezCurves]] will be approximated by [[Sketcher_CreateBSpline|Sketcher BSplines]].
 +
* The external [[KicadStepUp_Workbench|KicadStepUp Workbench]] contains a command to convert a [[Draft_BSpline|Draft BSpline]] into a series of [[Sketcher_CreateArc|Sketcher Arcs]]. For more information see the forum topic [https://forum.freecadweb.org/viewtopic.php?f=9&t=25082 BSplines to Shape2DView and Sketcher].
  
The conversion of an object that cannot be represented with a combination of straight lines, circular arcs, and B-Splines will usually fail, that is, the item will not appear in the sketch.
+
==Scripting==
  
In the past, a [[Draft_BSpline|Draft BSpline]] couldn't be converted directly to a sketch. A tool to perform this conversion was developed for the [[KicadStepUp_Workbench|KicadStepUp Workbench]], which would take a [[Draft_BSpline|Draft BSpline]] and convert it into a series of [[Sketcher_CreateArc|Sketcher Arcs]]. See the forum thread [https://forum.freecadweb.org/viewtopic.php?f=9&t=25082 BSplines to Shape2DView and Sketcher] for more information.
+
See also: [https://freecad.github.io/SourceDoc/ Autogenerated API documentation] and [[FreeCAD Scripting Basics|FreeCAD Scripting Basics]].
  
As of {{VersionPlus|0.17}} the conversion from [[Draft_BSpline|Draft BSpline]] to [[Sketcher_CreateBSpline|Sketcher BSpline]] is possible. However, converting a spline to a series of arcs may still be useful for exporting geometry to applications that don't support B-Splines, like KiCad.
+
To convert objects to a sketch use the {{incode|make_sketch}} method ({{Version|0.19}}) of the Draft module. This method replaces the deprecated {{incode|makeSketch}} method.
  
==Opcije==
+
{{Code|code=
 +
sketch = make_sketch(objects_list, autoconstraints=False, addTo=None, delete=False, name="Sketch", radiusPrecision=-1, tol=1e-3)
 +
}}
  
There are no options for this tool. Either it works with the selected object or not.
+
* {{incode|objects_list}} contains the objects to be converted. It is either a single object or a list of objects. {{incode|Draft}} objects, {{incode|Part::Feature}} objects and {{incode|Part.Shape}} objects are supported.
 +
* If {{incode|autoconstraints}} is {{incode|True}} coincident constraints are added to nodes belonging to the same source object.
 +
* {{incode|addTo}} is the existing sketch object the geometry is added to. If not supplied a new sketch is created.
 +
* If {{incode|delete}} is {{incode|True}} the source objects are deleted.
 +
* {{incode|name}} is the name for the new sketch.
 +
* {{incode|radiusPrecision}} indicates how radius constraints should be handled:
 +
** Use {{incode|-1}} to disable radius constraints.
 +
** Use {{incode|0}} to add individual radius constraints.
 +
** Use a positive number to round radii according to this precision, and to add equal constraints between curves with equal radii.
 +
* {{incode|tol}} is the tolerance used to check if shapes are planar and co-planar. Use {{incode|-1}} for a strict analysis.
 +
* {{incode|sketch}} is returned with the sketch object.
  
==Scripting==
+
To convert a sketch to Draft objects use the {{incode|draftify}} method of the Draft module.
  
See also: [https://www.freecadweb.org/api Autogenerated API documentation] and [[FreeCAD Scripting Basics|FreeCAD Scripting Basics]].
+
{{Code|code=
 +
draftify(objectslist, makeblock=False, delete=True)
 +
}}
  
Internally the Draft2Sketch tool uses two methods to convert back and forth from Draft to Sketch.
+
* {{incode|objectslist}} contains the objects to be converted. It is either a single object or a list of objects.
 +
* If {{incode|makeblock}} is {{incode|True}} the converted objects are grouped in a {{incode|Part::Part2DObject}}.
 +
* If {{incode|delete}} is {{incode|True}} the source objects are deleted.
  
Convert objects to Sketch:
+
Example:
  
 
{{Code|code=
 
{{Code|code=
Draft.makeSketch(objectslist, autoconstraints=False, addTo=None, delete=False, name="Sketch", radiusPrecision=-1)
+
import FreeCAD as App
}}
+
import Draft
 +
 
 +
doc = App.newDocument()
 +
 
 +
rectangle = Draft.make_rectangle(2000, 1000)
 +
circle = Draft.make_circle(500)
 +
doc.recompute()
  
Convert objects to Draft:
+
sketch_from_draft = Draft.make_sketch([rectangle, circle], autoconstraints=True, delete=False, radiusPrecision=0)
 +
doc.recompute()
  
{{Code|code=
+
draft_from_sketch = Draft.draftify(sketch_from_draft, delete=False)
Draft.draftify(objectslist, makeblock=False, delete=True)
+
doc.recompute()
 
}}
 
}}
  

Revision as of 09:30, 16 June 2021

Other languages:
Deutsch • ‎English • ‎Türkçe • ‎español • ‎français • ‎hrvatski • ‎italiano • ‎polski • ‎português do Brasil • ‎română • ‎svenska • ‎čeština • ‎русский
Arrow-left.svg Previous: Draft WireToBSpline.svg WireToBSpline
Next: Slope Draft Slope.svg Arrow-right.svg

Draft Draft2Sketch.svg Draft Draft2Sketch

Menu location
Modification → Draft to Sketch
Workbenches
Draft, Arch
Default shortcut
None
Introduced in version
-
See also
None

Description

The Draft Draft2Sketch.svg Draft Draft2Sketch command converts Draft objects to Sketcher Sketches and vice versa.

Draft Draft2Sketch example.png

Converting Draft objects to Sketcher Sketches

Usage

  1. Optionally select one or more Draft objects or Sketcher Sketches.
  2. There are several ways to invoke the command:
    • Press the Draft Draft2Sketch.svg Draft Draft2Sketch button.
    • Select the Modification → Draft Draft2Sketch.svg Draft to Sketch option from the menu.
  3. If you have not yet selected an object: select an object in the 3D view.
  4. A new object is created.

Notes

Scripting

See also: Autogenerated API documentation and FreeCAD Scripting Basics.

To convert objects to a sketch use the make_sketch method (introduced in version 0.19) of the Draft module. This method replaces the deprecated makeSketch method.

sketch = make_sketch(objects_list, autoconstraints=False, addTo=None, delete=False, name="Sketch", radiusPrecision=-1, tol=1e-3)
  • objects_list contains the objects to be converted. It is either a single object or a list of objects. Draft objects, Part::Feature objects and Part.Shape objects are supported.
  • If autoconstraints is True coincident constraints are added to nodes belonging to the same source object.
  • addTo is the existing sketch object the geometry is added to. If not supplied a new sketch is created.
  • If delete is True the source objects are deleted.
  • name is the name for the new sketch.
  • radiusPrecision indicates how radius constraints should be handled:
    • Use -1 to disable radius constraints.
    • Use 0 to add individual radius constraints.
    • Use a positive number to round radii according to this precision, and to add equal constraints between curves with equal radii.
  • tol is the tolerance used to check if shapes are planar and co-planar. Use -1 for a strict analysis.
  • sketch is returned with the sketch object.

To convert a sketch to Draft objects use the draftify method of the Draft module.

draftify(objectslist, makeblock=False, delete=True)
  • objectslist contains the objects to be converted. It is either a single object or a list of objects.
  • If makeblock is True the converted objects are grouped in a Part::Part2DObject.
  • If delete is True the source objects are deleted.

Example:

import FreeCAD as App
import Draft

doc = App.newDocument()

rectangle = Draft.make_rectangle(2000, 1000)
circle = Draft.make_circle(500)
doc.recompute()

sketch_from_draft = Draft.make_sketch([rectangle, circle], autoconstraints=True, delete=False, radiusPrecision=0)
doc.recompute()

draft_from_sketch = Draft.draftify(sketch_from_draft, delete=False)
doc.recompute()


Arrow-left.svg Previous: Draft WireToBSpline.svg WireToBSpline
Next: Slope Draft Slope.svg Arrow-right.svg