SVG import
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Be nice to others! Read the FreeCAD code of conduct!
Re: SVG import
Hi Sebastian,
Great work! this importer is becoming very complete.
A couple of objects in my test files 7 and 8 don't get imported, though, and give a math domain error... I'll have a look but you'll probably find the problem before me
Great work! this importer is becoming very complete.
A couple of objects in my test files 7 and 8 don't get imported, though, and give a math domain error... I'll have a look but you'll probably find the problem before me
Re: SVG import
I fixed a problem with test7 when there is only a singular solution and the a radix reaches -0.
But there is still a problem with test8 path3757.
(having sweepflag and large-arc-flag set)
large arc should not be set for an arc with exactly 180°
becomes
after applying sweep:
first angle1=-3.14 == 3.14 (drawn)
second angle1=-6.28 == 0 (not drawn)?
But there is still a problem with test8 path3757.
Code: Select all
a 14.142136,14.142136 0 1 1 -28.28427,0 14.142136,14.142136 0 1 1 28.28427,0
large arc should not be set for an arc with exactly 180°
becomes
Code: Select all
angle1=0.000376060307317 angledelta=3.14084053297 center=(122.228, -292.733, 0) rx=14.142136 ry=14.142136
angle1=-3.14121659328 angledelta=3.14084053297 center=(122.228, -292.722, 0) rx=14.142136 ry=14.142136
first angle1=-3.14 == 3.14 (drawn)
second angle1=-6.28 == 0 (not drawn)?
Re: SVG import
Importing of test8 now works up to a Draft.precision of 6 decimal places.
Re: SVG import
I have changed my mind on the unit handling for importSVG. I think that a full, spec compliant, implementation would be of little use. But i allready finished the regular expression, so we can make the function to strip the unit more beautiful.
where length is a string, and number also contains the exponent.
Code: Select all
def getsize(length):
"""extracts a number from the given string (removes unit suffixes)"""
number, exponent, unit=re.findall('([-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)(px|pt|pc|mm|cm|in|em|ex|%)?',length)[0]
return float(number)
Re: SVG import
That would simply "forget" about units and consider that 1 "any unit" in the svg doc equals 1 freecad unit. I think that's fine, actually that's the behaviour most of us will want anyway. As far as I know there is still virtually nobody who uses the svg format for technical drawing, and might want to import something that has very complex unit specification (like, some objects in mm and others in cm...)
Re: SVG import
Many hobbyist use Inkscape to make simple drawing at right size.As far as I know there is still virtually nobody who uses the svg format for technical drawing, and might want to import something that has very complex unit specification (like, some objects in mm and others in cm...)
Another use is to CNC engraving
Personnaly, I use inkscape to draw body guitar.... I try to import SVG body in freeCAD, they works but my body draw doesn't have good dimension.
So, for my use, i would like Freecad manage unit properly.
Thanks for your works.
Re: SVG import
If you used a current version of inkscape, there i a high chance that scaling by 0.2822222 (25.4mm/in / 90dpi) fixes your problem for the moment.ryback08 wrote:I try to import SVG body in freeCAD, they works but my body draw doesn't have good dimension.
So, for my use, i would like Freecad manage unit properly.
Handling the view box to get the scaling of user units right is on my list. But there are flags that tell if some wants to keep the aspect ratio or not . For the moment I'd rather leave the user with some scaling (and checking) to do by himself, than introducing gliches that my slightly mess up the aspect ratio.
On the other hand even inkscape is not perfect. Currently you can't use inkscape to work in cusom user units. Inkscape just displays everything in the user selected unit, but all svg data is created with 90dpi.
But there are three other things you can do SVG which are of litte use.
1. Lengths beings multipe of the viewbox (unit %)
2. Lengths that depend on the current font, only useful for typesetting (units em,ex)
3. Lengths that are CSS compatible and therefore iterpreted to be multiple of user units if used inside the document. (width="1in" is interpreted as width="90px" no matter what the real world dimension of the SVG are.
If the global user unit is not 90dpi, using 'css compatible' units in the document, they won't be absoulte, and problably break the document. On the other hand, if you want to use intermixed units, you need to your 'paths' to be in 90dpi coordinates.yorikvanhavre wrote:As far as I know there is still virtually nobody who uses the svg format for technical drawing, and might want to import something that has very complex unit specification (like, some objects in mm and others in cm...)
You can work around this for webdisgn. But you should avoid it for CAD.Note that use of px units or any other absolute unit identifiers can cause inconsistent visual results on different viewing environments since the size of "1px" may map to a different number of user units on different systems; thus, absolute units identifiers are only recommended for the ‘width’ and the ‘height’ on and situations where the content contains no transformations and it is desirable to specify values relative to the device pixel grid or to a particular real world unit size.
If someone asks for a special workflow (like FreeCAD->PyCAM or Inkscape->FreeCAD) i'll happy to make this work. But there are things that are of little use and often can be solved easier. As there is no support for the 'use' element someone needs to convert cloned copies to plain copies using inkscape. I don't see a point in implementing this before someone tells me he has more than 50 svg Files to process.
Re: SVG import
I've added the scaling of the whole svg acording to the viewbox, height and width attributes. Please put https://github.com/5263/free-cad/raw/sv ... portSVG.py to Mod/Draft in your FreeCAD directory and try again.ryback08 wrote:Personnaly, I use inkscape to draw body guitar.... I try to import SVG body in freeCAD, they works but my body draw doesn't have good dimension.
So, for my use, i would like Freecad manage unit properly.
Re: SVG import
Thank Shoogen
I rapidly try on windows (freecad 0.12), they do not seems works
So i try on linux (daily build 0.13 5075). FreedCAD try to open my SVG file. I have not line as before, just many point who draw my outline (contour).
Measure isn't correctly, still too large (approximately 3980 a place of 320mm)
I look into my SVG files, I look code and i see units="cm".
I open SVG files in inkscape, modify unit to "mm", open in freecad, the resulut is similar.
With old "importSVG.py", i have measure about 1123 (always at place of 320mm)
Excuse me for my quickly test, it is late. I would do more test tomorrow. maybe I've made a mistake.
Good night and realy thank for your work
I rapidly try on windows (freecad 0.12), they do not seems works
So i try on linux (daily build 0.13 5075). FreedCAD try to open my SVG file. I have not line as before, just many point who draw my outline (contour).
Measure isn't correctly, still too large (approximately 3980 a place of 320mm)
I look into my SVG files, I look code and i see units="cm".
I open SVG files in inkscape, modify unit to "mm", open in freecad, the resulut is similar.
With old "importSVG.py", i have measure about 1123 (always at place of 320mm)
Excuse me for my quickly test, it is late. I would do more test tomorrow. maybe I've made a mistake.
Good night and realy thank for your work
Re: SVG import
Hi ryback.
Sorry I mixed up multiplication and divsion;(
1123px25.4(mm/in)/90dpi=316.94mm (inkscpe 90dpi output)
3980x25.4²/90²=317(mm) (messed up)
I fixed that in my github repo.
SVG import is abit senstive to precission problems. You may want to tweak your Draft precision setting. There is currently no Windows build that includes the 'Part.Compound().connectEdgesToWires' function, which may be called it the wire segments dont line up.
Thanks for your feedback.
Sorry I mixed up multiplication and divsion;(
1123px25.4(mm/in)/90dpi=316.94mm (inkscpe 90dpi output)
3980x25.4²/90²=317(mm) (messed up)
I fixed that in my github repo.
SVG import is abit senstive to precission problems. You may want to tweak your Draft precision setting. There is currently no Windows build that includes the 'Part.Compound().connectEdgesToWires' function, which may be called it the wire segments dont line up.
Thanks for your feedback.