Draft SVG: Difference between revisions

From FreeCAD Documentation
(Added 'In progress'.)
No edit summary
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<languages/>
<languages/>

{{Page in progress}}

<translate>
<translate>
<!--T:16-->
<!--T:16-->
Line 15: Line 12:
{{GuiCommand
{{GuiCommand
|Name=Draft SVG
|Name=Draft SVG
|MenuLocation=File → Export → Flattened SVG (*.svg)
|MenuLocation=-
|Workbenches=[[Draft Workbench|Draft]]
|Workbenches=[[Draft Workbench|Draft]]
|Shortcut={{KEY|Ctrl}} + {{KEY|E}}
|Shortcut=-
|SeeAlso=-
|SeeAlso=[[Draft DXF]], [[FreeCAD and DXF Import]], [[Import Export]]
|Empty=1
|Empty=1
}}
}}


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

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


</translate>
</translate>
Line 31: Line 30:
{{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 53: Line 58:


===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).


==Unit Handling== <!--T:7-->
For more information see: [[Import_Export_Preferences|Import Export Preferences]].


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


Line 67: Line 72:


<!--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 to FreeCAD or by changing the width, height and viewbox attributes.


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

<!--T:27-->
For more information see: [[Import_Export_Preferences|Import Export Preferences]].

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

<!--T:28-->
{{Emphasis|See also:}} [[Draft API]] and [[FreeCAD Scripting Basics]].
{{Emphasis|See also:}} [[Draft API]] and [[FreeCAD Scripting Basics]].


Line 108: Line 120:
{{Userdocnavi{{#translation:}}}}
{{Userdocnavi{{#translation:}}}}
[[Category:Formats{{#translation:}}]]
[[Category:Formats{{#translation:}}]]
[[Category:File Formats{{#translation:}}]]
{{clear}}
{{clear}}

Revision as of 21:11, 8 May 2020

Draft SVG

Menu location
-
Workbenches
Draft
Default shortcut
-
Introduced in version
-
See also
-

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 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. Using absoulte 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 to FreeCAD or by changing the width, height and viewbox attributes.

Preferences

For more information see: Import Export Preferences.

Scripting

See also: Draft API and FreeCAD Scripting Basics.

You can export elements to SVG by using the following function:

importSVG.export(exportList, filename)

Example:

import Draft, importSVG

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

objects = [Polygon1, Polygon2]

importSVG.export(objects, "/home/user/Pictures/myfile.svg")