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!
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 »

@malorezzanzo00492 can you provide a test file and also your full About info? TIA
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
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 »

malorezzanzo00492 wrote: Sat Aug 13, 2022 9:48 pm There's a problem with linear_extrude()offset()union(){} and with linear_extrude()offset()union(){}.
In the second case FreeCAD gives this error:
File "...", line ..., in p_offset_action
if subobj.Shape.Volume == 0 :
<class 'RuntimeError'>: shape is invalid
In the first case, instead, it seems to ignore the union() instruction.
Think offset only works on 2d shapes hence the test for Volume == 0 and barf, what 2d shapes are you performing a union on?
i.e Please supply a test file that gives a valid result with native OpenSCAD - Thanks
malorezzanzo00492
Posts: 4
Joined: Sat Aug 13, 2022 9:24 pm

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

Post by malorezzanzo00492 »

@keithsloan52 @Kunda1
This is an example of code falling into the second case:

Code: Select all

linear_extrude(200)offset(delta=-10)
    union(){
        square(100);
        translate([100,0,0])square(100);
    };
In the attachment "unionOpenscad.png" the correct result with openscad, while in the attachment "unionFreecad.png" the wrong result with freecad.

This is an example of code falling into the first case:

Code: Select all

linear_extrude(200)offset(delta=-10)
    difference(){
        square(100);
        translate([50,0,0])square(100);
    };
In the attachment "differenceOpenscad.png" the result with openscad, while in freecad it gives the aforementioned error.

My About info:

Code: Select all

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.20.29177 (Git)
Build type: Release
Branch: releases/FreeCAD-0-20
Hash: 68e337670e227889217652ddac593c93b5e8dc94
Python 3.8.10, Qt 5.15.2, Coin 4.0.1, Vtk 8.2.0, OCC 7.6.2
Locale: Italian/Italy (it_IT)
Attachments
differenceOpencad.png
differenceOpencad.png (2.54 KiB) Viewed 1217 times
unionFreecad.png
unionFreecad.png (3.14 KiB) Viewed 1217 times
unionOpenscad.png
unionOpenscad.png (4.64 KiB) Viewed 1217 times
Last edited by malorezzanzo00492 on Wed Aug 17, 2022 7:14 pm, edited 1 time in total.
malorezzanzo00492
Posts: 4
Joined: Sat Aug 13, 2022 9:24 pm

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

Post by malorezzanzo00492 »

Another problem, maybe correlated is this code with this particular polygon:

Code: Select all

linear_extrude(10)offset(delta=-2)polygon([[0,0],[0,230],[33,230],[33,260],[0,260],[0,500],[500,500],[300,-3],[243,-2],[243,-27],[125,-26],[123,-1]]);
It gives this error:

Code: Select all

<Exception> makeOffset2D: result of offsetting is null!
Recompute failed! Please check report view.
Based on the polygon points, sometimes gives error and sometimes works.

My About info:

Code: Select all

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.20.29177 (Git)
Build type: Release
Branch: releases/FreeCAD-0-20
Hash: 68e337670e227889217652ddac593c93b5e8dc94
Python 3.8.10, Qt 5.15.2, Coin 4.0.1, Vtk 8.2.0, OCC 7.6.2
Locale: Italian/Italy (it_IT)
Last edited by malorezzanzo00492 on Wed Aug 17, 2022 7:14 pm, edited 1 time in total.
malorezzanzo00492
Posts: 4
Joined: Sat Aug 13, 2022 9:24 pm

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

Post by malorezzanzo00492 »

Other 2 problems:

The following code should render the "arcOpenscad" attachment, while it renders the "arcFreecad" one. The problems should be somewhere in the rotate.

Code: Select all

arcElevation = 185;
arcRadius = 52;
arcWid = 10;
arcLen = 150;

rotate([0,90,0]){
    // first arc
    translate([0,0,-arcWid])union(){
        linear_extrude(arcWid)square([arcLen,arcElevation]);
    translate([arcLen/2,arcElevation,0])cylinder(h=arcWid,r=arcLen/2);
};
    // second arc
    translate([0,0,-100])union(){
        linear_extrude(arcWid)square([arcLen,arcElevation]);
        translate([(arcLen)/2,arcElevation,0])cylinder(h=arcWid,r=(arcLen)/2);
    };
};
// central part
    cube([arcLen,100,arcElevation]);
This other piece of code should be a door frame as in the "doorOpenscad" attach, without the circular object at its feet:

Code: Select all

//include <BOSL2/std.scad>


module doorframe (arcElevation,arcHeight,span,frameWidth,frameLength=2,subframeLength=7,height=210){
    
    arcWidth = frameWidth-2;
    arcRadiusInt = (span-6)/2;
    arcRadiusExt = (span+3)/2;
    arcScale = [1,(height-arcElevation)/(span/2),1];
    arcPos = [0,arcElevation,-arcWidth/2];
    
    framePos = [-(span+frameLength*2)/2,0,-frameWidth/2];
    
    subframeWidth = frameWidth + 2;
    subframePos = [-(span+frameLength*2+subframeLength*2)/2,0,-subframeWidth/2];
    
    arcSorroundingPos = [0,arcElevation,-0.5];
    rotate([90,0,0])union(){
    //frame
    translate(framePos)
        difference(){
            cube([span+frameLength*2,height+frameLength,frameWidth]);
            translate([frameLength,0,0])cube([span,height,frameWidth]);
        }
    //subframe
    translate(subframePos)
    difference(){
        cube([span+frameLength*2+subframeLength*2,height+frameLength+subframeLength,subframeWidth]);
        translate([subframeLength,0,0])cube([span+frameLength*2,height+frameLength,subframeWidth]);
    }
    //arc
    translate(arcPos){
        scale(arcScale)
            difference(){
//                pie_slice(ang=180, l=arcWidth, r=arcRadiusExt);
                  cylinder(h=arcWidth, r=arcRadiusExt);
                cylinder(h=arcWidth, r=arcRadiusInt);
                translate([-arcRadiusExt,-arcRadiusExt,0])cube([arcRadiusExt*2,arcRadiusExt,arcWidth]);
            }
    }
    //between arc and frame
    translate(arcSorroundingPos)
        difference(){
            translate([-span/2,0,0])
                cube([span,height-arcElevation,1]);
            scale(arcScale)
            cylinder(h=1,r=arcRadiusInt);
        }
    }
}

doorframe(arcElevation=174,arcHeight=36,span=71,frameWidth=12);
My about info:

Code: Select all

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.20.29177 (Git)
Build type: Release
Branch: releases/FreeCAD-0-20
Hash: 68e337670e227889217652ddac593c93b5e8dc94
Python 3.8.10, Qt 5.15.2, Coin 4.0.1, Vtk 8.2.0, OCC 7.6.2
Locale: Italian/Italy (it_IT)
Attachments
doorFreecad.png
doorFreecad.png (4.75 KiB) Viewed 1179 times
doorOpenscad.png
doorOpenscad.png (3.3 KiB) Viewed 1179 times
arcFreescad.png
arcFreescad.png (7.55 KiB) Viewed 1179 times
arcOpenscad.png
arcOpenscad.png (3.79 KiB) Viewed 1179 times
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 »

Thanks for reporting

@chennes I have created the following test files from details in the this thread
Union_Squares.scad
(118 Bytes) Downloaded 20 times
Difference_Squares.scad
(122 Bytes) Downloaded 21 times
Offset_polygon.scad
(150 Bytes) Downloaded 21 times
Door_Arc.scad
(670 Bytes) Downloaded 19 times
ArcOpen.scad
(1.73 KiB) Downloaded 20 times
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 »

keithsloan52 wrote: Wed Aug 17, 2022 9:36 pm Thanks for reporting

@chennes I have created the following test files from details in the this thread

Union_Squares.scad
Difference_Squares.scad
Offset_polygon.scad
Door_Arc.scad
ArcOpen.scad
I have added a fix to offset action to do a checkObjShape to check and perform recompute of the object if required
to https://github.com/KeithSloan/OpenSCAD_Alt_Import this for me fixes difference.scad

Code: Select all

def p_offset_action(p):
    'offset_action : offset LPAREN keywordargument_list RPAREN OBRACE block_list EBRACE'
    # print('Offset Action')
    # print(len(p))
    # print(f'p6 : {p[6]}')
    if len(p[6]) == 0:
        newobj = placeholder('group',[],'{}')
    elif (len(p[6]) == 1 ): #single object
        subobj = p[6][0]
    else:
        subobj = fuse(p[6],"Offset Union")
    if 'r' in p[3] :
        offset = float(p[3]['r'])
    if 'delta' in p[3] :
        offset = float(p[3]['delta'])
    #print(subobj.Shape)
    #print(dir(subobj.Shape))
    #print(subobj.Shape.ShapeType)
    checkObjShape(subobj)
I did not check before the fix but I am not seeing a problem with ArcOpen.

With Offset_polygon the supplied offset is a negative number which causes errors

Code: Select all

23:25:33  <Exception> makeOffset2D: result of offsetting is null!
23:25:33  Recompute failed! Please check report view.
23:25:33  <Exception> makeOffset2D: result of offsetting is null!
23:25:33  Recompute failed : Offset2D
23:25:33  End processing CSG file
23:25:33  <Exception> makeOffset2D: result of offsetting is null!
23:25:33  Recompute failed! Please check report view.
Changing to a positive offset correctly matches OpenSCAD. Should FreeCAD makeOffset2D be able to handle negative offsets?
@Kunda1

Still to debug problems with DoorArc and Union_Squares
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 »

Should FreeCAD makeOffset2D be able to handle negative offsets? @Kunda1
Maybe open a new forum thread to discuss it?
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
coldtobi
Posts: 3
Joined: Fri Sep 09, 2022 1:11 pm

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

Post by coldtobi »

(This has been reported in Debian: https://bugs.debian.org/cgi-bin/bugrepo ... bug=860789)

Quoting the Debian Bug:
in attempting to convert from OpenSCAD to STEP,
found the advice here and followed it:
https://forum.lulzbot.com/viewtopic.php?t=243

however the following file has all of its "difference" (removal)
objects turned into "unions" (additions):
http://hands.com/~lkcl/microdesktop_prog2.scad
(Attaching a screenshot comparing FreeCAD 0.20.1 with OpenSCAD 2021.01, both Debian packaged versions.)
Attachments
Screenshot from 2022-09-11 13-32-14.png
Screenshot from 2022-09-11 13-32-14.png (145.81 KiB) Viewed 897 times
User avatar
chennes
Veteran
Posts: 3878
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 file contains an empty "union()" that appears to confuse FreeCAD -- we've got code to handle that condition, but it must not be working right. I'll try to take a closer look.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
Post Reply