Author Topic: Export to SVG - new plugin  (Read 11539 times)

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5263
  • Made in England
    • View Profile
Export to SVG - new plugin
« on: October 12, 2020, 20:45:24 pm »
I wanted this for use with my small laser cutter.
Instead of having to use Inkscape for everthing I thought it would good if CamBam could export SVG files that I import to "K40 Whisperer".

K40 Whisperer is ideal because it can directly control the laser for homing etc.

These are the operations supported by the plugin.

1. If the CamBam Layer has an "x" or "X" in it's Tag filed then any exported closed objects on that layer will be filled with the layer colour.
2. object are exported with the same colour as their CamBam layer
3. Polyline, straight or with 'bulge', if closed they can also be filled. exported as a 'path'
4. Spline,  if closed they can also be filled, exported as a 'path'
5. Polyrectangle, with or without corner radius applied, can also be filled
6. Lines, such as from an 'exploded' polyrectangle
7. Arc, exported as a 'path'
8. Circle, can be filled
9. Text, exported as 'text', can be 'regular', 'bold', 'italic' , can be filled
10. exported objects are 'grouped' according to their CamBam layers
11. Line thickness is exported from the CamBam Layer 'Pen Width', if it is set to 0 then the default exported width is 0.1 (mm)
12. looks at "Visible" layers only

Version 1.0 plugin attached for CamBam v1.0 only, I'm not planning to supporting 0.9.8. in future.
A sample cb file attached

The plugin will appear in, File->Export->to SVG

Edit:  version 2 attached
1. resizes page to exported objects
2. centralises objects on page
3. dimensions of objects imported by Inkscape are the same as those in CamBam
4. paths for Polylines with multiple arcs and lines will now "combine" into one path so that fill works correctly. (same as CamBam "Join")
5. the diagonal line in Bubba's sample file is fixed.

Edit: version 3 attached
1. added units to the svg file, both in the "width" and "height" parameters and also "units" ("mm" and "in")
2. Finally got "Namespace" sorted out, K40 would not open the file without that being set correctly.
3. tested with splines attached to polylines attached to arcs multiple times, then used CamBam "join" to see if the closed shape would colour fill okay in Inkscape and K40 Whisperer.
4 As far as I can make out the exported geometry is the same size as in CamBam however Inkscape also includes the stroke width in size.

Edit: version 3.1 attached
1. changed default stroke width to 0.04 for inches system, remeber you can set the exact Pen Width on the CamBam layer before exporting.

Edit: version 4.0 attached
1. rewrote Classes for svg objects, better code now.

Edit: verrsion 5.0 attached
1. added transforms to objects (rotation about Z and X,Y, translation only)  but that should be fine for all 2D work.
« Last Edit: November 01, 2020, 20:26:17 pm by EddyCurrent »
Filmed in Supermarionation

Offline Bubba

  • CNC Jedi
  • *****
  • Posts: 3355
    • View Profile
Re: Export to SVG - new plugin
« Reply #1 on: October 12, 2020, 21:10:15 pm »
Certainly welcomed addition for CB. As always Thank You for this.
My 2¢

Win11, CB(1.0)rc 1(64 bit) Mach3, ESS, G540, 4th Axis, Endurance Laser.

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7410
    • View Profile
    • Cambam V1.0 French Doc
Re: Export to SVG - new plugin
« Reply #2 on: October 12, 2020, 21:18:29 pm »
Thanks Eddy  ;D

++
David

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5263
  • Made in England
    • View Profile
Re: Export to SVG - new plugin
« Reply #3 on: October 12, 2020, 21:29:26 pm »
Try it before you say that   ;D ;D
Filmed in Supermarionation

Offline dh42

  • Administrator
  • CNC Jedi
  • *****
  • Posts: 7410
    • View Profile
    • Cambam V1.0 French Doc
Re: Export to SVG - new plugin
« Reply #4 on: October 12, 2020, 21:40:06 pm »
Not sure that I ever have used SVG format on any software since I use a PC .... LOL

++
David

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5263
  • Made in England
    • View Profile
Re: Export to SVG - new plugin
« Reply #5 on: October 12, 2020, 21:42:00 pm »
I've tested it on Inkscape but I'm sure there will be issues with other software and that's what I'd like to hear about.
The plugin has features that apply to CamBam rather than trying to cover all the svg options.
Filmed in Supermarionation

Offline Bubba

  • CNC Jedi
  • *****
  • Posts: 3355
    • View Profile
Re: Export to SVG - new plugin
« Reply #6 on: October 12, 2020, 23:23:56 pm »
I use Inscape often, and this plugin will safe me from jumping thru the hoops when exporting design from CB. In the past I needed the exported dxf format file to open and export again thru ViaCAD because dxf versions were not compatible with Inscape. ;D ;D
My 2¢

Win11, CB(1.0)rc 1(64 bit) Mach3, ESS, G540, 4th Axis, Endurance Laser.

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5263
  • Made in England
    • View Profile
Re: Export to SVG - new plugin
« Reply #7 on: October 13, 2020, 07:24:15 am »
When I first played with this all the graphics exported upside down, the reason being that an SVG image has it's origin TOP LEFT.
I had to multiply all the Y coordinates by -1 to invert them and it means you should draw in the BOTTOM RIGHT quadrant of the CamBam window if exporting to svg.

You will notice that the example cb file attached to my first post has all the objects in that lower right quadrant.


This is not required in latest version, draw anywhere.

« Last Edit: October 15, 2020, 14:01:37 pm by EddyCurrent »
Filmed in Supermarionation

Offline Bubba

  • CNC Jedi
  • *****
  • Posts: 3355
    • View Profile
Re: Export to SVG - new plugin
« Reply #8 on: October 13, 2020, 09:12:40 am »
Hi Eddy,
Just tried your plugin and the conversion works except for one issue. In the converted file (svg) the circle have extra line going across in the lower right section and it should not be there. Did not converted the circle to polyline so maybe it was the cause for this. Opened the svg in Inscape and FreeCAD and in both cases the line is displayed. Samples attached.     
My 2¢

Win11, CB(1.0)rc 1(64 bit) Mach3, ESS, G540, 4th Axis, Endurance Laser.

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5263
  • Made in England
    • View Profile
Re: Export to SVG - new plugin
« Reply #9 on: October 13, 2020, 09:30:19 am »
Bubba,

Thanks for testing.

It's because the polylines are 'Closed' and a 'z' has been added to the end. Unfortunately a closing straight line has been produced as a result.
Use a 'Circle' instead for now until I look into it.
Filmed in Supermarionation

Offline pixelmaker

  • CNC Jedi
  • *****
  • Posts: 1967
    • View Profile
    • pixelmaker
Re: Export to SVG - new plugin
« Reply #10 on: October 13, 2020, 09:50:33 am »
After a search I found the object in Illustrator CC.
After opening it has a diameter of 1.3229 mm.
The line thickness is 0.0353 mm.
The zero point, which is in the center of the object, is aligned at the upper left corner.
No size factor can be set. If I make the object 100mm in CB, it is 35.2778mm in Illustrator.
I can't get rid of the diagonal line by using more nodes.

ralf

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5263
  • Made in England
    • View Profile
Re: Export to SVG - new plugin
« Reply #11 on: October 13, 2020, 11:10:35 am »
Ralf,

Thanks for testing and feedback

1. The rogue line can be fixed by removing the 'z' character but there may be some other logic that allows it sometimes, I'll have to investigate.
2. Clearly there are many things about SVG files that I do not know about.
I've just discovered "ViewBox" for example and this I hope is going to fix the positioning issue.
3. The aim was to export at 1:1 ratio, I still have to look further into that and any differences inches might make
Filmed in Supermarionation

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5263
  • Made in England
    • View Profile
Re: Export to SVG - new plugin
« Reply #12 on: October 13, 2020, 22:05:08 pm »
Version 2.0 attached to first post. (tested with Inkscape)

1. resizes page to exported objects
2. centralises objects on page
3. dimensions of objects imported by Inkscape are the same as those in CamBam
4. paths for Polylines with multiple arcs and lines will now "combine" into one path so that "fill" works correctly. (same as CamBam "Join")
5. the diagonal line in Bubba's sample file is fixed.

If the file in CamBam is in inches and a dimension is 2.5", it will export as 2.5 to Inkscape
at present I don't know how the mm / inches is detected.
« Last Edit: October 13, 2020, 22:10:33 pm by EddyCurrent »
Filmed in Supermarionation

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5263
  • Made in England
    • View Profile
Re: Export to SVG - new plugin
« Reply #13 on: October 14, 2020, 20:21:21 pm »
Version 3.0 attached to first post. (tested with Inkscape and K40 Whisperer)

1. added units to the svg file, both in the "width" and "height" parameters and also "units" ("mm" and "in")
2. Finally got "Namespace" sorted out, K40 would not open the file without that being set correctly.
3. tested with splines attached to polylines attached to arcs multiple times, then used CamBam "join" to see if the closed shape would colour fill okay in Inkscape and K40 Whisperer.
4 As far as I can make out the exported geometry is the same size as in CamBam however Inkscape also includes the stroke width in size.

* This software also opens the CamBam exported svg files now   ;D ; https://sk1project.net/
* Rhino6 also opens the files with correct colours but of course no fill.
* Firefox browser also works

PaintshopPro9 failed to open them  ??? but it also won't open some svg files from Rhino or Inkscape, the software is quite old so maybe works with an old format ?

Small update to v3.1, changed default stroke width for inches system
« Last Edit: October 15, 2020, 05:33:38 am by EddyCurrent »
Filmed in Supermarionation

Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5263
  • Made in England
    • View Profile
Re: Export to SVG - new plugin
« Reply #14 on: October 15, 2020, 15:17:28 pm »
I made a test file for use with K40 Whisperer, a large "Hello World" key fob. (attached)
It uses three coloured layers for laser work, RED - Vector Cut, BLUE - Vector Engrave, BLACK - Raster Engrave

Outside dimensions in CamBam, 132.28143 x 39.80602

Dimensions after being cut on the laser, 131.5 x 39.25

The finished item was slightly undersize and I'm saying it was due to the cutting process where I had the feed speed very low, plus I did not have air assist on.

For me that's a great result and no intermediate Inkscape action required.

Also version 4 attached to first post.

1. rewrote the Classes for svg objects, much happier with the code now.
« Last Edit: October 15, 2020, 15:25:17 pm by EddyCurrent »
Filmed in Supermarionation