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: 2755
Joined: Mon Feb 27, 2012 5:31 pm

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

Post by keithsloan52 »

kwahoo wrote: Tue Sep 21, 2021 9:04 pm
keithsloan52 wrote: Tue Sep 21, 2021 7:54 pm
i.e. Again largest surface in the X-Y plane and negative in the Z direction
Ok, It is indeed in the X-Y local plane of Body, but also in the X-Z global plane according the gizmo in the corner. (planes differ, because the Body is rotated)
This is screenshot with the default cube moved by 50 mm in the Z direction:

Image

So, does the exporter use local (inside the Body) coordinates only? Preserving global coordinates would be very useful for assemblies.
Not for me.
B237F835-BE54-4EF9-A64D-34ED678C14BB.jpeg
B237F835-BE54-4EF9-A64D-34ED678C14BB.jpeg (33.1 KiB) Viewed 11580 times

Code: Select all

OS: macOS 10.15
Word size of FreeCAD: 64-bit
Version: 0.20.25566 (Git)
Build type: Release
Branch: master
Hash: 8c361dd3fc83840a911da950a845eb9f9342a0b6
Python version: 3.9.6
Qt version: 5.12.9
Coin version: 4.0.0
OCC version: 7.5.2
Locale: C/Default (C)
le_top
Posts: 20
Joined: Sat Apr 24, 2021 2:13 pm

Issues with fonts

Post by le_top »

Opening with SCAD shows the text with the correct font.

When opening the file in FreeCAD 0.19, the font used is not the one defined in the file.

When opening using a script (See: script in other post) there are errors:
Traceback (most recent call last):
File "./convert_shape.py", line 91, in <module>
FreeCAD.loadFile(iname)
ImportError: Traceback (most recent call last):
File "<string>", line 2, in <module>
File "C:\Program Files\FreeCAD 0.19\Mod\OpenSCAD\importCSG.py", line 146, in insert
processcsg(tmpfile)
File "C:\Program Files\FreeCAD 0.19\Mod\OpenSCAD\importCSG.py", line 177, in processcsg
result = parser.parse(f.read())
File "C:\Program Files\FreeCAD 0.19\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.19\bin\lib\site-packages\ply\yacc.py", line 1120, in parseopt_notrack
p.callable(pslice)
File "C:\Program Files\FreeCAD 0.19\Mod\OpenSCAD\importCSG.py", line 1167, in p_text_action
p[0] = [processTextCmd(t)]
File "C:\Program Files\FreeCAD 0.19\Mod\OpenSCAD\importCSG.py", line 813, in processTextCmd
face = importDXFface(tmpfilename,None,None)
File "C:\Program Files\FreeCAD 0.19\Mod\OpenSCAD\OpenSCAD2Dgeom.py", line 480, in importDXFface
import FreeCAD,importDXF
File "C:\Program Files\FreeCAD 0.19\Mod\Draft\importDXF.py", line 58, in <module>
from Draft import _Dimension, _ViewProviderDimension
<class 'ImportError'>: cannot import name '_ViewProviderDimension' from 'Draft' (C:\Program Files\FreeCAD
0.19\Mod\Draft\Draft.py)
Instructions:
- Unzip the electra.zip file (contains font);
- put nofont.scad in same directory as elektra.ttf
- Open with openscad: observe font is matrix like;
- Open with freecad: observe font is not matrix like;
- Open with conversion script (referred to above): observe read failure.
Attachments
elektra.zip
(16.86 KiB) Downloaded 44 times
nofont.scad
(197 Bytes) Downloaded 47 times
User avatar
chennes
Veteran
Posts: 3876
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 »

Thanks for the report, @le_top -- have you tested in in a 0.20 weekly build, or with @keithsloan52's external OpenSCAD parser mod? I haven't yet had a chance to test on mine, but we've made significant improvements to the OpenSCAD interoperability during the 0.20 build cycle. Things that load external files are probably still finicky, though, I need to do some more work on copying the required files to the temp directory.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
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 »

It tested it on the current build ( FreeCAD_0.20.26155_Win-LPv12.5.4_vc17.x-x86-64.7z ) as I installed it to check on what I shared here. But I think that subject is more related to step export than reading scad files.

I can see that there's been progress ;-) .
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 an additional case.

These CSG files were exported from openscad after reading an scad script.
Reading the SCAD script or the CSG script in the FreeCAD gui give the same (apparent) results (version info below).
Both work fine in openscad.

The first file is an LCD 16x02 model with text added on top of it.
WH1602B3-SLL-CWV#_text.csg
(24.15 KiB) Downloaded 41 times
elektra.zip
(16.86 KiB) Downloaded 36 times
The second file is the same model without the text.
WH1602B3-SLL-CWV#_notext.csg
(23.18 KiB) Downloaded 40 times
The first file with text read in Freecad breaks part of the body, but shows the text (in the standard font, not the specified one). It spends a log of time to import but writes a pretty important number of messages like this in the console : "11:49:34 0"

The second file without text read in FreeCAD shows the body as expected (but no text of course).

The strange thing is that having the text is breaking the body, the other thing was already presented in a previous, simpler case: the specified font is not used.

EDIT: OpenSCAD does not use the expected font when reading the exported csg file (it does when using the scad file). There is no "use <elektra.ttf>;" equivalent in the csg file.

I hope this helps.


OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.20.26155 (Git)
Build type: Release
Branch: master
Hash: 0926a4148bcff11249fd4f56bc30256102ffe105
Python version: 3.8.6+
Qt version: 5.15.2
Coin version: 4.0.1
OCC version: 7.5.0
Locale: French/France (fr_FR)
keithsloan52
Veteran
Posts: 2755
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: Sun Nov 21, 2021 10:54 am
EDIT: OpenSCAD does not use the expected font when reading the exported csg file (it does when using the scad file). There is no "use <elektra.ttf>;" equivalent in the csg file.

I hope this helps.
FreeCAD imports SCAD files by first getting OpenSCAD to create a CSG file. A CSG is still a script language and has to be parsed rather than a read format. If OpenSCAD does not create a CSG that on import looks the same as the SCAD file, then there is not a lot the FreeCAD importer can do about it. Report as a bug to OpenSCAD maybe.

Also the way text is implemented is that a DXF version is created and that is imported, you might want to check if changing the DXF importer options change anything, like try legacy importer or not if that is what is already set
keithsloan52
Veteran
Posts: 2755
Joined: Mon Feb 27, 2012 5:31 pm

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

Post by keithsloan52 »

As the use font is not passed to the CSG file, you might try installing the Font into Windows, rather than telling OpenSCAD to use a Font in a referenced file.
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 understand that FreeCad relies on other code to convert to CSG and that when the "use" is missing, FreeCad is not the tool responsible for that.

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.

With regards to the font issue:
Installing the font under windows does not help - even OpenSCAD requires the "use <electra.ttf;" statement to be present to use the specific font.



Here is a third case (the two previous cases I provided are still valid for their main purpose):

No font explicitally specified, just writing a fine layer of text in gold, so not potentially introducing an issue because of a bad font.

Code: Select all

// SCAD file contents
gold="#ffd700";
$fn = 32;
color(gold)
  linear_extrude(0.001) {
    text("Hello FreeCAD!", size=5.55*0.95);
  };
Executing that takes a long time on my high end machine, the console shows:

Code: Select all

4:19:30  opening C:\Users\User\AppData\Local\Temp\fc-28472-995712-000002.dxf...
14:19:30  This function will be deprecated. Please use 'make_layer'.
14:19:30  ----------------
14:19:30  Layer
14:19:30  name: 0
14:19:30  line_color: (0.0, 0.0, 0.0)
14:19:30  line_width: 2.0
14:19:30  draw_style: Solid
14:19:30  transparency: 0
14:19:30  drawing 542 lines...
14:19:30  skipping texts...
14:19:30  skipping dimensions...
14:19:30  skipping points...
14:19:30  skipping leaders...
14:19:30  skipping hatches...
14:19:30  skipping *blocks...
14:19:30  done processing
14:19:30  successfully imported C:\Users\mdeweerd\AppData\Local\Temp\fc-28472-995712-000002.dxf
14:19:30  Scale: [1.0, 1.0]
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

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.
keithsloan52
Veteran
Posts: 2755
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
With regards to the font issue:
Installing the font under windows does not help - even OpenSCAD requires the "use <electra.ttf;" statement to be present to use the specific font.

Code: Select all

// SCAD file contents
gold="#ffd700";
$fn = 32;
color(gold)
  linear_extrude(0.001) {
    text("Hello FreeCAD!", size=5.55*0.95);
  };
My reading of the OpenSCAD manual https://en.wikibooks.org/wiki/OpenSCAD_ ... guage#Text
indicates that you can specify the font to use an installed font, use is for specific font files.
i.e. use allows one to use a font that is not installed but its definition is in a referenced file
In addition to the installed fonts, it's possible to add project specific font files. Supported font file formats are TrueType Fonts (*.ttf) and OpenType Fonts (*.otf). The files need to be registered with use<>.

use <ttf/paratype-serif/PTF55F.ttf>
keithsloan52
Veteran
Posts: 2755
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 Executing that takes a long time on my high end machine, the console shows:

Code: Select all

4:19:30  opening C:\Users\User\AppData\Local\Temp\fc-28472-995712-000002.dxf...
14:19:30  This function will be deprecated. Please use 'make_layer'.
To my knowledge FreeCAD does not have any facilities for reading font definitions, so what you have to realise is that the importer is having to resort to getting OpenSCAD to create a DXF file of the output text and then importing that, it is never going to be quick.

The function will be depreciated is coming from importDXF.py perhaps @chennes would look at function importDXFface in OpenSCAD2Dgeom.py to change it to use make_layer but I would not expect to see a big change in run time as I think the slowness is down to having to treat the text as a DXF file.
Post Reply