I made a sketch in solidworks which I saved as a DXF because DXF is what my Laser cutter accepts
As well as loading it in my laser I sometimes improt it into inkscape to set the colours of the lines to Red and Blue
My laser knows to engrave blue lines and cut red ones
Every thing is fine unless I use a bezier curve in the sketch and then if I load it into the laser or into inkscape , it adds
an extra line , a straight line between the two ends of the bezier curve I cant of course leave this line in as the laser would treat it as a cut line . In inkscape I can select the whole drawing and do ungroup which seperates all the lines but sadly
it wont ungroup the extra line from the bezier curve so I cant delete it , Does anyone know a way around this ?
I will try to add a picture pointing to the unwanted lines that solidworks seems to like adding
I indicated the nuisance lines with red pointers
SolidworksImport/export
Can you share a DXF with this issue?
When you say "bezier" I assume you mean spline curve (using Solidworks terminology)?
I did a little experiment, and I am not getting the same result. However, that could be because I am using a different version of Solidworks than you are (I am using SW 2018 SP5), or it might have to do with settings (see settings I have set below).
Created DXF:
Re-imported DXF into Solidworks:
Settings for export of DXF:
Have you tried to Export as Polylines instead of splines (circled area in the above picture)?
Hi Jim
Yes I wrote last night to Scorch ( he wrote the laser program) and told him the way you fixed netscape
and it seems he has used the same cure in K40 On line 701 of dxf.py
Once again thanks everyone for your input
Don
Do you have the latest version (0.33) of K40? I just looked at the source code and the problem has been fixed.
Thats superb thanks Jim.
I dont have a python editor so used word pad and was a little confused at first,
As I doesnt show line numbers I told it to search for "closed" which it did but the line already had the & 1 at the end
I told it to find the next instance of closed and it found the correct lines which I changed , I can now load DXFs into inkscape
and it no longer adds the extra lines . I tried saving it back out as both DXF and SVG files and both load into my laser driver program again without the extra lines , Job Done
If I could find out how to make the same changes in my laser program K40 Whisperer I could also load the DXFs straight into that but I had a look at the program hoping to find the same dxf_input.py but no such luck
So I will have to load them into Inkscape and re save them first
Don
That's great!
I just realized that Inkscape ships the importer as a Python extension. You can simply edit it to correct the problem. The file is in the share\extensions subdirectory of the Inkscape installation. Make a backup copy of the dxf_input.py file and then edit the original. The changes that need to be made are in the export_LWPOLYLINE(): function. It starts at line 146. At line 153 will be this:
Change it to this:
Just insert & 1 before the colon.
Make the exact same change at line 185. Save it and now splines should come in to Inkscape correctly.
Ugh, I was afraid that might be the case
But maybe its still an easy fix if find/replace using a larger, more specific string.
I wouldn't use a simple Find & Replace. I just opened a random DXF on my machine and there were 25 instances of '128', none of which were related to polylines.
Hi Jim
Do you think Using Find and Replace All occurrences in a text editor would probably work as a fast method to correct this, unless "128" shows up in places where it should not be replaced?
I've just discovered that SOLIDWORKS ignores the polylines settings when exporting sketches. All splines are exported as polylines, no matter what. For a simple sketch with a single spline in it like this:
the DXF has the following in the ENTITIES section:
=========================================
ENTITIES
0
LWPOLYLINE
5
73
330
1F
100
AcDbEntity
8
0
6
Continuous
62
7
100
AcDbPolyline
90
57
70
128
43
0.0
...
...
...
<226 pair of coordinates>
...
...
...
0
ENDSEC
0
SECTION
====================================================
Note that the spline is defined using the LWPOLYLINE entity. The DXF Specification for LWPOLYLINE looks like this:
Group Code 70 is the important one here. SOLIDWORKS sets this value to 128. If you edit the DXF file change it to 0, the spline imported into Inkscape will be open instead of closed:
Inkscape is really at fault here. In their import code they have this:
===========================
===========================
The line with the #closed path comment is checking to see if the polyline is closed. If so, Inkscape adds a new vertex with the same coordinates as the first vertex effectively closing the polyline. The problem is that the check is doing a binary comparison of something with three possible values. The check above is basically saying:
"If the value of group 70 isn't zero, the path is closed."
So, when SOLIDWORKS sets the value to 128, it isn't zero, and is therefore considered closed by Inkscape.
The latest Inkscape codebase includes a fix for this. the bold line above is replaced by this:
This line is saying:
"If the value of group 70 is 1, the path is closed."
So, the value of 128 doesn't cause a false positive.
Unfortunately, the latest downloadable version for Windows doesn't include the fix.
Thank you for trying to help Chris
Don
Hi Don,
I have been able to reproduce this so I don't need to see your file.
I though the enabling the endpoint merging in the SolidWorks export would help, but it appears to have no effect in relation to this issue, despite changing the value to 0.001, 0.01, 0.1
I also tried chaining the curves and using the make path in the SolidWorks sketch but that no effect either.
It would seem your work around is best as there appears no way to correct this in Inkscape.
try again
Hi Chris
You are probably right about there being a way to tell inkscape not to treat it as a closed shape ,
I just wish I knew what that way was .
I tried removing fill but that made no difference . I shall try to add 3 files
the first is what I see as I am about to save it as a DXF
The next is what I see when I open that saved file in inkscape or my laser program
Now hopefully I can attach the DXF file as saved by SW
Hmmm I tried to send the post
when I attached the DXF it warned max size is 25Mb my file is 42.4Kb and it says its too large
Don
Hi Chris
You are probably right about there being a way to tell inkscape not to treat it as a closed shape ,
I just wish I knew what that way was .
I tried removing fill but that made no difference . I shall try to add 3 files
the first is what I see as I am about to save it as a DXF
The next is what I see when I open that saved file in inkscape or my laser program
Now hopefully I can attach the DXF file as saved by SW
I think that worked ,
Don
Hi Chris
You are probably right about there being a way to tell inkscape not to treat it as a closed shape ,
I just wish I knew what that way was .
I tried removing fill but that made no difference . I shall try to add 3 files
the first is what I see as I am about to save it as a DXF
The next is what I see when I open that saved file in inkscape or my laser program
Now hopefully I can attach the DXF file as saved by SW
I think that worked ,
Don
Hi Chris
You are probably right about there being a way to tell inkscape not to treat it as a closed shape ,
I just wish I knew what that way was .
I tried removing fill but that made no difference . I shall try to add 3 files
the first is what I see as I am about to save it as a DXF
The next is what I see when I open that saved file in inkscape or my laser program
Now hopefully I can attach the DXF file as saved by SW
I think that worked ,
Don
Hi Chris
You are probably right about there being a way to tell inkscape not to treat it as a closed shape ,
I just wish I knew what that way was .
I tried removing fill but that made no difference . I shall try to add 3 files
the first is what I see as I am about to save it as a DXF
The next is what I see when I open that saved file in inkscape or my laser program
Now hopefully I can attach the DXF file as saved by SW
I think that worked ,
Don
Inkscape appears to be treating the curve as a closed shape and is joining the endpoints automatically.
There is probably a way to turn this off in Inkscape.
If you remove the fill, does the line go away?
EDIT
It is possible some operations in Inkscape may have generated that line as well. In that case the fill issue is probably not relevant.
Can you attache the original DXF file you saved from SolidWorks?
Hi Jim , I just set my settings to poly lines and saved as a DXF but when I open in inkscape or whisperer it still has the extra lines
When you re-opened it in SW did it change the curves into polylines? That's what happens for me, which might explain why your second export can be imported without problems. It's isn't a curve anymore, its a series of lines. If this is OK, you can simply change the SW export options to export curves as polylines, and you can avoid the double exporting:
Hi Jim , thanks for replying , I shall give that a try, , I have found one work around which I have posted as a reply to Dan in the post above yours
Don
Hi Dan
Thanks for replying . Like you I can also open it back up in solidworks and like you it opens fine , Its only when I try to
open it in Inkscape or " K40 Whisperer" ( my laser driver program) that I get the bad result . I have found a work around but dont know why it works , What I did was save it as a DXF from SW then reload the DXF into SW as a 2D sketch , then resave it as a DXF again and for some reason it then opens fine in both of the programs that played up before.
Why It works I have no idea but it does work
Don
In Inkscape, you can split the Path to remove the unwanted segment:
Before:
After:
To do this, select the node at the end of the unwanted segment and use the 'Break Path At Selected Nodes tool:
Do the same at the other end of the segment, and then you can delete it.