KeithSloan / GDML

FreeCAD GDML Workbench - AddonManager Installable
Other
56 stars 17 forks source link

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

Open a-sunkari opened 1 month ago

a-sunkari commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

@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 commented 1 month ago

@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 commented 1 month ago

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 commented 1 month ago

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

KeithSloan commented 1 month ago

@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 commented 1 month ago

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