Draft SVG/sv: Difference between revisions

From FreeCAD Documentation
(Updating to match new version of source page)
(Updating to match new version of source page)
Line 11: Line 11:
</div>
</div>


== Description ==
==Description==

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


[[Image:Screenshot inkscape.jpg]]
[[Image:Screenshot inkscape.jpg]]
Line 27: Line 28:
</div>
</div>


The following SVG objects can be imported:
<div class="mw-translate-fuzzy">
* PATH objects
===Importera===
* LINE objects
* RECT objects
* CIRCLE objects
* ELLIPSE objects
* POLYGON objects
* POLYLINE objects


===Limitations===
Fungerar på samma sätt som att öppna men skapar objekten i det aktiva dokumentet istället för att skapa ett nytt.

</div>
FreeCAD will not import path objects that have only one point ([https://forum.freecadweb.org/viewtopic.php?f=3&t=43856 forum discussion]).


<div class="mw-translate-fuzzy">
<div class="mw-translate-fuzzy">
Line 44: Line 52:
* Dimensioner
* Dimensioner
</div>
</div>

The following FreeCAD objects can be exported:
* Lines and wires (polylines)
* Arcs and circles
* Faces
* Texts
* Dimensions


<div class="mw-translate-fuzzy">
<div class="mw-translate-fuzzy">
Tänk på att SVG är ett 2D format, så all Z information kommer att ignoreras (alla objekt kommer att plattas ut).
Tänk på att SVG är ett 2D format, så all Z information kommer att ignoreras (alla objekt kommer att plattas ut).
</div>
</div>

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 [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.


<div class="mw-translate-fuzzy">
<div class="mw-translate-fuzzy">
Line 59: Line 86:
</div>
</div>


For more information see: [[Import_Export_Preferences|Import Export Preferences]].
== Unit Handling ==
When exporting, a User Unit (px) equals one millimeter.


==Scripting==
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 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.
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 ==
{{Emphasis|See also:}} [[Draft API]] and [[FreeCAD Scripting Basics]].
{{Emphasis|See also:}} [[Draft API]] and [[FreeCAD Scripting Basics]].



Revision as of 20:49, 12 March 2020

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

Öppna

Denna funktion importerar SVG file som redigerbara 2D objekt, i motsats till den inbyggda Ritningsmodulen vilken importerar svg filer som pappersritningar. Följande SVG objekt importeras för närvarande:

  • PATH objekt med M, C, L eller A kommandon
  • RECT objekt

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

Exportera

Följande objekt kan exporteras i en SVG fil:

  • Linjer och trådar (polylines)
  • Cirkelbågar och cirklar
  • Ytor
  • Text
  • Dimensioner

The following FreeCAD objects can be exported:

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

Tänk på att SVG är ett 2D format, så all Z information kommer att ignoreras (alla objekt kommer att plattas ut).

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.

Alternativ

Följande parametrar kan specificeras i Skissalternativ tabben (meny Redigera -> Alternativ -> Draft):

  • Import style: Detta låter dig välja på vilket sätt som objekten från svg filen kommer att ritas i FreeCAD. Du kan välja mellan:
    • None: detta är det snabbare sättet, ingen konvertering utförs, alla objekt kommer att vara svarta med 2 pixels bredd (FreeCAD standard)
    • Use default color and linewidth: Alla importerade objekt kommer att anta nuvarande linjebredd/färg från Skiss kommandolådan
    • Original color and linewidth: Objekt kommer att behålla den färg och linjebredd (om den är specificerad) som de har i svg filen

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")