Scale problem while importing from Inkscape

Hi !

Something funny here: I have to work quite a lot from inkscape these days.
I create profiles there and import them into blender.

Now, i have all my inscape files using centimeters as unit.
Let us say I create a square document, 10cm×10cm, filled with a square shape 10×10cm

I thought that importing that to blender would mean getting a 0.1BU×0.1BU square. But it doesn’t. In fact I get something strange, a ratio i didn’t understand at first.

So i thought, let’s try with a 100 pixel×100pixel inkscape document and square. I import into blender: nope, rather strange too.

And now, the horrible truth: a 1 inch×1inch square ! Import it into the blender, and voila ! a 1 BU× 1BU square.

BUT ! This is only true if you set your scen units to be “none” or “metric” ! If you choose “imperial”, you don’t get the 1×1 square !

So to sum it up, a 1in×1in square in inkscape is a 1BU×1BU square in Blender if you use Metrics !!! :spin::spin::spin::spin::spin::spin:

I thought that an explicit measure in centimeters in inkscape would translate to the same in Blender if Blender is set to “metrics” !

This beats me…

No-one knows why this strange behaviour ?

Don’t know -will try and see- but at the beginning of the file there is this table:

SVGUnits = {"": 1.0,
            "px": 1.0,
            "in": 90,
            "mm": 90 / 25.4,
            "cm": 90 / 2.54,
            "pt": 1.25,
            "pc": 15.0,
            "em": 1.0,
            "ex": 1.0,
            "INVALID": 1.0,  # some DocBook files contain this

does it makes sense? you could just edit it if not…

edit: tried this myself but didn’t work, only editing matrices at end of file did it :frowning:

This is strange. I have to check if SVG files specify the unit within themselves.

Well, i am a bit surprised.
The importer searches for units at the ends of values, like “width=34.01cm” or “height=2.87in”.
But inkscape doesn’t specify the units like that. Instead there is a special node in the xml tree, under “sodipodi:namedview”

I googled up “svg” and looked at wikipedia’s article, and the example doesn’t show units right after values.

So, i had a deeper look at the importer, and there is nothing wrong there at all.
@liero: indeed, changing these values doesn’t help, for the following reason:
Inkscape export without mentionning the units of the coordinates. This is accepted behaviour. one could specify: “x=12.3cm” or leave “x=12.3” just as well in which case the user system determines what to do.
So in our case, coordinates are read without units, and the applied scaling factor is the one mentionned in the snippet of code you posted on line 1:

“”: 1.0,

Changing the other values further down only has an influence if coordinates are given with a specified unit, like “width=12.45in”
In that case, the value given in your code snippet plays a role.

So I think this importer should go a bit further and read inkscape file better.
In fact, in an inkscape file, one can find a “sodipodi:namedview” xml node. In there we can find a “units” attribute which is the unit you use in the “viewport” of inkscape. Reading that value (could be in, cm, mm,etc…) and re-using it when coordinates units are not mentionned would be a great thing !

I struggle to understand how the importer work (first taste on object oriented scripting: I feel a bit lost there…)
I hope i can play with that and have some success !


yep, I took a similar route as you did, found the easiest way is editing the matrices at the end of importer… added m*= 0.0254 to line 1760 and get it to import in cm… but just a hack

Just for the record:
Inkscape SVG != SVG.
You can save as plain SVG but it makes no difference.

Made an SVG with an 1x1m square.
Import it to Blender with BU, square is imported with dimensions: 39.163 BU / 39.163 BU
If you set it to metric, it is imported with dimensions: 39.163m / 39.163m
If you set it to imperial, it is imported with dimensions: 42.83yd / 42.83yd

And now guess what´s in the SVG file?
<rect width=“3524.7019” height=“3524.7021” …

those are pixel, which are 1m if you open it up back in inkscape.

Now if you set the file properties in inkscape to meter and save it.
Import it to blender with metric, the suare is imported with dimensions: 39.163m / 39.163m

If you look in the SVG again:
<sodipodi:namedview … units=“m” …
<rect width=“3524.7019” height=“3524.7021”…

So blenders svg importer seems just to do what´s fed to him.

so, screw Inkscape, lets do W3C compliant SVG 1.1

&lt;?xml version="1.0" standalone="no"?&gt;
&lt;!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 

&lt;svg width="100cm" height="100cm" version="1.1"

&lt;rect x="0" y="0" width="100cm" height="100cm"


Guess what happens if you import it with Blender set to metric…
dimensions: 39.163m / 39.163m

So inkscape makes the quad 3524.7 pixel
Blender imports it with a size of 39.163 BU
And one meter should have 39.37 inches so it´s not just 100DPI either.

this makes no sense to me :smiley:

@ Arexma:

I don’t know what you did wrong, but as you code example specifies units with coordinates (width=“100cm”) , it should work…and it does ! You get a nice 1m square.

It is not 100dpi neither, the base is 90dpi. Look at the dimensions you give:39.163BU and 3524.7019 make a 90:1 ratio

Inkscape does indeed produce an “enriched” svg. The idea would be to use the units field to specify to blender the ratio to apply.

I know it. It was 3.00 am when I did this and I was up since 8am ^^
I also didn´t see the 90dpi… tbh I was too tired already to divide…

Anyways. Blenders importer then abides to SVG standards. To cover Inkscapes escapades would require a lot of coding, would be great though as Inkscape often goes hand in hand with Blender, at least in my pipeline. I usually insert a “default square” in the svg and then scale the whole thing after import. Not the best solution, but the result fits. I don´t know if hours, weeks maybe even months of coding would justify so we get the luxury to save us 1 minute of scaling :wink:

I did some readup and it seems Inkscape assumes 90dpi for everything as fixed value, if you where to change the DPI in inkscape you could force it to another pixel value.
Automation most likely would be to have blenders importer check if it is an inkscape svg, if so, check if there´s a measurement set like “meter” and recalculate all import values with the 90dpi.

The question is the responsibility. Does Blender have to import non standard compliant SVG, or does Inkscape has to export standard compliant SVG with the “default SVG” save option - because it´s not very default if you do so either.

I´d say it is the responsibility of Inkscape, however if we wait for them to do or ask them to do the stuff right and wait, we’ll grow old men. :wink:

And the next question is rather philosophical but as the name SVG suggests, its scalable, so does it have to have a set unit system at all? You can fit it to anything you want, you just have to scale it.

I find it a bigger problem, that the import to blender often fails on filling the geometry like it shows in inkscape, or to simply change which areas to fill if you scale it.
And the convert to mesh feature is simply a catastrophe. If you import a svg, for example a brand logo or something and leave it curves, approximated AO and shadows often cause problems, especially if you extrude the curves, which wouldnt be if you wher to use a mesh.
If you convert to a mesh though, you got the problem that you for instance can´t let it follow a curve anymore due to the nature of the geometry.

It would be grand if the convert to mesh could actually parse the curve, and create a grid-mesh based on a set gridwith from it and not “just” take the curves controlpoints and “somehow rather randomly” fill them with triangles.

I don’t think it is that big a task really. I mean, I am not used to object oriented programming but i think i could succed to adapt that script.

You seem to say that inkscape produces non compliant svg, but i am not so sure of that ! Inkscape doesn’t specify units when giving out coordinates, but that seems to be quite acceptable in the guidelines of the svg format:
See chapter 7.10

I’ll try something !

EDIT: think it’s ok, but i’d like the import to work like Inkscape: Origin is bottom left in inkscape