shaise / FreeCAD_SheetMetal

A simple sheet metal workbench for FreeCAD
http://theseger.com/projects/2015/06/sheet-metal-addon-for-freecad/
GNU Lesser General Public License v2.1
190 stars 55 forks source link

Bend: Invalid subelement name #342

Open JaapStruyk opened 2 months ago

JaapStruyk commented 2 months ago

most of the workbench not working due to mallformed names of subelement, subelement has a name like: ;g543;SKT;:Hc32,E;:G;XTR;:7,F.Face3 when selecting Face3

OS: Ubuntu 24.04 LTS (ubuntu:GNOME/ubuntu) Word size of FreeCAD: 64-bit Version: 0.22.0dev.37543 (Git) AppImage Build type: Release Branch: main Hash: 3eb45b045cdda9d5bfe11baba2567a1df90f064c Python 3.11.9, Qt 5.15.13, Coin 4.0.2, Vtk 9.2.6, OCC 7.7.2 Locale: Dutch/Netherlands (nl_NL) Installed mods:

shaise commented 2 months ago

Is this freecad version with the new topological naming enabled?

JaapStruyk commented 2 months ago

No idea, stock appimage from weekly builds so presume not, btw starting with a sheetmetal base shape works fine, just found out then when saving, closing and reopening the drawing it's working as it should so think it's FreeCAD related not the sheetmetal workbench.

shaise commented 2 months ago

The ;g543;SKT;:Hc32,E;:G;XTR;:7,F.Face3 instead of just Face3 hints that the TNP is already enabled. I never tested it with TNP. I will investigate. Thanks!

JaapStruyk commented 2 months ago

It looks that TNP is used while working but gets lost when saving/reopening, on re-edit it's TNP again. Looks like a freecad bug in this release but does show a tiny bottleneck with sheetmetal if TNP is applied defenatly. Thanks for helping!

shaise commented 2 months ago

I will investigate if sheetmetal might collide with TNP.

shaise commented 2 months ago

@JaapStruyk , I have added some code to bypass the TNP issue. please update and test

JaapStruyk commented 2 months ago

Looks like you nailed it ;-) tried a couple of things but couldn't find trouble, thanks for the quick responce.

GS90 commented 2 months ago

Hello, Unfortunately, after the TNP problem was fixed, the models of sheet metal parts stopped working correctly. Errors appear after saving and reopening files.

FreeCAD info (latest weekly-build):

OS: Ubuntu 22.04.4 LTS (XFCE/xfce)
Word size of FreeCAD: 64-bit
Version: 0.22.0dev.37668 (Git) AppImage
Build type: Release
Branch: main
Hash: ea68c5e88cdc80044ede482f6ad908820f4c1c82
Python 3.11.9, Qt 5.15.13, Coin 4.0.2, Vtk 9.2.6, OCC 7.7.2
Locale: English/United States (en_US)
Installed mods: 
  * Assembly4 0.50.13
  * Plot 2022.4.17
  * sheetmetal 0.4.17
  * addFC 0.3.1
  * CfdOF 1.25.17
  * fasteners 0.5.21

Report:

09:59:47  <PropertyLinks> PropertyLinks.cpp(453): Error#Bend.baseObject missing element reference Error#BaseBend ;g5v2;SKT;:Had6,V;:G;OFS;:Had6:7,V;:G;OFS;:Had6:7,V;WIR;:Had6:4,V;:G;XTR;:Had6:7,E;:H,E.Edge2
09:59:47  <PropertyLinks> PropertyLinks.cpp(453): Error#Bend.baseObject missing element reference Error#BaseBend ;g3v1;SKT;:Had6,V;:G;OFS;:Had6:7,V;:G;OFS;:Had6:7,V;WIR;:Had6:4,V;:G;XTR;:Had6:7,E;:G;OFS;:Had6:7,E;:H,E.Edge40
09:59:47  pyException: Traceback (most recent call last):
  File "/home/***/.local/share/FreeCAD/Mod/sheetmetal/./SheetMetalCmd.py", line 1551, in execute
    thk, thkDir = sheet_thk(Main_Object, face[0])
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/***/.local/share/FreeCAD/Mod/sheetmetal/./SheetMetalCmd.py", line 437, in sheet_thk
    selItem = MainObject.getElement(SheetMetalBaseCmd.getElementFromTNP(selFaceName))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
<class 'ValueError'>: Invalid subelement name
09:59:47  Bend: Invalid subelement name

https://github.com/shaise/FreeCAD_SheetMetal/assets/25671299/07c01fa3-5572-440e-a4c3-7b846401d707

Error.zip

shaise commented 2 months ago

ok. I will investigate further more.

shaise commented 2 months ago

@GS90 , Thank you for the catch. This is indeed another TNP use case. Please check my fix.

I still think what I do is a workaround. I think .getElement should support TNP, perhaps @bgbsww can way in.

bgbsww commented 2 months ago

So the long subelement name is the correct full history name of the element, and as you can see, the tail portion after the dot is the traditional short name. Can you give a specific pointer to where in the FC API you are getting these names, so that I can confirm whether or not they should be visible at that point? My expectation is they would not be and you would just deal with the short name.

shaise commented 2 months ago

Hi @bgbsww , Thank you for your reply. Here is how it goes: A sheetmetal feature holds the selected faces it was built upon like this

        obj.addProperty(
            "App::PropertyLinkSub", "baseObject", "Parameters", _tip_
        ).baseObject = (selobj.Object, selobj.SubElementNames)

the SubElementNames is a list of faces / edges returned from the getSelectionEx command which return plain names. however when I read back the baseObject property it returns the full TNP name.

For now, as a workaround, I just clean the TNP name. Testing the same on FreeCad Link version, baseObject return the simple name, as expected.

shai

shaise commented 2 months ago

@GS90 , Thanks, I'll take a look. Please make a new issue for it. and delete the message from here.

shaise commented 2 months ago

Hi @bgbsww ,

Attached is an example I can not make any workarounds since this time the error is in C++. load the file, select Bend feature and change the length to say 15. This is the error:

15:04:41  <Exception> FeatureDressUp.cpp(209): Invalid edge link: ;Edge60;D9d4;:H,E.Edge70
15:04:41  Fillet: Invalid edge link: ;Edge60;D9d4;:H,E.Edge70

Test-SM-TNP.zip

bgbsww commented 2 months ago

Thank you! The reference on PropertyLinkSub was super helpful; there are no differences at the python layer, and no differences in the C++ implementation of PropertyLinkSub.

However, it appears that the ComplexGeoData::findElementName which is now Data::findElementName is missing this suspiciously germane clause at the top:

    // skip leading dots
    while(subname && subname[0] == '.')
        ++subname;

I need to keep running this down, but this smells right.

shaise commented 2 months ago

Thanks for all your hard work on TNP!

bgbsww commented 2 months ago

With that code in place, your example file fails until I replace Edge70 (one of the fillets), because it has a bad reference, but once that's done it appears to work correctly.

I need to run all the test suites and submit a PR, expect it to be in place soon, and hopefully you won't need the workarounds at that point.

shaise commented 2 months ago

Thanks again!