Problem OpenSCAD scad & csg files - PLEASE Add them to this thread - Thanks

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Problem OpenSCAD scad & csg files - PLEASE Add them to this thread - Thanks

Post by keithsloan52 »

le_top wrote: Wed Nov 24, 2021 1:26 pm
};
[/code]

Executing that takes a long time on my high end machine, the console shows:

14:19:30 End processing CSG file
14:19:30 0
14:19:30 0
14:19:30 0
14:19:30 0
14:19:30 0
14:19:30 0
14:19:30 0
14:19:30 0
14:19:30 0
14:19:30 0
14:19:30 0
14:19:30 0
14:19:30 0
14:19:30 0
14:19:30 0
14:19:30 0
14:19:30 0
14:19:30 0
14:19:30 0
14:19:30 0
[/code]


So that's 20 times "14:19:30 0", as many as there are contours apparently, the use of a deprecated function and very slow execution just for writing 11 characters requiring effectively 20 contours.
Given the output is coming after the End Processing CSG file
and its 20 contours that the print is in the standard FreeCAD importDXF.py code maybe make_layer would help the DXF importer is not something I know a lot about.
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Problem OpenSCAD scad & csg files - PLEASE Add them to this thread - Thanks

Post by keithsloan52 »

le_top wrote: Wed Nov 24, 2021 1:26 pm
However the last test case was not about that in principle, but abou the fact that adding text makes part of the model disappear.
The CSG files demonstrates that (the difference is only the "text"): the file without "text" shows all parts/bodies - the file with text makes the LCD display itself disappear, only the "PCB" itself and the (added) text remain.
Loading the version with text on my machine gives the following error which would explain why you are not seeing
the other parts etc

Code: Select all

6:40:41  Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Applications/FreeCAD_0.19.app/Contents/Resources/Mod/OpenSCAD/importCSG.py", line 126, in open
    processcsg(filename)
  File "/Applications/FreeCAD_0.19.app/Contents/Resources/Mod/OpenSCAD/importCSG.py", line 177, in processcsg
    result = parser.parse(f.read())
  File "/Applications/FreeCAD_0.19.app/Contents/Resources/lib/python3.8/site-packages/ply/yacc.py", line 333, in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
  File "/Applications/FreeCAD_0.19.app/Contents/Resources/lib/python3.8/site-packages/ply/yacc.py", line 1120, in parseopt_notrack
    p.callable(pslice)
  File "/Applications/FreeCAD_0.19.app/Contents/Resources/Mod/OpenSCAD/importCSG.py", line 1167, in p_text_action
    p[0] = [processTextCmd(t)]
  File "/Applications/FreeCAD_0.19.app/Contents/Resources/Mod/OpenSCAD/importCSG.py", line 813, in processTextCmd
    face = importDXFface(tmpfilename,None,None)
  File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/OpenSCAD_Alt_Import/OpenSCAD2Dgeom.py", line 497, in importDXFface
    faces = edgestofaces(edges)
  File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/OpenSCAD_Alt_Import/OpenSCAD2Dgeom.py", line 410, in edgestofaces
    return Overlappingfaces(facel).makeshape()
  File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/OpenSCAD_Alt_Import/OpenSCAD2Dgeom.py", line 229, in makeshape
    return fusefaces(faces)
  File "/Users/keithsloan/Library/Preferences/FreeCAD/Mod/OpenSCAD_Alt_Import/OpenSCAD2Dgeom.py", line 366, in fusefaces
    return reduce(lambda p1,p2: p1.fuse(p2),faces)
<class 'TypeError'>: reduce() of empty sequence with no initial value
Maybe @chennes can debug/fix the error
le_top
Posts: 20
Joined: Sat Apr 24, 2021 2:13 pm

Re: Problem OpenSCAD scad & csg files - PLEASE Add them to this thread - Thanks

Post by le_top »

- Ok with regards to the speed - mainly listing my observations. If it's "slow" but works, that's ok.
- My understanding of "use" is the same. Fonts are listed in 'Help>Font List' in OpenSCAD.
Note: Elektra was installed using Windows' install function, and when redoing the operation it said "already installed"
Following some tests:
- Elektra was listed when an .scad file with 'use <Elektra.ttf>' in it was opened;
- Adding 'use <Electra.ttf>;' interactively or removing it interactively does not have any effect (it has to be loaded initially, when it is loaded it is found);
- As all other fonts were in 'C:\Windows\Fonts' I moved 'elektra.ttf' there. Miracle: OpenSCAD now determine that the font is installed - so to OpenSCAD, 'Installed' means that it has to be in the predetermined location.
Other "miracle": opening the SCAD file in FreeCAD, now also finds the font! (Still slow, but works!).
- 3rd "miracle": reading the SCAD file with text no longer makes the LCD body disappear (interactively, the text is visible in the correct font, from a script using FreeCAD Gui I still have issues that I'am investigating). If haven't tested the CSG I provided, but you confirm an execution issue (when not "installing" the font).
le_top
Posts: 20
Joined: Sat Apr 24, 2021 2:13 pm

Re: Problem OpenSCAD scad & csg files - PLEASE Add them to this thread - Thanks

Post by le_top »

Here is another case.

7seg.zip
(3.24 KiB) Downloaded 57 times
On OpenSCAD, there is just a warning, on FreeCAD 0.20 it fails.

OpenSCAD: "WARNING: Unsupported DXF Entity 'SPLINE' (18) in "7seg7mm.dxf""

FreeCAD 0.20:

Code: Select all

Traceback (most recent call last):
  File "<string>", line 2, in <module>
  File "C:\Program Files\FreeCAD 0.20\Mod\OpenSCAD\importCSG.py", line 149, in insert
    processcsg(tmpfile)
  File "C:\Program Files\FreeCAD 0.20\Mod\OpenSCAD\importCSG.py", line 180, in processcsg
    result = parser.parse(f.read())
  File "C:\Program Files\FreeCAD 0.20\bin\lib\site-packages\ply\yacc.py", line 333, in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
  File "C:\Program Files\FreeCAD 0.20\bin\lib\site-packages\ply\yacc.py", line 1120, in parseopt_notrack
    p.callable(pslice)
  File "C:\Program Files\FreeCAD 0.20\Mod\OpenSCAD\importCSG.py", line 801, in p_import_file1
    p[0] = [process_import_file(filen,ext,p[3]['layer'])]
  File "C:\Program Files\FreeCAD 0.20\Mod\OpenSCAD\importCSG.py", line 819, in process_import_file
    obj=processDXF(fname,layer)
  File "C:\Program Files\FreeCAD 0.20\Mod\OpenSCAD\importCSG.py", line 882, in processDXF
    face = importDXFface(filename,layer,doc)
  File "C:\Program Files\FreeCAD 0.20\Mod\OpenSCAD\OpenSCAD2Dgeom.py", line 497, in importDXFface
    faces = edgestofaces(edges)
  File "C:\Program Files\FreeCAD 0.20\Mod\OpenSCAD\OpenSCAD2Dgeom.py", line 410, in edgestofaces
    return Overlappingfaces(facel).makeshape()
  File "C:\Program Files\FreeCAD 0.20\Mod\OpenSCAD\OpenSCAD2Dgeom.py", line 229, in makeshape
    return fusefaces(faces)
  File "C:\Program Files\FreeCAD 0.20\Mod\OpenSCAD\OpenSCAD2Dgeom.py", line 366, in fusefaces
    return reduce(lambda p1,p2: p1.fuse(p2),faces)
<class 'TypeError'>: reduce() of empty sequence with no initial value
Traceback (most recent call last):
  File "./convert_shape.py", line 143, in <module>
    FreeCAD.loadFile(iname)
TypeError: Traceback (most recent call last):
  File "<string>", line 2, in <module>
  File "C:\Program Files\FreeCAD 0.20\Mod\OpenSCAD\importCSG.py", line 149, in insert
    processcsg(tmpfile)
  File "C:\Program Files\FreeCAD 0.20\Mod\OpenSCAD\importCSG.py", line 180, in processcsg
    result = parser.parse(f.read())
  File "C:\Program Files\FreeCAD 0.20\bin\lib\site-packages\ply\yacc.py", line 333, in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
  File "C:\Program Files\FreeCAD 0.20\bin\lib\site-packages\ply\yacc.py", line 1120, in parseopt_notrack
    p.callable(pslice)
  File "C:\Program Files\FreeCAD 0.20\Mod\OpenSCAD\importCSG.py", line 801, in p_import_file1
    p[0] = [process_import_file(filen,ext,p[3]['layer'])]
  File "C:\Program Files\FreeCAD 0.20\Mod\OpenSCAD\importCSG.py", line 819, in process_import_file
    obj=processDXF(fname,layer)
  File "C:\Program Files\FreeCAD 0.20\Mod\OpenSCAD\importCSG.py", line 882, in processDXF
    face = importDXFface(filename,layer,doc)
  File "C:\Program Files\FreeCAD 0.20\Mod\OpenSCAD\OpenSCAD2Dgeom.py", line 497, in importDXFface
    faces = edgestofaces(edges)
  File "C:\Program Files\FreeCAD 0.20\Mod\OpenSCAD\OpenSCAD2Dgeom.py", line 410, in edgestofaces
    return Overlappingfaces(facel).makeshape()
  File "C:\Program Files\FreeCAD 0.20\Mod\OpenSCAD\OpenSCAD2Dgeom.py", line 229, in makeshape
    return fusefaces(faces)
  File "C:\Program Files\FreeCAD 0.20\Mod\OpenSCAD\OpenSCAD2Dgeom.py", line 366, in fusefaces
    return reduce(lambda p1,p2: p1.fuse(p2),faces)
<class 'TypeError'>: reduce() of empty sequence with no initial value
le_top
Posts: 20
Joined: Sat Apr 24, 2021 2:13 pm

Re: Problem OpenSCAD scad & csg files - PLEASE Add them to this thread - Thanks

Post by le_top »

Yet another case where adding "scale(10)" to the openscad script avoids the following error in freecad 0.20:
01:30:06 Traceback (most recent call last):
File "C:\Program Files\FreeCAD 0.20\Mod\OpenSCAD\OpenSCADFeatures.py", line 406, in execute
self.createGeometry(fp)
File "C:\Program Files\FreeCAD 0.20\Mod\OpenSCAD\OpenSCADFeatures.py", line 449, in createGeometry
faces.extend(pipe_shell.shape().Faces)
<class 'Part.OCCError'>: BRep_API: command not done
Test case:
AddScaleToFix.zip
(9.08 KiB) Downloaded 50 times
Uncommenting "scale(10)" avoids the error.

Code: Select all

translate([1,1,1])
     color("#f00")
       linear_extrude(0.001) {
         //scale(10) // Adding this line fixes the issue
           import("logo.dxf");
       };

So my workaround is to scale(10), do the extrusion and add scale(0.1) before the translation.
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Problem OpenSCAD scad & csg files - PLEASE Add them to this thread - Thanks

Post by keithsloan52 »

le_top wrote: Tue Dec 14, 2021 11:07 pm Here is another case.


7seg.zip

On OpenSCAD, there is just a warning, on FreeCAD 0.20 it fails.

OpenSCAD: "WARNING: Unsupported DXF Entity 'SPLINE' (18) in "7seg7mm.dxf""
Thanks for reporting have pm'ed Chris @chennes

I think this maybe down to the fact that the DXF importer does not supports Splines
keithsloan52
Veteran
Posts: 2756
Joined: Mon Feb 27, 2012 5:31 pm

Re: Problem OpenSCAD scad & csg files - PLEASE Add them to this thread - Thanks

Post by keithsloan52 »

le_top wrote: Wed Dec 15, 2021 12:33 am Yet another case where adding "scale(10)" to the openscad script avoids the following error in freecad 0.20:
01:30:06 Traceback (most recent call last):
File "C:\Program Files\FreeCAD 0.20\Mod\OpenSCAD\OpenSCADFeatures.py", line 406, in execute
self.createGeometry(fp)
File "C:\Program Files\FreeCAD 0.20\Mod\OpenSCAD\OpenSCADFeatures.py", line 449, in createGeometry
faces.extend(pipe_shell.shape().Faces)
<class 'Part.OCCError'>: BRep_API: command not done
Test case:
AddScaleToFix.zip

Uncommenting "scale(10)" avoids the error.

Code: Select all

translate([1,1,1])
     color("#f00")
       linear_extrude(0.001) {
         //scale(10) // Adding this line fixes the issue
           import("logo.dxf");
       };

So my workaround is to scale(10), do the extrusion and add scale(0.1) before the translation.
Seems to be a problem with any linear extrude < 1.0
le_top
Posts: 20
Joined: Sat Apr 24, 2021 2:13 pm

Re: Problem OpenSCAD scad & csg files - PLEASE Add them to this thread - Thanks

Post by le_top »

I have linear_extrudes of 0.001 that work on a custom font (after installing the font in the location now documented on the Wiki). So while it may be related to a linear_extrude, not all linear_extrudes fail, but maybe they all fail with the items provided in this example.
lguillau
Posts: 1
Joined: Fri Jan 07, 2022 2:48 pm

Re: Problem OpenSCAD scad & csg files - PLEASE Add them to this thread - Thanks

Post by lguillau »

Hello, I've identified a possible bug in the openscad csg file import feature in FreeCAD (0.19, build 24267). I hope this is the correct place to post this message. If not, tell me.
I've quickly designed a staircase in openscad and I've exported it as a CSG file.
Image
When I import the CSG file (see attached file LG01.csg), the model does not look the same as what we see in openscad.
Image
Playing with the CSG file, I've realized that removing 2 "group" nodes solved the problem (see attached file Lg01_corrected.csg)
Image
The 2 "group" nodes that I removed where at lines 30 and 154 (I've removed also the 2 corresponding "}" )
Thanks
Laurent
Attachments
Lg01_corrected.csg
(10.89 KiB) Downloaded 28 times
Lg01.csg
(11.16 KiB) Downloaded 31 times
User avatar
chennes
Veteran
Posts: 3881
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Problem OpenSCAD scad & csg files - PLEASE Add them to this thread - Thanks

Post by chennes »

That looks to be a visibility problem: all of the correct pieces are there, but in some cases things that should have been hidden are left visible. It looks to me like it's always happening to linear extrudes, so maybe I can chase it down from that.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
Post Reply