[BUG] Python stp import discrepancies between 0.18 and 0.19

About the development of the Part Design module/workbench. PLEASE DO NOT POST HELP REQUESTS HERE!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
OneTwentyTwo
Posts: 4
Joined: Mon Jun 07, 2021 1:45 am

[BUG] Python stp import discrepancies between 0.18 and 0.19

Post by OneTwentyTwo »

Hello,

Before I start to describe my problem, I'd like to say that I really enjoy FreeCAD and the work done by the developers. Great software, especially the Python interface!

I will try to give as many details as possible. If some things are missing, let me know and I will add them

Very high level: I use a python script (no gui) to import an assembly in the step format (see stp file attached) and then read the parts in order to build a tree. This script works perfectly fine with FreeCAD 0.18, but does not work with FreeCAD 0.19 because of a segmentation fault.

My setup: I am using Docker containers. One for each version so everything is independant and there is no clash between both versions. Here is the information I printed from the console. Please note that I am also able to reproduce my issue on Windows, so the OS seems to be irrelevant.

FreeCAD 0.18
BuildVersionMinor: 0.18
BuildVersionMajor: 0
BuildRevision: 16146 (Git)
BuildRevisionDate: 2019/10/22 16:53:35
BuildRevisionBranch: HEAD detached at 0.18.4
BuildRevisionHash: 980bf9060e28555fecd9e3462f68ca74007b70f8
Python version: 3.6.9
OCC Version: 7.3.0

FreeCAD 0.19
BuildVersionMinor: 0.19
BuildVersionMajor: 0
BuildRevision: 24291 (Git)
BuildRevisionDate: 2021/04/15 09:17:08
BuildRevisionBranch: HEAD detached at 0.19.2
BuildRevisionHash: 7b5e18a0759de778b74d3a5c17eba9cb815035ac
Python version: 3.8.10
OCC Version: 7.4.0

FreeCAD 0.20
BuildVersionMinor: 0.20
BuildVersionMajor: 0
BuildRevision: 25025 (Git)
BuildRevisionDate: 2021/06/04 16:30:30
BuildRevisionBranch: master
BuildRevisionHash: fb8b21ec43dca706a4aa2d63d59a4fb79f050369
Python version: 3.9.5
OCC Version: 7.5.2

More detailed description of my issue
The command I use to import my step file is: Import.open(path_to_file). I attached the result that I get with 0.18 (Cylinders-018.txt). That result file is a list of the parts in the model and is autogenerated by my script with the information retrieved from the FreeCAD import. For testing purposes, you can use the python command FreeCAD.ActiveDocument.Objects to see the list of imported objects.

Now, when I switch to 0.19 and run the exact same script with the same input file, I get a segmentation fault. The console only prints Segmentation Fault without more details though. If there is a way to get the error code, please let me know and I will add it. There was a similar issue raised a couple months ago: https://forum.freecadweb.org/viewtopic.php?f=19&t=49243. They suggested a workaround and with that workaround, the file can be imported without the segfault, but all the children information is lost (which makes sense, because the workaround is to set ReadShapeCompoundMode to False, see file Cylinders-019.txt) and unfortunately, this is not the behavior that I am looking for. I would expect the import command to work with both ReadShapeCompoundMode set to True or False and I would expect the results to be the same for 0.18 and 0.19.

Please note that I am able to reproduce this issue with all the 0.19 versions that I've tried (so far). So I do not think that it is tied to the specific version above. I am also able to reproduce the issue with other stp models that are assemblies.

Let me know if you want me to provide more details.
Thanks a lot for your time!
Attachments
Cylinders.stp
(16.5 KiB) Downloaded 141 times
Cylinders-019.txt
(128 Bytes) Downloaded 123 times
Cylinders-018.txt
(1007 Bytes) Downloaded 127 times
Last edited by OneTwentyTwo on Tue Jun 08, 2021 2:26 am, edited 1 time in total.
chrisb
Veteran
Posts: 53785
Joined: Tue Mar 17, 2015 9:14 am

Re: [BUG] Python stp import discrepancies between 0.18 and 0.19

Post by chrisb »

Hi and welcome to the forum!

Please retry with a current 0.20 version.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
OneTwentyTwo
Posts: 4
Joined: Mon Jun 07, 2021 1:45 am

Re: [BUG] Python stp import discrepancies between 0.18 and 0.19

Post by OneTwentyTwo »

chrisb wrote: Mon Jun 07, 2021 8:08 pm Hi and welcome to the forum!

Please retry with a current 0.20 version.
Hello Chris,

I tried with the latest 0.20 build. Same issue. I added the version info in my initial post.
chrisb
Veteran
Posts: 53785
Joined: Tue Mar 17, 2015 9:14 am

Re: [BUG] Python stp import discrepancies between 0.18 and 0.19

Post by chrisb »

Did you try with a plain vanilla config? I can import the step file using the GUI without problems.

OS: macOS 10.16
Word size of FreeCAD: 64-bit
Version: 0.20.24825 (Git)
Build type: Release
Branch: master
Hash: ccc4151b3020969450325466e385850783795325
Python version: 3.9.2
Qt version: 5.12.9
Coin version: 4.0.0
OCC version: 7.5.1
Locale: C/Default (C)
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
OneTwentyTwo
Posts: 4
Joined: Mon Jun 07, 2021 1:45 am

Re: [BUG] Python stp import discrepancies between 0.18 and 0.19

Post by OneTwentyTwo »

chrisb wrote: Tue Jun 08, 2021 6:17 amDid you try with a plain vanilla config?
Yes, I always install FreeCAD from the standard AppImage provided with each version
chrisb wrote: Tue Jun 08, 2021 6:17 amI can import the step file using the GUI without problems.
My issue is not with the GUI though, and it is not that I can't import. If I use the workaround provided in the thread I linked:

Code: Select all

FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Import/hSTEP").SetBool("ReadShapeCompoundMode", False)
(ReadShapeCompoundMode set to False instead of True) then I can import, but I lose all the tree hierarchy of my assembly.

I installed the version 0.20 detailled in my first post on Windows just to try it out and made a Python script to test. I force ReadShapeCompoundMode to True at the beginning to make sure to overwrite any saved user preference. Surprisingly, I did not get the Segfault on Windows, but if you run it, you will see that the outputs between 0.18 and 0.19/0.20 are different and they should not. I expect the importer to retrieve the same objects from the same stp file.

You can use the code below. Put it in the FreeCAD bin folder with the stp file and run it from there with both versions.

Code: Select all

import FreeCAD
import Import


# To run from the python interpreter
# exec(open(​"test_import.py").read())
# Let's set this to true in order to overwrite the user preferences and make sure the problematic mode is used
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Import/hSTEP").SetBool("ReadShapeCompoundMode", True)
Import.open("Cylinders.stp")

for o in FreeCAD.ActiveDocument.Objects:
    print(f"{o.Label}")
Output from 0.18
FreeCAD 0.18, Libs: 0.18R4 (GitTag)
...
Reading STEP file......
SOLID
SOLID001
SOLID002
SOLID003
SOLID004
SOLID005
SOLID006
SOLID007
Cylinders
Origin
X_Axis
Y_Axis
Z_Axis
XY_Plane
XZ_Plane
YZ_Plane

Output from 0.19/0.20
Cylinders001
Syres
Veteran
Posts: 2891
Joined: Thu Aug 09, 2018 11:14 am

Re: [BUG] Python stp import discrepancies between 0.18 and 0.19

Post by Syres »

OneTwentyTwo wrote: Tue Jun 08, 2021 12:44 pm
chrisb wrote: Tue Jun 08, 2021 6:17 amDid you try with a plain vanilla config?
Yes, I always install FreeCAD from the standard AppImage provided with each version
I believe what @chrisb was getting at was, have you tried renaming your config files so you're starting as a new user, I did and this is what I found. I have a number of Windows builds from when big changes happen and I firstly proved this occurred after the Big Merge in August 2019 but it's related to more than just the Preference you quote in the code.

Here are the settings which cause <class 'RuntimeError'>: Illegal storage access! error:

StepImportFails.jpg
StepImportFails.jpg (63.88 KiB) Viewed 5995 times

and here are the reset parameters which make your code work as you expect:

StepImportWorks.jpg
StepImportWorks.jpg (80.52 KiB) Viewed 5995 times

So in this instance I don't believe it to be a bug, where specific areas of FreeCAD that are fully backwards compatible, these should be classed as a bonus IMHO.

OS: Windows 7 Version 6.1 (Build 7601: SP 1)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.24291 (Git)
Build type: Release
Branch: releases/FreeCAD-0-19
Hash: 7b5e18a0759de778b74d3a5c17eba9cb815035ac
Python version: 3.8.6+
Qt version: 5.15.2
Coin version: 4.0.1
OCC version: 7.5.0
Locale: English/United Kingdom (en_GB)
OneTwentyTwo
Posts: 4
Joined: Mon Jun 07, 2021 1:45 am

Re: [BUG] Python stp import discrepancies between 0.18 and 0.19

Post by OneTwentyTwo »

Syres wrote: Wed Jun 09, 2021 12:35 pm I believe what @chrisb was getting at was, have you tried renaming your config files so you're starting as a new user, I did and this is what I found.
All my FreeCAD versions are dockerized, so I believe that the config files should be clean everytime I start my containers... Anyway, I hardcoded the parameters in my code and it works now! The only difference is that instead of having Solid001, Solid002, etc, I now have Cylinder001, Cylinder002, etc, which is even better.

Thanks a lot for your help, I really appreciate it!

Now I am wondering if this is really a matter of clean config files (since I am running everything in Docker). Should this information be in the release notes somewhere?
chrisb
Veteran
Posts: 53785
Joined: Tue Mar 17, 2015 9:14 am

Re: [BUG] Python stp import discrepancies between 0.18 and 0.19

Post by chrisb »

Syres wrote: Wed Jun 09, 2021 12:35 pm I believe what @chrisb was getting at was, have you tried renaming your config files so you're starting as a new user, I did and this is what I found.
For the sake of completeness and precision: That's what my comment was indeed about.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Jaume Calm
Posts: 2
Joined: Thu Mar 09, 2023 8:13 am

Re: [BUG] Python stp import discrepancies between 0.18 and 0.19

Post by Jaume Calm »

Hello!

I was having the exact same issue, also with the dockerized environment, so thanks for the post.

I can't say for the original poster, but for me the issue was not that there was already a config, but rather the lack of it.
It wasn't until I run

Code: Select all

/usr/bin/freecadcmd --dump-config
that the ".FreeCAD" dir popped up with the "user.cfg" and "system.cfg" files.
And this is how it looked like:

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<FCParameters>

  <FCParamGroup Name="Root">
    <FCParamGroup Name="BaseApp">
      <FCParamGroup Name="LogLevels">
        <FCInt Name="Default" Value="2"/>
      </FCParamGroup>
      <FCParamGroup Name="Preferences">
        <FCParamGroup Name="General"/>
        <FCParamGroup Name="Units"/>
        <FCParamGroup Name="Macro"/>
        <FCParamGroup Name="Mod">
          <FCParamGroup Name="Import">
            <FCParamGroup Name="hSTEP">
              <FCBool Name="ReadShapeCompoundMode" Value="1"/>
            </FCParamGroup>
          </FCParamGroup>
          <FCParamGroup Name="OpenSCAD"/>
        </FCParamGroup>
      </FCParamGroup>
    </FCParamGroup>
  </FCParamGroup>

</FCParameters>
After this, I had no need to add or override any parameter whatsoever in my py script.
But it got me wondering, so I kept testing without the usr.cfg file, and the only parameter that made it work was setting "UseLinkGroup" to false

Code: Select all

FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Import").SetBool("UseLinkGroup", False)
Which implies that if a cfg file is present, even if the values are not specified, some "default" values are taken, but otherwise it just fails for whatever reason.

I'm sorry I do not have the capacityto give you a gdb backtrace, but this seems to be totally related to viewtopic.php?t=49243 so maybe @amrit3701 will be able to figure out something else, since this piece of information seemed to be lacking in that thread.

Good luck to you all.
User avatar
adrianinsaval
Veteran
Posts: 5534
Joined: Thu Apr 05, 2018 5:15 pm

Re: [BUG] Python stp import discrepancies between 0.18 and 0.19

Post by adrianinsaval »

please state your version information, are you able to reproduce this on 0.21? If so, I suggest creating an issue on github.
Post Reply