GDML icon indicating copy to clipboard operation
GDML copied to clipboard

Error for GDML export in FreeCAD 1.0 (RC 1.0 and 2.0)

Open a-sunkari opened this issue 1 year ago • 40 comments

OS: Windows 11 FreeCAD Version: 1.0 (In both RC 1.0 and 2.0)

I recently started using the GDML workbench in FreeCAD 1.0 due to an issue in version 0.21 where the tesselate function did not work properly.

The GDML workbench worked fine until today, where I am having the following error after I attempt to export the worldVOL to GDML:

12:38:27  check GDML structure
12:38:27  GDML Counts : 3 1
12:38:27  Root GDML Counts 3 1
12:38:27  process VolAsm Name worldVOL Label worldVOL
12:38:27  testing isAsembly for: worldVOL
12:38:27  pyException: Traceback (most recent call last):
  File "<string>", line 8, in <module>
  File "C:\Users\appin\AppData\Roaming\FreeCAD\Mod\GDML\.\freecad\gdml\exportGDML.py", line 3101, in export
    exportGDMLworld(first, filepath, fileExt)
  File "C:\Users\appin\AppData\Roaming\FreeCAD\Mod\GDML\.\freecad\gdml\exportGDML.py", line 2869, in exportGDMLworld
    exportGDML(first, filepath, fileExt)
  File "C:\Users\appin\AppData\Roaming\FreeCAD\Mod\GDML\.\freecad\gdml\exportGDML.py", line 2792, in exportGDML
    exportWorldVol(first, fileExt)
  File "C:\Users\appin\AppData\Roaming\FreeCAD\Mod\GDML\.\freecad\gdml\exportGDML.py", line 2720, in exportWorldVol
    processVolAssem(vol, xmlParent, WorldVOL)
  File "C:\Users\appin\AppData\Roaming\FreeCAD\Mod\GDML\.\freecad\gdml\exportGDML.py", line 2328, in processVolAssem
    if isContainer(vol):
       ^^^^^^^^^^^^^^^^
  File "C:\Users\appin\AppData\Roaming\FreeCAD\Mod\GDML\.\freecad\gdml\exportGDML.py", line 2489, in isContainer
    if not isAssembly(obj):
           ^^^^^^^^^^^^^^^
  File "C:\Users\appin\AppData\Roaming\FreeCAD\Mod\GDML\.\freecad\gdml\exportGDML.py", line 2538, in isAssembly
    for ob in childObjects[obj]:
              ~~~~~~~~~~~~^^^^^
<class 'KeyError'>: (<Part object>,)

It looks like Part object is not found in childObjects. Considering that the error comes after it's checking the assembly dictionary for the world volume, I think the error has something to do with that?

To double check, I opened a FreeCAD document I was able to successfully export yesterday and tried exporting it today, and I got the same error. I also attempted using both RC 1.0 and 2.0, but the same issue presented itself in both versions.

Let me know if more information is needed, or if there is anything I can do to change the code to get the export function working!

a-sunkari avatar Oct 06 '24 17:10 a-sunkari

Not much i can do as i am away till 15th.

May i ask how you created the Tessellation, Munther add a facility to perform Automatic Tessellation for various Part options like Loft etc and that has now been extended for general Part objects, for example as created on import of a step file, so there maybe a work around by using a different method of creating the Tessellation.

KeithSloan avatar Oct 07 '24 06:10 KeithSloan

Looking further at the error messages please could you post a screen shot of the FC structure?.

There should be a App::Part WorldVol and a number of items underneath

KeithSloan avatar Oct 07 '24 06:10 KeithSloan

Obviously there is a bug of some sort but looks like something has gone wrong with the structure, should look like, check combo view as per

KeithSloan avatar Oct 07 '24 07:10 KeithSloan

Is it possible to email me the file, or at least the part that is causing the failure? I have fixed several issues recently, but I will have to wait for Keith to get back from vacation to merge the fixes.

mhindi2 avatar Oct 07 '24 11:10 mhindi2

Thank you all for your quick responses!

@KeithSloan yes, I made sure the file followed the right "structure" for the world volume. This was a .step geometry that I used the object-to-tesselate function on. I've attached a screenshot of it, as well as the FreeCAD file, to this comment.

image

Interestingly, I was able to export this file to GDML a few days ago with no problem (as commented in the other post) but couldn't do so the day after! I don't know why that would be, because as far as I know, there hadn't been any changes to the GDML workbench or my FreeCAD installation. I've attached that GDML file to this comment as well.

@mhindi2 yes, the FreeCAD file is attached to this comment. Attached is also the GDML I was able to successfully export a few days ago. No changes have been made to the FreeCAD file since then.

FreeCAD Files.zip

Thank you all again for your help!

a-sunkari avatar Oct 07 '24 16:10 a-sunkari

The last update to the Main branch was 27th Sept.

If you know how to access git on windows you could try going back to the 23rd with

git checkout -b testbranch 228e857

Needs to be performed in the directory where FC has installed the GDML workbench

KeithSloan avatar Oct 07 '24 16:10 KeithSloan

@KeithSloan Just gave it a try, changing the branch didn't seem to solve the issue.

For reference, the GDML export worked on 10/5, but attempting to export the same file (with no changes) on 10/6 caused the export issues listed above.

Take your time and enjoy the vacation! I'm not in a rush because I'm using the STL-to-GDML python tool which is serving me just fine for the time being. Perhaps Dr. Hindi might be able to give it a try in the meantime as well.

a-sunkari avatar Oct 07 '24 17:10 a-sunkari

@a-sunkari I responded by email a short time ago, but it seems the response did not make it to this page. So I will paste what I wrote:

Thanks for giving me a copy of the file. I am responding to this via email; not sure what will show up on the github page.

On my system (FreeCAD 0.21.1) and with my current version of the workbench I don't get the error you reported when I export the file to gdml. See attached screenshot. I can send you the version of the exportGDML.py file that I cam currently using, but this is probably out of step of what's on the github and still has some bugs that I already fixed in a new branch, but I am not ready yet to release the new branch.

A question for you, though. All the tessellated shapes (converted from step) seem to be tubes. Is there any reason why you don't build them as tubes instead of importing them as step files. Simulations would run much faster with tubes than with tessellations.

Screenshot_20241007_101942

mhindi2 avatar Oct 07 '24 17:10 mhindi2

Thanks for the review!

So I went back to 0.21.2 and it seems to export fine, although there are some changes to be made to the repo. One, as mentioned in the other thread is to change the edgelistArea function to match the Python 3.8 interpreter in FreeCAD 0.21. The other error I got:

"C:\Users\appin\AppData\Roaming\FreeCAD\Mod\GDML\.\freecad\gdml\exportGDML.py", line 6244, in AutoTessellateExporter def alreadyExported(shape) -> str | None: <class 'TypeError'>: unsupported operand type(s) for |: 'type' and 'NoneType'

was also a Python version mismatch; I solved it with adding

from typing import Union

and changing the alreadyExported function to

def alreadyExported(shape) -> Union[str, None]:

to get around the inability to use the | syntax in that version of Python. I will add this to the other thread as well.

As one last sanity check, I installed 1.0 on my Rocky Linux virtual machine and tried exporting from there, but I ended up getting the same export error. I think that the reason for the export error I have been having in FreeCAD 1.0 is due to the fact that it uses Python 3.11 in the interpreter rather than 3.8; perhaps that causes the problem? I will investigate and update if I find anything.

@mhindi2 thanks for the feedback about using tubes versus tessellated shapes! I plan on using more complex geometry in the future, but I just wanted to test a basic geometry to make sure the .step -> tessellation -> GDML conversion works well.

a-sunkari avatar Oct 07 '24 19:10 a-sunkari

Thanks for working on this! As far as I know, the type annotation is something that the python interpreter itself should ignore. But it seems in Windows the python interpreter complains about types it does not understand. You could easily just remove the types altogether.

Keith has been looking into issues with FC 1.0; I have not tested that version myself yet. When Keith returns we will address those issues. Thanks for sticking with us and don't hesitate to bring up any issues you might find!

On Mon, Oct 7, 2024, 12:36 PM a-sunkari @.***> wrote:

Thanks for the review!

So I went back to 0.21.2 and it seems to export fine, although there are some changes to be made to the repo. One, as mentioned in the other thread https://github.com/KeithSloan/GDML/issues/146 is to change the edgelistArea function to match the Python 3.8 interpreter in FreeCAD 0.21. The other error I got:

"C:\Users\appin\AppData\Roaming\FreeCAD\Mod\GDML.\freecad\gdml\exportGDML.py", line 6244, in AutoTessellateExporter def alreadyExported(shape) -> str | None: <class 'TypeError'>: unsupported operand type(s) for |: 'type' and 'NoneType'

was also a Python version mismatch; I solved it with adding

from typing import Union

and changing the alreadyExported function to

def alreadyExported(shape) -> Union[str, None]:

to get around the inability to use the | syntax in that version of Python. I will add this to the other thread as well.

I think that the reason for the export error I have been having in FreeCAD 1.0 is due to the fact that it uses Python 3.11 in the interpreter rather than 3.8; perhaps that causes the problem? I will investigate and update if I find anything.

@mhindi2 https://github.com/mhindi2 thanks for the feedback about using tubes versus tessellated shapes! I plan on using more complex geometry in the future, but I just wanted to test a basic geometry to make sure the .step -> tessellation -> GDML conversion works well.

— Reply to this email directly, view it on GitHub https://github.com/KeithSloan/GDML/issues/147#issuecomment-2397732233, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWV3NCB6KRXKMNHLGBSOWZTZ2LPDDAVCNFSM6AAAAABPOQXA5OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGOJXG4ZTEMRTGM . You are receiving this because you were mentioned.Message ID: @.***>

mhindi2 avatar Oct 07 '24 20:10 mhindi2

@a-sunkari @mhindi2

Please could you email me a copy of the file, so I can check with the version of exportGDML that I and the Repro have.

Thanks

KeithSloan avatar Oct 15 '24 12:10 KeithSloan

Okay back from vacation. I just picked up the version posted above and had no problem on export or loading into geant4 Image 15-10-2024 at 16 04

KeithSloan avatar Oct 15 '24 15:10 KeithSloan

Hello,

Just a quick note to say that I am seeing this exact error in FreeCAD 1.0.0. I also could export the day before, but cannot now. The export also fails on the simplest design I could make, a single box GDMLBox inside the worldVOL.

robinsheehy avatar Nov 27 '24 06:11 robinsheehy

I just re-downloaded the problem file in this thread and tried with FC1.0.0 on my system and exported okay. Same with a simple Box.

Please could you post your FreeCAD info.

I also attach a zip of the files concerned FreeCAD Files 2.zip

My FreeCAD info is

OS: macOS 14.4 Architecture: x86_64 Version: 1.0.0.39109 (Git) Conda Build type: Release Branch: (HEAD detached at 1.0.0) Hash: 2fcc5317fe3aee96ca73475986a577719fc78e20 Python 3.11.10, Qt 5.15.15, Coin 4.0.3, Vtk 9.3.0, OCC 7.8.1 Locale: C/Default (C) Stylesheet/Theme/QtStyle: unset/FreeCAD Classic/Qt default Installed mods:

  • ImportNURBS 1.1.0
  • ImportExport_3DM 0.1.0
  • DynamicData 2.69.0
  • Pyramids-and-Polyhedrons
  • occi-freecad-plugin 0.1.0
  • GDML 2.0.0
  • fasteners 0.5.30
  • Design456 0.0.1
  • Alternate_OpenSCAD 1.0.0
  • SWPart
  • toSketch 1.0.1
  • Curves 0.6.51

KeithSloan avatar Nov 27 '24 07:11 KeithSloan

Have had one user on Windows that reported that, they had to save and restart their system to fix an export problem, that suggests to me that there is a memory bug somewhere.

Given that you could export the day before maybe you are seeing a similar problem.

KeithSloan avatar Nov 27 '24 07:11 KeithSloan

Okay I just updated the package.xml file in the repro to say 2.0.1 Beta so if you go to tools | addon Manager Refesh cache

You should see the latest version is 2.0.1 Beta.

Try uninstall | restart FC | install

Ignore install of python gmsh ( There is an issue with FC 1.0.0 and the gmsh python lib ) All non Gmsh facilities should be fine.

If you then FreeCAD | About Copy info an paste you should see something like OS: macOS 14.4 Architecture: x86_64 Version: 1.0.0.39109 (Git) Conda Build type: Release Branch: (HEAD detached at 1.0.0) Hash: 2fcc5317fe3aee96ca73475986a577719fc78e20 Python 3.11.10, Qt 5.15.15, Coin 4.0.3, Vtk 9.3.0, OCC 7.8.1 Locale: C/Default (C) Stylesheet/Theme/QtStyle: unset/FreeCAD Classic/Qt default Installed mods:

  • ImportNURBS 1.1.0
  • ImportExport_3DM 0.1.0
  • DynamicData 2.70.0
  • Pyramids-and-Polyhedrons
  • occi-freecad-plugin 0.1.0
  • GDML 2.0.1Beta
  • fasteners 0.5.32
  • Design456 0.0.1
  • Alternate_OpenSCAD 1.0.0
  • SWPart
  • toSketch 1.0.1
  • Curves 0.6.51

If you see GDML 2.0.1 Beta Then this will check you have the latest version

(For some reason the addon manager does not pick up on the change) It says 2.0.0 is latest but after install says installed 2.0.1 Image 27-11-2024 at 08 23

<package format="1" xmlns="https://wiki.freecad.org/Package_Metadata"> <name>GDML workbench</name> <description>An external workbench for creating GDML models for Geant4 and Root</description> <version>2.0.1 Beta</version> <date>2024-27-11</date> <maintainer email="[email protected]">Keith Sloan</maintainer> <license file="LICENSE">LGPL-2.1</license> <url type="repository" branch="Main">https://github.com/KeithSloan/GDML</url> <url type="documentation">https://github.com/KeithSloan/GDML/wiki</url> <url type="readme">https://github.com/KeithSloan/GDML/blob/Main/README.md</url>

KeithSloan avatar Nov 27 '24 08:11 KeithSloan

For how to successfully install the gmsh python library see https://github.com/KeithSloan/GDML/issues/154

KeithSloan avatar Nov 27 '24 17:11 KeithSloan

Thank you all for your quick responses!

@KeithSloan yes, I made sure the file followed the right "structure" for the world volume. This was a .step geometry that I used the object-to-tesselate function on. I've attached a screenshot of it, as well as the FreeCAD file, to this comment.

image

Interestingly, I was able to export this file to GDML a few days ago with no problem (as commented in the other post) but couldn't do so the day after! I don't know why that would be, because as far as I know, there hadn't been any changes to the GDML workbench or my FreeCAD installation. I've attached that GDML file to this comment as well.

@mhindi2 yes, the FreeCAD file is attached to this comment. Attached is also the GDML I was able to successfully export a few days ago. No changes have been made to the FreeCAD file since then.

FreeCAD Files.zip

Thank you all again for your help!

@a-sunkari May I ask why you rotated the WorldVol 90 degrees?

This make things very difficult to create valid GDML for its contents.

KeithSloan avatar Dec 02 '24 20:12 KeithSloan

@KeithSloan I'm pretty sure I did that to rotate all my geometry because they were imported in the wrong direction. I'm pretty sure I got the error even when I rotated just the individual geometries as well, or even if I didn't rotate anything at all. I'm currently on vacation so I can't see the file right now but I'll be able to check early next week.

a-sunkari avatar Dec 04 '24 15:12 a-sunkari

Thanks - If you can provide the original file un-rotated some time, we can look the issue.

KeithSloan avatar Dec 04 '24 16:12 KeithSloan

Here's a test file I've been working on that doesn't export for me in 1.0 - but works fine on previous versions, with the small changes to the code I've made. The world volume is not rotated in this file. Let me know if any more info is needed!

File provided as link because GitHub doesn't support the uploading of FreeCAD files.

https://file.io/eAg5tzP2FQCM

a-sunkari avatar Dec 17 '24 18:12 a-sunkari

When I try access the file I get a message that says it has been deleted. Could you please repost, or else email me directly. Thanks.

mhindi2 avatar Dec 18 '24 15:12 mhindi2

Hi, I also encountered the same problem. I seem to have solved this problem by modifying the function def buildDocTree() in "GDML/freecad/gdml/exportGDML.py":

You can refer to: https://github.com/KeithSloan/GDML/issues/158#issuecomment-2599593615

exportGDML.py

zhangcaocao avatar Jan 18 '25 07:01 zhangcaocao

Im now getting familiar with FreeCAD and the GDML workbench, has this function mod been verified to resolve export issues in Win or Linux yet? I unfortunately was having the same issues with Part Obj , in both OS. If so, can this function modification be done in FreeCAD itself?

adastra-orion avatar Feb 19 '25 21:02 adastra-orion

Could you please send me the file you are having problems with. On my Linux machine the export works fine and on Windows it works with the modification suggested in one of the responses to #147. Please see coment from zhangcaocao above. His solution works on Windows (and on Linux, but that was working already).

Munther

On Wed, Feb 19, 2025, 1:19 PM adastra-orion @.***> wrote:

Im now getting familiar with FreeCAD and the GDML workbench, has this function mod been verified to resolve export issues in Win or Linux yet? I unfortunately was having the same issues with Part Obj , in both OS. If so, can this function modification be done in FreeCAD itself?

— Reply to this email directly, view it on GitHub https://github.com/KeithSloan/GDML/issues/147#issuecomment-2669784070, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWV3NCELLBKM7AXZRCILBIT2QTYPBAVCNFSM6AAAAABPOQXA5OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNRZG44DIMBXGA . You are receiving this because you were mentioned.Message ID: @.***> [image: adastra-orion]adastra-orion left a comment (KeithSloan/GDML#147) https://github.com/KeithSloan/GDML/issues/147#issuecomment-2669784070

Im now getting familiar with FreeCAD and the GDML workbench, has this function mod been verified to resolve export issues in Win or Linux yet? I unfortunately was having the same issues with Part Obj , in both OS. If so, can this function modification be done in FreeCAD itself?

— Reply to this email directly, view it on GitHub https://github.com/KeithSloan/GDML/issues/147#issuecomment-2669784070, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWV3NCELLBKM7AXZRCILBIT2QTYPBAVCNFSM6AAAAABPOQXA5OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNRZG44DIMBXGA . You are receiving this because you were mentioned.Message ID: @.***>

mhindi2 avatar Feb 19 '25 23:02 mhindi2

I am using just the simple feature function present in the workbench, generating a cube, and attempting to export the worldvol.

adastra-orion avatar Feb 24 '25 16:02 adastra-orion

Image

adastra-orion avatar Feb 24 '25 17:02 adastra-orion

Could yopu please send me or show me the report view (under View->Panels->Report View). You can save that as a text file. Also, please send the information shown under Help->About FreeCAD.

Thanks, Munther

mhindi2 avatar Feb 24 '25 18:02 mhindi2

Got it, thank you! I will check out the branch you are using and and see if I get the same error. I know that I have fixed this a while ago, and I thought the fix should be in the Main branch now, but I will compare against what I have.

mhindi2 avatar Feb 25 '25 01:02 mhindi2