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
chennes
Veteran
Posts: 3884
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 »

OK, I just added a custom function to handle union(); (the original parser sees that line as illegal syntax). I don't know if it's the most elegant solution, but now I am getting the correct shape (git commit 88ee6bb47f).
microdesktop_freecad.jpeg
microdesktop_freecad.jpeg (147.01 KiB) Viewed 3686 times
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 »

Snap 'edge' testers will be able to test this functionality in ~1 hour once the builds complete.

Edit:
@chennes will this change merit adding documentation to the OpenSCAD_Workbench ?

Edit2:
The docs say that python3-ply is a necessary dependency (for v0.19). Is this still true for v0.20+ ?
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: 3884
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 »

Kunda1 wrote: Sun Sep 11, 2022 10:23 pm @chennes will this change merit adding documentation to the OpenSCAD_Workbench ?
I don't think so -- this is really a bug fix. I am hopeful that it resolves quite a few nagging OpenSCAD problems, though -- I've seen this construct in several recent bugs.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
chennes
Veteran
Posts: 3884
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 »

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
Thanks, Keith - sorry for the delayed response. I've incorporated a few of your recent changes into mainline, and can reproduce the errors above. It does seem like we need to add support for negative offsets, since they are legal in OpenSCAD.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
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 »

The attached SCAD file which is just a large polyhedron request just seem to loop the OpenSCAD importers.
trial.scad
(19.49 KiB) Downloaded 21 times
trial.csg
(19.31 KiB) Downloaded 24 times
User avatar
chennes
Veteran
Posts: 3884
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 »

@keithsloan52 I am working on the last bit of issue #7305 -- there are some commented out lines near the end of importDXFface that, if uncommented, will mostly clean up the issue. Do you know why they are commented out? I think that the end of that function should be something like:

Code: Select all

    container = None
    for layer in layers: #remove everything that has been imported
        if container is None:
            container = layer.getParentGroup()
        removeOp = getattr(layer, "removeObjectsFromDocument", None)
        if callable(removeOp):
            layer.removeObjectsFromDocument()
        for obj in layer.Group:
            obj.Document.removeObject(obj.Name)
        layer.Document.removeObject(layer.Name)
    container.Document.removeObject(container.Name)
If I do that, both the extra lines and the extra Layers container are removed from the example file in the ticket.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
chennes
Veteran
Posts: 3884
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 »

keithsloan52 wrote: Sun Nov 20, 2022 10:41 am The attached SCAD file which is just a large polyhedron request just seem to loop the OpenSCAD importers.
It looks like we're locked up on this call in AppPartPy.cpp, line 963

Code: Select all

                shape = sewShell.ApplySewing(shell);
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
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 »

chennes wrote: Fri Dec 02, 2022 1:29 am @keithsloan52 I am working on the last bit of issue #7305 -- there are some commented out lines near the end of importDXFface that, if uncommented, will mostly clean up the issue. Do you know why they are commented out? I think that the end of that function should be something like:

Code: Select all

    container = None
    for layer in layers: #remove everything that has been imported
        if container is None:
            container = layer.getParentGroup()
        removeOp = getattr(layer, "removeObjectsFromDocument", None)
        if callable(removeOp):
            layer.removeObjectsFromDocument()
        for obj in layer.Group:
            obj.Document.removeObject(obj.Name)
        layer.Document.removeObject(layer.Name)
    container.Document.removeObject(container.Name)
If I do that, both the extra lines and the extra Layers container are removed from the example file in the ticket.
I did the original importer using Lex to parse, Sebastian came up with the idea of dealing with hull, minkowski requests by invoking openscad
and hence the importDXFface.

No idea why those lines got commented but I would leave them as comments and copy the code just after the comments
adding a comment that they were added back on 02/12/2022.

Rational I have had situations where code goes back and forth. So if somebody looks in the future and thinks they should be commented out for
some reason, they should be aware that we have been round this loop before.

It would be a lot simpler if the DXF importer that FC now uses supported import to a face as well as import to a doc.
I once did some fixes for the old FC importer lib, it was HORRIBLE code in my opinion.
csg_p01
Posts: 1
Joined: Tue Dec 06, 2022 8:33 pm

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

Post by csg_p01 »

Code: Select all

union() {
    rotate_extrude()
    polygon([
    [10,0],
    [10,20],
    [10,20],
    [0,0]
    ]);
    
    linear_extrude(5)
    circle(d=10);
}
seems to produce a angle argument of 90° for union in freecad 0.20, even though it is not supposed to.

changing the order does result in the correct union:

Code: Select all

union() {
    linear_extrude(5)
    circle(d=10);
    
    rotate_extrude()
    polygon([
    [10,0],
    [10,20],
    [10,20],
    [0,0]
    ]);
}
This is true for csg as well as scad files and happens with wrong values for the translation property of union in a similar way (in freecad 0.18 union worked fine).
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 »

csg_p01 wrote: Tue Dec 06, 2022 8:48 pm

Code: Select all

union() {
    rotate_extrude()
    polygon([
    [10,0],
    [10,20],
    [10,20],
    [0,0]
    ]);
    
    linear_extrude(5)
    circle(d=10);
}
seems to produce a angle argument of 90° for union in freecad 0.20, even though it is not supposed to.

changing the order does result in the correct union:

Code: Select all

union() {
    linear_extrude(5)
    circle(d=10);
    
    rotate_extrude()
    polygon([
    [10,0],
    [10,20],
    [10,20],
    [0,0]
    ]);
}
This is true for csg as well as scad files and happens with wrong values for the translation property of union in a similar way (in freecad 0.18 union worked fine).
Note the sections of code above are scad code, they don't work if you just put them in a file with the extension csg,
they could be exported from native OpenSCAD as csg files.
testcsg1.scad
(148 Bytes) Downloaded 18 times
testcsg2.scad
(148 Bytes) Downloaded 19 times
I can confirm the described behaviour for

Code: Select all

OS: macOS 10.16
Word size of FreeCAD: 64-bit
Version: 0.20.29177 (Git)
Build type: Release
Branch: (HEAD detached at 0.20)
Hash: 68e337670e227889217652ddac593c93b5e8dc94
Python 3.9.13, Qt 5.12.9, Coin 4.0.0, Vtk 9.1.0, OCC 7.5.3
Locale: C/Default (C)
Installed mods: 
  * ImportNURBS 1.1.0
  * ImportExport_3DM 0.1.0
  * Pyramids-and-Polyhedrons
  * GDML 2.0.0
  * Alternate_OpenSCAD 1.0.0
  * toSketch 1.0.1
  * Curves 0.6.4
The problem seems not to occur with the Alternate OpenCAD importer.
Post Reply