discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

SVG import recenter

R
Ronaldo
Mon, Jan 15, 2018 9:04 PM

Why OpenSCAD SVG export reposition the object? I exported a square with a
vertex at the origin in SVG format and the file import is centered at the
origin. There is no way to restore the original position for non-regular
objects. Is there no way to save in a SVG file format its original origin?

--
Sent from: http://forum.openscad.org/

Why OpenSCAD SVG export reposition the object? I exported a square with a vertex at the origin in SVG format and the file import is centered at the origin. There is no way to restore the original position for non-regular objects. Is there no way to save in a SVG file format its original origin? -- Sent from: http://forum.openscad.org/
F
fred_dot_u
Mon, Jan 15, 2018 9:38 PM

You've not made note of the program in which you are using the SVG file, so I
ran amok on my end and used Inkscape to make an assessment which may be of
no value to you.

It appears that Inkscape (and perhaps the SVG world in general?) will take a
file and arbitrarily assign the coordinate system by referencing the
bounding box of the items being created/rendered.

I created a primitive in OpenSCAD and exported it as SVG. When opened in
Inkscape, it was offset by the radius of the circle created, even though the
circle was centered on the origin in OpenSCAD.

Shifting the circle changed nothing. The circle opened in Inkscape in the
same location.

I created two circles, one with dual positive center coordinates and the
other with dual negative center coordinates. When the SVG was opened, it was
all referenced to the bounding box.

I'm operating on simple guessing here, as I did not research the foundation
of the SVG world. Most of what I might have found would have gone over my
head, while these simple tests allow for simple conclusions.

If you require a specific origin reference when moving from OpenSCAD to SVG,
it may be necessary to create registrations objects that will define the
bounding box and place your creations where desired. I suspect that any
objects created that are centered on the origin will never appear as such in
SVG form.

--
Sent from: http://forum.openscad.org/

You've not made note of the program in which you are using the SVG file, so I ran amok on my end and used Inkscape to make an assessment which may be of no value to you. It appears that Inkscape (and perhaps the SVG world in general?) will take a file and arbitrarily assign the coordinate system by referencing the bounding box of the items being created/rendered. I created a primitive in OpenSCAD and exported it as SVG. When opened in Inkscape, it was offset by the radius of the circle created, even though the circle was centered on the origin in OpenSCAD. Shifting the circle changed nothing. The circle opened in Inkscape in the same location. I created two circles, one with dual positive center coordinates and the other with dual negative center coordinates. When the SVG was opened, it was all referenced to the bounding box. I'm operating on simple guessing here, as I did not research the foundation of the SVG world. Most of what I might have found would have gone over my head, while these simple tests allow for simple conclusions. If you require a specific origin reference when moving from OpenSCAD to SVG, it may be necessary to create registrations objects that will define the bounding box and place your creations where desired. I suspect that any objects created that are centered on the origin will never appear as such in SVG form. -- Sent from: http://forum.openscad.org/
MK
Marius Kintel
Mon, Jan 15, 2018 9:49 PM

Is this an export problem or an import problem? i.e. if you inspect your
SVG file, does it look correct?

-Marius

On Mon, Jan 15, 2018 at 4:04 PM, Ronaldo rcmpersiano@gmail.com wrote:

Why OpenSCAD SVG export reposition the object? I exported a square with a
vertex at the origin in SVG format and the file import is centered at the
origin. There is no way to restore the original position for non-regular
objects. Is there no way to save in a SVG file format its original origin?

--
Sent from: http://forum.openscad.org/


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Is this an export problem or an import problem? i.e. if you inspect your SVG file, does it look correct? -Marius On Mon, Jan 15, 2018 at 4:04 PM, Ronaldo <rcmpersiano@gmail.com> wrote: > Why OpenSCAD SVG export reposition the object? I exported a square with a > vertex at the origin in SVG format and the file import is centered at the > origin. There is no way to restore the original position for non-regular > objects. Is there no way to save in a SVG file format its original origin? > > > > > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
MS
Mark Schafer
Mon, Jan 15, 2018 10:56 PM

IMHO - use the openscad exporter from inkscape.
https://www.thingiverse.com/thing:1065500

On 1/16/2018 10:49 AM, Marius Kintel wrote:

Is this an export problem or an import problem? i.e. if you inspect your SVG file, does it look correct?

-Marius

On Mon, Jan 15, 2018 at 4:04 PM, Ronaldo <rcmpersiano@gmail.com> wrote:

Why OpenSCAD SVG export reposition the object? I exported a square with a
vertex at the origin in SVG format and the file import is centered at the
origin. There is no way to restore the original position for non-regular
objects. Is there no way to save in a SVG file format its original origin?

--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

[![](https://ipmcdn.avast.com/images/icons/icon-envelope-tick-green-avg-v1.png)](http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient) Virus-free. [www.avg.com](http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient)     [ ](#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2)
<pre wrap="">_______________________________________________
OpenSCAD mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Discuss@lists.openscad.org">Discuss@lists.openscad.org</a>
<a class="moz-txt-link-freetext" href="http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org">http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org</a>
F
fred_dot_u
Mon, Jan 15, 2018 11:03 PM

I think the OP is trying to get a reverse of that which the Thingiverse
Inkscape OpenSCAD extension provides. It takes an SVG and turns it into an
OpenSCAD file/STL, while the original request is to position an OpenSCAD
created shape exported as SVG, based on the OpenSCAD coordinate system.

--
Sent from: http://forum.openscad.org/

I think the OP is trying to get a reverse of that which the Thingiverse Inkscape OpenSCAD extension provides. It takes an SVG and turns it into an OpenSCAD file/STL, while the original request is to position an OpenSCAD created shape exported as SVG, based on the OpenSCAD coordinate system. -- Sent from: http://forum.openscad.org/
RP
Ronaldo Persiano
Mon, Jan 15, 2018 11:08 PM

I don't know how to answer that because I don't know the SVG file format.
The code I rendered to export was:

square(40);

and the exported file was:

<?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" " http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg width="40mm" height="40mm" viewBox="0 -40 40 40" xmlns=" http://www.w3.org/2000/svg" version="1.1">

<title>OpenSCAD Model</title> <path d=" M 0,-0 L 40,-0 L 40,-40 L 0,-40 z " stroke="black" fill="lightgray" stroke-width="0.5"/> </svg>

This file import renders a centered square with the correct size.

2018-01-15 19:49 GMT-02:00 Marius Kintel marius@kintel.net:

Is this an export problem or an import problem? i.e. if you inspect your
SVG file, does it look correct?

-Marius

On Mon, Jan 15, 2018 at 4:04 PM, Ronaldo rcmpersiano@gmail.com wrote:

Why OpenSCAD SVG export reposition the object? I exported a square with a
vertex at the origin in SVG format and the file import is centered at the
origin. There is no way to restore the original position for non-regular
objects. Is there no way to save in a SVG file format its original origin?

--
Sent from: http://forum.openscad.org/


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

I don't know how to answer that because I don't know the SVG file format. The code I rendered to export was: square(40); and the exported file was: <?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" " http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="40mm" height="40mm" viewBox="0 -40 40 40" xmlns=" http://www.w3.org/2000/svg" version="1.1"> <title>OpenSCAD Model</title> <path d=" M 0,-0 L 40,-0 L 40,-40 L 0,-40 z " stroke="black" fill="lightgray" stroke-width="0.5"/> </svg> This file import renders a centered square with the correct size. 2018-01-15 19:49 GMT-02:00 Marius Kintel <marius@kintel.net>: > Is this an export problem or an import problem? i.e. if you inspect your > SVG file, does it look correct? > > -Marius > > On Mon, Jan 15, 2018 at 4:04 PM, Ronaldo <rcmpersiano@gmail.com> wrote: > >> Why OpenSCAD SVG export reposition the object? I exported a square with a >> vertex at the origin in SVG format and the file import is centered at the >> origin. There is no way to restore the original position for non-regular >> objects. Is there no way to save in a SVG file format its original origin? >> >> >> >> >> -- >> Sent from: http://forum.openscad.org/ >> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> > > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > >
AR
Algot Runeman
Mon, Jan 15, 2018 11:27 PM

It would seem you could subtract 1/2 the SVG dimensions (1/2 of square's
size, in this case) (assume both mm in Inkscape and in OpenSCAD) which
would relocate the image, no?

Where are you importing to?

On 01/15/2018 06:08 PM, Ronaldo Persiano wrote:

I don't know how to answer that because I don't know the SVG file
format. The code I rendered to export was:

 square(40);

and the exported file was:

 <?xml version="1.0" standalone="no"?>
 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
 <svg width="40mm" height="40mm" viewBox="0 -40 40 40"
 xmlns="http://www.w3.org/2000/svg" version="1.1">
 <title>OpenSCAD Model</title>
 <path d="
 M 0,-0 L 40,-0 L 40,-40 L 0,-40 z
 " stroke="black" fill="lightgray" stroke-width="0.5"/>
 </svg>

This file import renders a centered square with the correct size.

2018-01-15 19:49 GMT-02:00 Marius Kintel <marius@kintel.net
mailto:marius@kintel.net>:

 Is this an export problem or an import problem? i.e. if you
 inspect your SVG file, does it look correct?

  -Marius

 On Mon, Jan 15, 2018 at 4:04 PM, Ronaldo <rcmpersiano@gmail.com
 <mailto:rcmpersiano@gmail.com>> wrote:

     Why OpenSCAD SVG export reposition the object? I exported a
     square with a
     vertex at the origin in SVG format and the file import is
     centered at the
     origin. There is no way to restore the original position for
     non-regular
     objects. Is there no way to save in a SVG file format its
     original origin?




     --
     Sent from: http://forum.openscad.org/

     _______________________________________________
     OpenSCAD mailing list
     Discuss@lists.openscad.org <mailto:Discuss@lists.openscad.org>
     http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
     <http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org>



 _______________________________________________
 OpenSCAD mailing list
 Discuss@lists.openscad.org <mailto:Discuss@lists.openscad.org>
 http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
 <http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org>

OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

It would seem you could subtract 1/2 the SVG dimensions (1/2 of square's size, in this case) (assume both mm in Inkscape and in OpenSCAD) which would relocate the image, no? Where are you importing to? On 01/15/2018 06:08 PM, Ronaldo Persiano wrote: > I don't know how to answer that because I don't know the SVG file > format. The code I rendered to export was: > > square(40); > > > and the exported file was: > > <?xml version="1.0" standalone="no"?> > <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" > "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> > <svg width="40mm" height="40mm" viewBox="0 -40 40 40" > xmlns="http://www.w3.org/2000/svg" version="1.1"> > <title>OpenSCAD Model</title> > <path d=" > M 0,-0 L 40,-0 L 40,-40 L 0,-40 z > " stroke="black" fill="lightgray" stroke-width="0.5"/> > </svg> > > > This file import renders a centered square with the correct size. > > 2018-01-15 19:49 GMT-02:00 Marius Kintel <marius@kintel.net > <mailto:marius@kintel.net>>: > > Is this an export problem or an import problem? i.e. if you > inspect your SVG file, does it look correct? > >  -Marius > > On Mon, Jan 15, 2018 at 4:04 PM, Ronaldo <rcmpersiano@gmail.com > <mailto:rcmpersiano@gmail.com>> wrote: > > Why OpenSCAD SVG export reposition the object? I exported a > square with a > vertex at the origin in SVG format and the file import is > centered at the > origin. There is no way to restore the original position for > non-regular > objects. Is there no way to save in a SVG file format its > original origin? > > > > > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org <mailto:Discuss@lists.openscad.org> > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > <http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org> > > > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org <mailto:Discuss@lists.openscad.org> > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > <http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org> > > > > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
MK
Marius Kintel
Tue, Jan 16, 2018 12:17 AM

On Jan 15, 2018, at 6:08 PM, Ronaldo Persiano rcmpersiano@gmail.com wrote:

and the exported file was:
[...]

Thanks. This is an import issue and is covered by https://github.com/openscad/openscad/issues/1740

If anyone wants to contribute to SVG import, there is more work to do in this domain before it can become a stable feature.

-Marius

> On Jan 15, 2018, at 6:08 PM, Ronaldo Persiano <rcmpersiano@gmail.com> wrote: > > and the exported file was: > [...] Thanks. This is an import issue and is covered by https://github.com/openscad/openscad/issues/1740 If anyone wants to contribute to SVG import, there is more work to do in this domain before it can become a stable feature. -Marius
RP
Ronaldo Persiano
Tue, Jan 16, 2018 12:47 AM

I am using version 2018.01.06. The problem seems to be in both import and
export or how they map the coordinate system of SVG into the coordinate
system of OpenSCAD.
For instance, the following SVG file

<?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" " http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg width="80mm" height="80mm" viewBox="0 0 80 80" xmlns=" http://www.w3.org/2000/svg" version="1.1">

<title>OpenSCAD Model</title> <path d=" M 40,40 L 80,40 L 80,80 L 40,80 z " stroke="black" fill="lightgray" stroke-width="0.5"/> </svg>

is shown as a square translated from the origin in the online editor
https://www.freecodeformat.com/svg-editor.php.
But if you import that SVG file into OpenSCAD, the square is centered.

On the other hand, the SVG file exported by:

translate([40,40]) square(40);

does not show any translation in the referred SVG editor.

2018-01-15 22:17 GMT-02:00 Marius Kintel marius@kintel.net:

On Jan 15, 2018, at 6:08 PM, Ronaldo Persiano rcmpersiano@gmail.com

wrote:

and the exported file was:
[...]

Thanks. This is an import issue and is covered by
https://github.com/openscad/openscad/issues/1740

If anyone wants to contribute to SVG import, there is more work to do in
this domain before it can become a stable feature.

-Marius


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

I am using version 2018.01.06. The problem seems to be in both import and export or how they map the coordinate system of SVG into the coordinate system of OpenSCAD. For instance, the following SVG file <?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" " http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="80mm" height="80mm" viewBox="0 0 80 80" xmlns=" http://www.w3.org/2000/svg" version="1.1"> <title>OpenSCAD Model</title> <path d=" M 40,40 L 80,40 L 80,80 L 40,80 z " stroke="black" fill="lightgray" stroke-width="0.5"/> </svg> is shown as a square translated from the origin in the online editor https://www.freecodeformat.com/svg-editor.php. But if you import that SVG file into OpenSCAD, the square is centered. On the other hand, the SVG file exported by: translate([40,40]) square(40); does not show any translation in the referred SVG editor. 2018-01-15 22:17 GMT-02:00 Marius Kintel <marius@kintel.net>: > > On Jan 15, 2018, at 6:08 PM, Ronaldo Persiano <rcmpersiano@gmail.com> > wrote: > > > > and the exported file was: > > [...] > > Thanks. This is an import issue and is covered by > https://github.com/openscad/openscad/issues/1740 > > If anyone wants to contribute to SVG import, there is more work to do in > this domain before it can become a stable feature. > > -Marius > > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
P
Parkinbot
Sun, Jan 21, 2018 3:26 PM

Despite fixing the bug, wouldn't it be nice (and easy to implement) to have a
function syntax for svg-import? Something like:

data = import("my.svg");
for(p=data) polygon(p);

--
Sent from: http://forum.openscad.org/

Despite fixing the bug, wouldn't it be nice (and easy to implement) to have a function syntax for svg-import? Something like: data = import("my.svg"); for(p=data) polygon(p); -- Sent from: http://forum.openscad.org/