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!
vk7krj
Posts: 4
Joined: Fri Apr 22, 2022 9:40 pm

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

Post by vk7krj »

I have a problem loading an scad file into freecad and this appears to be the correct place to ask about it.

It appears freecad is not using the difference command and the object is shown as just a series of solid cubes and disks when it should be a spoked flywheel. I have tried to put a couple of jpg's in to show, but can't figure out how to put them in this message so I have pasted the openscad file in at the bottom..

My freecad info is-

OS: Windows 10 Version 2009
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.24267 +148 (Git)
Build type: Release
Branch: Branch_0.19.4
Hash: 476ecf091941bead59b14e44afa6064d5a66afa3
Python version: 3.8.6+
Qt version: 5.15.2
Coin version: 4.0.1
OCC version: 7.5.3
Locale: English/Australia (en_AU)

and openscad is-
OpenSCAD version 2021.01

The openscad file:-

Code: Select all

$fn = 128;

//Set up the dimensions
hubdiameter = 25;
shaftdiameter = 12;
wheeldiameter = 100;
hubthickness = 10;
rimthickness = 20;
spokethickness = 8;
numberofspokes = 5;
//Set draught so mold can be
//removed from sand
draught = 2;
//Don't change the next 3 lines
wheelrimthickness = (wheeldiameter - rimthickness);
spokelength = (wheeldiameter-hubdiameter+5);
rotation = 360/(numberofspokes);
//Set the ovalness of the spokes (1=round,
//  less than one is oval in one plane,
//  more than one is oval in the other plane
ovality = 1.5;
// Make half a wheel for casting
difference(){
//Wheel rim
difference(){
  difference(){
    color ("violet")
    cylinder(h=12,d1=wheeldiameter,d2=wheeldiameter-draught,center=true);
//Two 3mm holes so the wheel halves
//can be correctly registered in the mold
    translate([0, wheeldiameter/2-5, -5])
    cylinder(h=10,d=3);
    translate([0, -(wheeldiameter/2-5), -5])
    cylinder(h=10,d=3);
  }   
//Cut out the annulus and make the spokes
difference(){
    color ("blue")
    cylinder(h=13,d1=wheelrimthickness-draught,d2=wheelrimthickness,center=true);
   for (i=[1:numberofspokes]){     
    rotate([90,0,rotation * i])     
    scale([ovality,1,1])
    color ("red")
//comment out cylinder line and uncomment 
//cube line for rectangular spokes
    cylinder(h=spokelength, d=spokethickness, center=false);}
//    cube([65,spokethickness,5],center=true);}
  }
  color ("lightblue");
cylinder(h=12,d=15,center=true);
}

//This cube differences out half the wheel
//to make a mold for casting
translate ([0, 0, -10])
cube ([wheeldiameter+10, wheeldiameter+10, 20],center = true); 
}
//Draw half a hub center
difference(){
  color ("green")
  translate ([0, 0, 2.5])
  cylinder(h=5,d1=hubdiameter,d2=hubdiameter-draught,center=true);
  color ("navy")
  cylinder(h=11,d1=shaftdiameter,d2=shaftdiameter-draught, center=true);
}
Last edited by vk7krj on Sat Apr 23, 2022 1:27 am, edited 1 time in total.
chrisb
Veteran
Posts: 53930
Joined: Tue Mar 17, 2015 9:14 am

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

Post by chrisb »

Hi and welcome to the forum!

Please retry with a current 0.20 version.

Please edit your post and put the code in code tags using the button </>. That makes the post easier to read.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
vk7krj
Posts: 4
Joined: Fri Apr 22, 2022 9:40 pm

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

Post by vk7krj »

Thanks Chrisb, I have now installed the current 0.20 version, it made it a little better but still not correct. If I open the stl of the flywheel, that displays correctly but the scad file is still not differencing properly. I have put in jpegs of the two files as shown in freecad- the first one is the scad file, the second is the stl created from it in openscad.

Image
Image
Attachments
flywheel scad.JPG
flywheel scad.JPG (39.06 KiB) Viewed 2553 times
flywheel stl.JPG
flywheel stl.JPG (29.84 KiB) Viewed 2553 times
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

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

Post by Kunda1 »

x-posting another issue that was opened before posting to the thread: issue #6810
When opening a OpenSCAD file I get the following error: (see files attached + error below)
Instead of opening the part with all subsections, it just makes a single cube.

Code: Select all

16:27:03  Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Program Files\FreeCAD 0.19\Mod\OpenSCAD\importCSG.py", line 119, in open
    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 854, in p_multmatrix_action
    parentcolor=p[6][0].ViewObject.ShapeColor
<class 'IndexError'>: list index out of range
Tested on

Code: Select all

OS: macOS 10.16
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.24366 (Git)
Build type: Release
Python version: 3.9.7
Qt version: 5.12.9
Coin version: 4.0.0
OCC version: 7.5.3
Locale: C/Default (C)
I also tried versions 0.20 dev, 0.19.4, and 0.19.1 on Windows 10.
thorlabs_optomech.scad
(161.51 KiB) Downloaded 23 times
baseplate_test1.scad
(1.01 KiB) Downloaded 23 times
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
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 »

I was not able to reproduce the problem reported in the ticket -- FreeCAD loaded the file fine for me using

Code: Select all

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.20.28764 (Git)
Build type: Debug
Branch: master
Hash: 4f9eb9ebcea67bff2a46cfc97ae125472f115a11
Python 3.8.6+, Qt 5.15.2, Coin 4.0.1, OCC 7.5.3
Locale: English/United States (en_US)
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

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

Post by Kunda1 »

chennes wrote: Fri Apr 29, 2022 1:51 pm I was not able to reproduce the problem reported in the ticket -- FreeCAD loaded the file fine for me using
@chennes which ticket?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
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 »

#6810
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
unphased
Posts: 4
Joined: Tue May 17, 2022 5:45 am

Cannot open openscad model

Post by unphased »

Here is the error I'm getting.

Code: Select all

WARNING: Token 'DOT' defined, but not used
WARNING: Token 'WORD' defined, but not used
WARNING: There are 2 unused tokens
WARNING: Couldn't create 'parsetab'. [Errno 13] Permission denied: '/usr/share/freecad/Mod/OpenSCAD/parsetab.py'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/share/freecad/Mod/OpenSCAD/importCSG.py", line 84, in open
    processcsg(tmpfile)
  File "/usr/share/freecad/Mod/OpenSCAD/importCSG.py", line 142, in processcsg
    result = parser.parse(f.read())
  File "/usr/lib/python3/dist-packages/ply/yacc.py", line 333, in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
  File "/usr/lib/python3/dist-packages/ply/yacc.py", line 1120, in parseopt_notrack
    p.callable(pslice)
  File "/usr/share/freecad/Mod/OpenSCAD/importCSG.py", line 391, in p_offset_action
    if subobj[0].Shape.Volume == 0 :
<class 'RuntimeError'>: shape is invalid
How can I find out more about what modifications I should try to make to the scad definition to prevent this problem, or could I do some hack to remove the check?
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Cannot open openscad model

Post by Kunda1 »

Please add the file/code to the original post please, along with your full About info
Edit: @unphased I've merged your thread in to the pre-existing 'Problem OpenSCAD scad & csg files - PLEASE Add them to this thread - Thanks' thread
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
chennes
Veteran
Posts: 3881
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Cannot open openscad model

Post by chennes »

unphased wrote: Tue May 17, 2022 5:50 am

Code: Select all

WARNING: Couldn't create 'parsetab'. [Errno 13] Permission denied: '/usr/share/freecad/Mod/OpenSCAD/parsetab.py'
We fixed this warning a couple of weeks ago -- make sure you're running the latest available dev build, or wait for the release of 0.20 in the coming weeks. Then let's see if the problem persists.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
Post Reply