SVG import recenter

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

SVG import recenter

Ronaldo
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
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: SVG import recenter

fred_dot_u
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/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: SVG import recenter

kintel
Administrator
In reply to this post by Ronaldo
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 <[hidden email]> 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
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: SVG import recenter

Neon22

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 <[hidden email]> 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
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


Virus-free. www.avg.com


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: SVG import recenter

fred_dot_u
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/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: SVG import recenter

Ronaldo
In reply to this post by kintel
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 <[hidden email]>:
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 <[hidden email]> 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
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: SVG import recenter

algotruneman
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 <[hidden email]>:
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 <[hidden email]> 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
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org




_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: SVG import recenter

kintel
Administrator
In reply to this post by Ronaldo
> On Jan 15, 2018, at 6:08 PM, Ronaldo Persiano <[hidden email]> 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
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: SVG import recenter

Ronaldo
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
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 <[hidden email]>:
> On Jan 15, 2018, at 6:08 PM, Ronaldo Persiano <[hidden email]> 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
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: SVG import recenter

Parkinbot
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/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
tp3
Reply | Threaded
Open this post in threaded view
|

Re: SVG import recenter

tp3
On 21.01.2018 16:26, Parkinbot wrote:
> Despite fixing the bug, wouldn't it be nice (and easy to implement)
> to have a function syntax for svg-import? Something like:
>
Nice, yes. Easy to implement, no.
Already the definition of the data structure is not trivial. That
example code will not simply work with an SVG describing a ring
(= circle with a hole) as it would just union a big and a smaller
circle so the hole would be lost.

ciao,
  Torsten.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
-- Torsten
Reply | Threaded
Open this post in threaded view
|

Re: SVG import recenter

Parkinbot
You are right. My fast example did not cover these cases, but this is not
important for functional stuff, where you can discover negative volumes.

This code

$fn = 4;
difference()
{
  circle(20);
  circle(10);
}

will give:

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

and I would expect to get this:
import = [[[ 20,-0 ],[ 0,-20 ],[-20,-0], [ 0,20]], [[ -10,-0],[ 0,-10 ],[
10,-0 ],[ 0,10]]];

which results from the M sections. Currently I am using my own converter for
this. But it would be a nice to have. Also equivalentkly for STLs.




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

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org