OpenSCAD import / importCSG: support for SVG?

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
r31415
Posts: 5
Joined: Fri Jan 17, 2020 4:02 pm

OpenSCAD import / importCSG: support for SVG?

Post by r31415 »

When importing OpenSCAD-models, importCSG.py only supports dxf as 2D-format.

Since FreeCAD already has an SVG-import: Would it be possible, to also support svg in importCSG.py?
Is there any plan to support this, or what would have to be done?

Then, it would be possible, to import extruded SVGs from OpenSCAD to FreeCAD.
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: OpenSCAD import / importCSG: support for SVG?

Post by keithsloan52 »

r31415 wrote: Fri Jan 08, 2021 8:36 pm When importing OpenSCAD-models, importCSG.py only supports dxf as 2D-format.

Since FreeCAD already has an SVG-import: Would it be possible, to also support svg in importCSG.py?
Is there any plan to support this, or what would have to be done?

Then, it would be possible, to import extruded SVGs from OpenSCAD to FreeCAD.
OpenSCAD import of SVG requires the 2019 version and importCSG has not been updated to support that facility.
importCSG would need to have code added to import the SVG file to a FreeCAD Object.
Do you have a small test scad and svg that I could use to evaluate?
r31415
Posts: 5
Joined: Fri Jan 17, 2020 4:02 pm

Re: OpenSCAD import / importCSG: support for SVG?

Post by r31415 »

Thanks for your answer, and sorry that I haven't replied earlier.

I've attached a minimal example.

I would be very pleased, if FreeCAD could import CSG+SVG in the (near) future, and I'm willing to help, but I don't know the FreeCAD-codebase.
Attachments
svg-test.csg
CSG-file, exported by OpenSCAD, to be imported by FreeCAD
(300 Bytes) Downloaded 29 times
svg-test.svg
SVG example
(4.18 KiB) Downloaded 41 times
svg-test.scad
OpenSCAD with SVG
(150 Bytes) Downloaded 37 times
User avatar
chennes
Veteran
Posts: 3876
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: OpenSCAD import / importCSG: support for SVG?

Post by chennes »

This is on my radar for 0.20 as we work to make interoperability with OpenSCAD more robust. There are some glitches in the DXF code that need resolution as well.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: OpenSCAD import / importCSG: support for SVG?

Post by keithsloan52 »

chennes wrote: Mon Apr 12, 2021 12:59 am This is on my radar for 0.20 as we work to make interoperability with OpenSCAD more robust. There are some glitches in the DXF code that need resolution as well.
Chris - Way to Go :D :)
Kuxe
Posts: 1
Joined: Thu Aug 04, 2022 8:35 am

Re: OpenSCAD import / importCSG: support for SVG?

Post by Kuxe »

Any updates on this? I have FreeCAD 0.20 but I wind up with:

Code: Select all

File "/usr/lib/freecad/Mod/OpenSCAD/importCSG.py", line 866, in process_import_file
    raise ValueError("Unsupported file extension %s" % ext)
<class 'ValueError'>: Unsupported file extension svg
when importing .csg to FreeCAD, where the .csg was exported from a .scad with a .svg import.
User avatar
chennes
Veteran
Posts: 3876
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: OpenSCAD import / importCSG: support for SVG?

Post by chennes »

No, this didn't happen for 0.20 (as you've discovered). It's still on the "someday to-do list", but if any other dev wants to have at it please go ahead!
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: OpenSCAD import / importCSG: support for SVG?

Post by keithsloan52 »

For SVG FreeCAD uses sax

From importSVG.py

Code: Select all

# Set up the parser
    parser = xml.sax.make_parser()
    parser.setFeature(xml.sax.handler.feature_external_ges, False)
    parser.setContentHandler(svgHandler())
    parser._cont_handler.doc = doc
Wondering if there is a way to have it create a single object rather than insert n objects into a doc.
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: OpenSCAD import / importCSG: support for SVG?

Post by keithsloan52 »

Okay I have added code to the Alternate OpenSCAD importer https://github.com/KeithSloan/OpenSCAD_Alt_Import

Remember with the Alternate importer you need to select open file - csg or scad file
Then you will be prompted as to which importer you wish to use.

Image 08-08-2022 at 20.30.jpg
Image 08-08-2022 at 20.30.jpg (377.65 KiB) Viewed 736 times
User avatar
chennes
Veteran
Posts: 3876
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: OpenSCAD import / importCSG: support for SVG?

Post by chennes »

keithsloan52 wrote: Mon Aug 08, 2022 6:10 pm Wondering if there is a way to have it create a single object rather than insert n objects into a doc.
Did you get this resolved?
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
Post Reply