Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
a-sunkari opened this issue Oct 6, 2024 · 22 comments
Open

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

a-sunkari opened this issue Oct 6, 2024 · 22 comments

Comments

@a-sunkari
Copy link

a-sunkari commented Oct 6, 2024

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!

@KeithSloan
Copy link
Owner

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
Copy link
Owner

KeithSloan commented Oct 7, 2024

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 KeithSloan reopened this Oct 7, 2024
@KeithSloan
Copy link
Owner

KeithSloan commented Oct 7, 2024

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

@mhindi2
Copy link
Collaborator

mhindi2 commented Oct 7, 2024

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.

@a-sunkari
Copy link
Author

a-sunkari commented Oct 7, 2024

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!

@KeithSloan
Copy link
Owner

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

@a-sunkari
Copy link
Author

@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.

@mhindi2
Copy link
Collaborator

mhindi2 commented Oct 7, 2024

@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

@a-sunkari
Copy link
Author

a-sunkari commented Oct 7, 2024

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.

@mhindi2
Copy link
Collaborator

mhindi2 commented Oct 7, 2024 via email

@KeithSloan
Copy link
Owner

@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
Copy link
Owner

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

@robinsheehy
Copy link

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.

@KeithSloan
Copy link
Owner

KeithSloan commented Nov 27, 2024

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
Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

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

@KeithSloan
Copy link
Owner

KeithSloan commented Dec 2, 2024

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.

@a-sunkari
Copy link
Author

@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.

@KeithSloan
Copy link
Owner

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

@a-sunkari
Copy link
Author

a-sunkari commented Dec 17, 2024

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

@mhindi2
Copy link
Collaborator

mhindi2 commented Dec 18, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants