Draft SVG: Difference between revisions

From FreeCAD Documentation
mNo edit summary
(Marked this version for translation)
 
(40 intermediate revisions by 5 users not shown)
Line 1: Line 1:
<languages/>
<languages/>
<translate>
<translate>
<!--T:16-->
{{docnav|[[Draft_DXF|Autodesk .DXF .DWG]]|[[Draft_OCA|Open Cad format .OCA]]|[[Draft_Module|Draft Module]]|IconC=Workbench_Draft.svg}}


<!--T:1-->
<!--T:16-->
{{Docnav
{{GuiCommand
|[[Draft_DXF|Autodesk .DXF .DWG]]
|Name=Draft SVG
|[[Draft_OCA|Open Cad format .OCA]]
|MenuLocation=File → Export → Flattened SVG (*.svg)
|Workbenches=[[Draft Workbench|Draft]]
|[[Draft_Module|Draft]]
|IconL=
|Shortcut={{KEY|Ctrl}} + {{KEY|E}}
|IconR=
|SeeAlso=[[Draft DXF]], [[FreeCAD and DXF Import]], [[Import Export]]
|IconC=Workbench_Draft.svg
|Empty=1
}}
}}


</translate>
== Description == <!--T:11-->
{{TOCright}}
This function imports [[SVG]] files as workable [[Draft Workbench]] objects, as opposed to the [[Drawing Workbench]] [[Drawing Open SVG|Open SVG]] function which imports SVG files as sheet drawings.
<translate>

==Description== <!--T:11-->

<!--T:20-->
Draft SVG is a software module used by the [[File:Std_Open.svg|24px]] [[Std_Open|Std Open]], [[File:Std_Import.svg|24px]] [[Std_Import|Std Import]] and [[File:Std_Export.svg|24px]] [[Std_Export|Std Export]] commands to handle the [[SVG]] file format.


</translate>
</translate>
Line 23: Line 27:
{{Caption|Inkscape drawing exported to SVG, which is subsequently opened in FreeCAD}}
{{Caption|Inkscape drawing exported to SVG, which is subsequently opened in FreeCAD}}


== Opening == <!--T:2-->
==Importing== <!--T:2-->
The following SVG objects get imported at the moment:
* '''PATH''' objects
* '''LINE''' objects
* '''RECT''' objects
* '''CIRCLE''' objects
* '''ELLIPSE''' objects
* '''POLYGON''' objects
* '''POLYLINE''' objects


== Importing == <!--T:3-->
<!--T:21-->
The following SVG objects can be imported:
Works the same way as opening but creates the objects in the active document instead of creating a new one.
* PATH objects
* LINE objects
* RECT objects
* CIRCLE objects
* ELLIPSE objects
* POLYGON objects
* POLYLINE objects


== Exporting == <!--T:4-->
===Limitations=== <!--T:22-->

The following objects can be exported in an SVG file:
<!--T:23-->
FreeCAD will not import path objects that have only one point ([https://forum.freecadweb.org/viewtopic.php?f=3&t=43856 forum discussion]).

==Exporting== <!--T:4-->

<!--T:24-->
The following FreeCAD objects can be exported:
* Lines and wires (polylines)
* Lines and wires (polylines)
* Arcs and circles
* Arcs and circles
Line 45: Line 55:


===Limitations=== <!--T:5-->
===Limitations=== <!--T:5-->
'''Important Note:''' Keep in mind that SVG is a 2D format, so all Z information will be disregarded (all objects will be flattened).


== Preferences == <!--T:6-->
<!--T:25-->
SVG is a 2D format, so all Z information will be disregarded (all objects will be flattened).
The following parameters can be specified in the [[Draft Preferences]] tab ({{MenuCommand|Edit → Preferences → Draft}}):
* Import/Export → Import style: This lets you choose the way objects from the svg file will be drawn in FreeCAD. You can choose between:
** None: this is the faster way, there is no conversion, all objects will be black with 2px width (FreeCAD default)
** Use default color and linewidth: All imported objects will take current linewidth/color from the draft command bar
** Original color and linewidth: Objects will keep the color and linewidth (if specified) they have in the svg file
* Import/Export → Export Style:
** Translated: All elements are translated that their coordinates are positive. This should aid display and printing. The output coordinate system is not consistent between individually exported elements.
** Raw: The position of all elements preserved. This intended for CAM usage for example in PyCAM. Layers or Slices exported individually will match.
* General settings → Internal precision level:
** This value is used to check if a bezier curve segment has to be considered a straight line. If you import detailed paths, like rendered text, you may want to increase this setting up to 6. If you are working with Inkscape please consider to raise the precision in the [[SVG]] file, well. (Inkscape {{MenuCommand|Menu → File → Inkscape Preferences → SVG Output → Numeric Precision}})


== Unit Handling == <!--T:7-->
==Unit Handling== <!--T:7-->

<!--T:26-->
When exporting, a User Unit (px) equals one millimeter.
When exporting, a User Unit (px) equals one millimeter.


<!--T:8-->
<!--T:8-->
When importing, the width, height and viewBox attributes are respected. All elements are scaled to their size in millimeter, which is FreeCAD internal unit. If the SVG does not contain information on its physical size, it is assumed to have 90 DPI resolution.
When importing, the width, height and viewBox attributes are respected. All elements are scaled to their size in millimeters, which is FreeCAD's internal unit. If the SVG does not contain information on its physical size, it is assumed to have a 90 DPI resolution.
Using absoulte units in attributes inside the SVG should be avoided. Relative units like em,ex and % are currently not supported.
Using absolute units in attributes inside the SVG should be avoided. Relative units like em, ex and % are currently not supported.


<!--T:9-->
<!--T:9-->
The SVG Editor, [[Inkscape]] currently works only with 90 DPI documents. No matter which unit is selected in Inkscape. All the output has to be considered converted to 90 DPI and '''rounded''' to 6 decimal places. As FreeCAD (and the SVG standard) is agnostic to the precision of rounding done in Inkscape these values will not be rounded on input. And odd values in millimeter will remain.
The [https://inkscape.org/ Inkscape] SVG Editor currently works only with 90 DPI documents. No matter which unit is selected in Inkscape. All the output has to be considered converted to 90 DPI and rounded to 6 decimal places. As FreeCAD (and the SVG standard) is agnostic to the precision of rounding done in Inkscape these values will not be rounded on input. And odd values in millimeter will remain.
If you need the SVG import not to be rounded, work on User Units (px) in Inkscape. Scaling can be done after the import to FreeCAD or by changing the width, height and viewbox attributes.
If you need the SVG import not to be rounded, work on User Units (px) in Inkscape. Scaling can be done after the import in FreeCAD or by changing the width, height and viewbox attributes.


== Scripting == <!--T:13-->
==Preferences== <!--T:6-->

{{Emphasis|See also:}} [[Draft API]] and [[FreeCAD Scripting Basics]].
<!--T:27-->
See [[Import_Export_Preferences|Import Export Preferences]].

==Scripting== <!--T:13-->

<!--T:28-->
See also: [https://freecad.github.io/SourceDoc/ Autogenerated API documentation] and [[FreeCAD Scripting Basics|FreeCAD Scripting Basics]].


<!--T:14-->
<!--T:14-->
You can export elements to SVG by using the following function:
To export objects to SVG use the {{incode|export}} method of the importSVG module.

</translate>
</translate>
{{Code|code=
{{Code|code=
Line 80: Line 90:
}}
}}
<translate>
<translate>

<!--T:29-->
* For the Windows OS: use a {{FileName|/}} (forward slash) as the path separator in {{Incode|filename}}.


<!--T:15-->
<!--T:15-->
Example:
Example:

</translate>
</translate>
{{Code|code=
{{Code|code=
import Draft, importSVG
import FreeCAD as App
import Draft
import importSVG


doc = App.newDocument()
Polygon1 = Draft.makePolygon(3, radius=500)
Polygon2 = Draft.makePolygon(5, radius=1500)


polygon1 = Draft.make_polygon(3, radius=500)
objects = [Polygon1, Polygon2]
polygon2 = Draft.make_polygon(5, radius=1500)


doc.recompute()

objects = [polygon1, polygon2]
importSVG.export(objects, "/home/user/Pictures/myfile.svg")
importSVG.export(objects, "/home/user/Pictures/myfile.svg")
}}
}}
<translate>
<translate>


<!--T:10-->
{{docnav|[[Draft_DXF|Autodesk .DXF .DWG]]|[[Draft_OCA|Open Cad format .OCA]]|[[Draft_Module|Draft Module]]|IconC=Workbench_Draft.svg}}


<!--T:17-->
<!--T:10-->
{{Docnav
{{Draft Tools navi}}
|[[Draft_DXF|Autodesk .DXF .DWG]]
|[[Draft_OCA|Open Cad format .OCA]]
|[[Draft_Module|Draft]]
|IconL=
|IconR=
|IconC=Workbench_Draft.svg
}}


<!--T:18-->
{{Userdocnavi}}
</translate>
</translate>
{{Draft Tools navi{{#translation:}}}}
{{clear}}
{{Userdocnavi{{#translation:}}}}
[[Category:File Formats{{#translation:}}]]

Latest revision as of 08:03, 15 September 2021

Description

Draft SVG is a software module used by the Std Open, Std Import and Std Export commands to handle the SVG file format.

Inkscape drawing exported to SVG, which is subsequently opened in FreeCAD

Importing

The following SVG objects can be imported:

  • PATH objects
  • LINE objects
  • RECT objects
  • CIRCLE objects
  • ELLIPSE objects
  • POLYGON objects
  • POLYLINE objects

Limitations

FreeCAD will not import path objects that have only one point (forum discussion).

Exporting

The following FreeCAD objects can be exported:

  • Lines and wires (polylines)
  • Arcs and circles
  • Faces
  • Texts
  • Dimensions

Limitations

SVG is a 2D format, so all Z information will be disregarded (all objects will be flattened).

Unit Handling

When exporting, a User Unit (px) equals one millimeter.

When importing, the width, height and viewBox attributes are respected. All elements are scaled to their size in millimeters, which is FreeCAD's internal unit. If the SVG does not contain information on its physical size, it is assumed to have a 90 DPI resolution. Using absolute units in attributes inside the SVG should be avoided. Relative units like em, ex and % are currently not supported.

The Inkscape SVG Editor currently works only with 90 DPI documents. No matter which unit is selected in Inkscape. All the output has to be considered converted to 90 DPI and rounded to 6 decimal places. As FreeCAD (and the SVG standard) is agnostic to the precision of rounding done in Inkscape these values will not be rounded on input. And odd values in millimeter will remain. If you need the SVG import not to be rounded, work on User Units (px) in Inkscape. Scaling can be done after the import in FreeCAD or by changing the width, height and viewbox attributes.

Preferences

See Import Export Preferences.

Scripting

See also: Autogenerated API documentation and FreeCAD Scripting Basics.

To export objects to SVG use the export method of the importSVG module.

importSVG.export(exportList, filename)
  • For the Windows OS: use a / (forward slash) as the path separator in filename.

Example:

import FreeCAD as App
import Draft
import importSVG

doc = App.newDocument()

polygon1 = Draft.make_polygon(3, radius=500)
polygon2 = Draft.make_polygon(5, radius=1500)

doc.recompute()

objects = [polygon1, polygon2]
importSVG.export(objects, "/home/user/Pictures/myfile.svg")