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

List and Export linked files #370

Closed
wants to merge 16 commits into from

Conversation

leoheck
Copy link
Contributor

@leoheck leoheck commented Oct 5, 2022

This is an attempt to list unique linked files of the assembly.
I also export files into a zip package with the name of the file + asm4_zip in the assembly folder.

@hasecilu
Copy link
Contributor

hasecilu commented Oct 5, 2022

I tried to load the changes but no icons are loaded in the WB, there is something in InitGui.py that breaks it.
Edit: ok, I'll check it but i have a problem with dependencies

@leoheck
Copy link
Contributor Author

leoheck commented Oct 6, 2022

Thanks. It happens that Freecad has a different file path for the file being loaded when using the GUI and the CLI. I improved the behavior of the zip exporter.

Now, I don't have issues with InitGui.py
Could you check if your copy it is updated and does not have changes?

@hasecilu
Copy link
Contributor

hasecilu commented Oct 6, 2022

Is anytree, I have it in my system but not in FreeCAD's enviroment

@leoheck
Copy link
Contributor Author

leoheck commented Oct 6, 2022

Did you do/try this?

sudo -H pip install anytree

@leoheck
Copy link
Contributor Author

leoheck commented Oct 6, 2022

I installed it this way and it was working.

@hasecilu
Copy link
Contributor

hasecilu commented Oct 6, 2022

Ok, I solved it copying the anytree folder to the A4 folder.

The icon of List Linked Files is white/light gray and very similiar the the BOM buttons, maybe change to a similar color as List Linked Files (Tree) to have them "grouped" visually? Both commands work fine. There are typos in the svg files they say: Liked.

I got some errors with Export FIles and I think it's because those files were used more than once in the Assembly, so the function tries to add them again.

13:22:32  ASM4> [ZIP] Adding file: cad/FreeCAD-library/T8_leadscrew/T8_leadscrew_500mm.FCStd
13:22:32  ASM4> [ZIP] Adding file: cad/FreeCAD-library/SHF08/SHF08.FCStd
13:22:32  /snap/freecad-realthunder/70/usr/lib/python3.8/zipfile.py:1517: UserWarning: Duplicate name: 'cad/FreeCAD-library/SHF08/SHF08.FCStd'
  return self._open_to_write(zinfo, force_zip64=force_zip64)
13:22:32  ASM4> [ZIP] Adding file: cad/FreeCAD-library/KFL08/KFL08.FCStd
13:22:32  /snap/freecad-realthunder/70/usr/lib/python3.8/zipfile.py:1517: UserWarning: Duplicate name: 'cad/FreeCAD-library/KFL08/KFL08.FCStd'
  return self._open_to_write(zinfo, force_zip64=force_zip64)
13:22:32  ASM4> [ZIP] Adding file: sub-assemblies/Electronics.FCStd
13:22:32  ASM4> [ZIP] Adding file: cad/Board4electronics.FCStd
13:22:32  ASM4> [ZIP] Adding file: cad/step/Arduino_CNC_shield.FCStd
13:22:32  ASM4> [ZIP] Adding file: cad/step/Fuente_12V_10A.FCStd
13:22:32  ASM4> [ZIP] Adding file: cad/FreeCAD-library/Slot_T_nuts/Slot_T_nuts.FCStd
13:22:32  /snap/freecad-realthunder/70/usr/lib/python3.8/zipfile.py:1517: UserWarning: Duplicate name: 'cad/FreeCAD-library/Slot_T_nuts/Slot_T_nuts.FCStd'
  return self._open_to_write(zinfo, force_zip64=force_zip64)
13:22:32  ASM4> [ZIP] Adding file: cad/Spacer_20.FCStd
13:22:32  ASM4> [ZIP] Adding file: sub-assemblies/SW_X.FCStd
13:22:32  ASM4> [ZIP] Adding file: cad/step/Limit_SW_PCB.FCStd
13:22:32  /snap/freecad-realthunder/70/usr/lib/python3.8/zipfile.py:1517: UserWarning: Duplicate name: 'cad/step/Limit_SW_PCB.FCStd'
  return self._open_to_write(zinfo, force_zip64=force_zip64)
13:22:32  ASM4> [ZIP] Adding file: sub-assemblies/Green.FCStd
13:22:32  ASM4> [ZIP] Adding file: cad/FDM/Light.FCStd
13:22:32  ASM4> [ZIP] Adding file: cad/step/Green_indicator.FCStd
13:22:32  ASM4> [ZIP] Adding file: cad/FreeCAD-library/NEMA/NEMA_17_with_connector.FCStd
13:22:32  ASM4> [ZIP] Adding file: cad/Steel L-Bracket for NEMA 17.FCStd
13:22:32  /snap/freecad-realthunder/70/usr/lib/python3.8/zipfile.py:1517: UserWarning: Duplicate name: 'cad/Steel L-Bracket for NEMA 17.FCStd'
  return self._open_to_write(zinfo, force_zip64=force_zip64)
13:22:32  ASM4> [ZIP] Adding file: cad/FDM/NEMA17_support.FCStd
13:22:32  ASM4> [ZIP] Adding file: cad/FreeCAD-library/Coupling/Beam-coupling-8mm-5mm.FCStd
13:22:32  /snap/freecad-realthunder/70/usr/lib/python3.8/zipfile.py:1517: UserWarning: Duplicate name: 'cad/FreeCAD-library/Coupling/Beam-coupling-8mm-5mm.FCStd'
  return self._open_to_write(zinfo, force_zip64=force_zip64)
13:22:32  ASM4> [ZIP] Adding file: sub-assemblies/3D-printed_corner.FCStd
13:22:32  ASM4> [ZIP] Adding file: cad/FDM/Big_Corner/Big_Corner.FCStd
13:22:32  ASM4> [ZIP] Adding file: cad/FreeCAD-library/Slot_T_nuts/Slot_T_nuts.FCStd
13:22:32  ASM4> [ZIP] Adding file: sub-assemblies/Bed_full.FCStd
13:22:32  ASM4> [ZIP] Adding file: sub-assemblies/Bed_top.FCStd
13:22:32  ASM4> [ZIP] Adding file: cad/Plate_03.FCStd
13:22:32  ASM4> [ZIP] Adding file: sub-assemblies/Bed_bottom.FCStd
13:22:32  ASM4> [ZIP] Adding file: cad/FreeCAD-library/SK08/SK08.FCStd
13:22:32  ASM4> [ZIP] Adding file: cad/FreeCAD-library/KP08/KP08.FCStd
13:22:32  ASM4> [ZIP] Adding file: cad/8mmx500_rod.FCStd
13:22:32  /snap/freecad-realthunder/70/usr/lib/python3.8/zipfile.py:1517: UserWarning: Duplicate name: 'cad/8mmx500_rod.FCStd'
  return self._open_to_write(zinfo, force_zip64=force_zip64)
13:22:32  ASM4> [ZIP] Adding file: cad/FreeCAD-library/T8_leadscrew/T8_leadscrew_500mm.FCStd
13:22:32  /snap/freecad-realthunder/70/usr/lib/python3.8/zipfile.py:1517: UserWarning: Duplicate name: 'cad/FreeCAD-library/T8_leadscrew/T8_leadscrew_500mm.FCStd'
  return self._open_to_write(zinfo, force_zip64=force_zip64)
13:22:32  ASM4> [ZIP] Adding file: sub-assemblies/SW_Y.FCStd
13:22:32  ASM4> [ZIP] Adding file: cad/FDM/LSW_support_Y.FCStd

@hasecilu
Copy link
Contributor

hasecilu commented Oct 6, 2022

Did you do/try this?

sudo -H pip install anytree

I have just tried this and did not work in both snap and AppImage

@leoheck
Copy link
Contributor Author

leoheck commented Oct 6, 2022

hm, I thought those "UserWarning: Duplicate name:" were just a warning, this may not be the case. They have to be added to preserve the hierarchy when unpacking the zip. I could rename all items before inserting in the package, and then I did not have errors, but this is not the fix since they won't be renamed back to the original when unpacking the zip. I am investigating this thing.

@hasecilu
Copy link
Contributor

hasecilu commented Oct 6, 2022

They still manage to be packed in the zip files, even with the unzip command I get messages asking me to replace the same files.
Screenshot from 2022-10-06 14-26-55

@leoheck
Copy link
Contributor Author

leoheck commented Oct 6, 2022

try to extract it and load the main assembly, please.

@hasecilu
Copy link
Contributor

hasecilu commented Oct 6, 2022

For some reason in the list the googley eyes, Spacer 6.35 and V slot profile 370 mm are not detected and the files are not saved in the zip.

The assembly in the zip file is almost complete but due to above error there are errors about file not found

@leoheck
Copy link
Contributor Author

leoheck commented Oct 6, 2022

It seems there is no duplicated files, only in the zip

Examining this case here:

17:54:17  ASM4> [ZIP] Adding file: cad/Steel L-Bracket for NEMA 17.FCStd
17:54:17  /tmp/.mount_FreeCARwPJVr/usr/lib/python3.10/zipfile.py:1517: UserWarning: Duplicate name: 'cad/Steel L-Bracket for NEMA 17.FCStd'

Then we see that there is only one file with this name:

➜  diy-pcb-cnc git:(testing) ✗ find -name "*Steel L-Bracket for NEMA 17.FCStd*"
./cad/Steel L-Bracket for NEMA 17.FCStd

This is the whole list of files.

17:58:01  ASM4> Listing uniq linked files
17:58:01    1 - ASSembly.FCStd
17:58:01    2 - cad/8mmx300_rod.FCStd
17:58:01    3 - cad/8mmx500_rod.FCStd
17:58:01    4 - cad/Board4electronics.FCStd
17:58:01    5 - cad/CNC_mount/CNC_mount_V2.FCStd
17:58:01    6 - cad/Drill_bit.FCStd
17:58:01    7 - cad/FDM/Big_Corner/Big_Corner.FCStd
17:58:01    8 - cad/FDM/Emergency_button_case.FCStd
17:58:01    9 - cad/FDM/LSW_support_Y.FCStd
17:58:01   10 - cad/FDM/LSW_support_Z.FCStd
17:58:01   11 - cad/FDM/Light.FCStd
17:58:01   12 - cad/FDM/NEMA17_support.FCStd
17:58:01   13 - cad/FreeCAD-library/2020_V-slot_Al_extrusion/2020x450_V_slot_profile.FCStd
17:58:01   14 - cad/FreeCAD-library/2020_V-slot_Al_extrusion/2020x490_V_slot_profile.FCStd
17:58:01   15 - cad/FreeCAD-library/Corner/2020_corner_bracket.FCStd
17:58:01   16 - cad/FreeCAD-library/Coupling/Beam-coupling-8mm-5mm.FCStd
17:58:01   17 - cad/FreeCAD-library/Electrical Switches/EmergencyButton_LAY37.fcstd
17:58:01   18 - cad/FreeCAD-library/KFL08/KFL08.FCStd
17:58:01   19 - cad/FreeCAD-library/KP08/KP08.FCStd
17:58:01   20 - cad/FreeCAD-library/NEMA/NEMA_17_with_connector.FCStd
17:58:01   21 - cad/FreeCAD-library/SC8UU/SC8UU.FCStd
17:58:01   22 - cad/FreeCAD-library/SHF08/SHF08.FCStd
17:58:01   23 - cad/FreeCAD-library/SK08/SK08.FCStd
17:58:01   24 - cad/FreeCAD-library/Slot_T_nuts/Slot_T_nuts.FCStd
17:58:01   25 - cad/FreeCAD-library/T8_housing_bracket/T8_housing_bracket.FCStd
17:58:01   26 - cad/FreeCAD-library/T8_leadscrew/T8_leadscrew_350mm.FCStd
17:58:01   27 - cad/FreeCAD-library/T8_leadscrew/T8_leadscrew_500mm.FCStd
17:58:01   28 - cad/FreeCAD-library/T8_screw_nut/Anti_backlash_nut/T8_antibacklash_nut_simplified.FCStd
17:58:01   29 - cad/Mototool.FCStd
17:58:01   30 - cad/Plate_03.FCStd
17:58:01   31 - cad/Plate_04.FCStd
17:58:01   32 - cad/Plate_05.FCStd
17:58:01   33 - cad/Side_wood.FCStd
17:58:01   34 - cad/Spacer_20.FCStd
17:58:01   35 - cad/Steel L-Bracket for NEMA 17.FCStd <============ THIS ONE
17:58:01   36 - cad/Timing_belt_GT2.FCStd
17:58:01   37 - cad/Timing_pulley_GT2_20.FCStd
17:58:01   38 - cad/Timing_pulley_GT2_60.FCStd
17:58:01   39 - cad/step/Arduino_CNC_shield.FCStd
17:58:01   40 - cad/step/Fuente_12V_10A.FCStd
17:58:01   41 - cad/step/Green_indicator.FCStd
17:58:01   42 - cad/step/Limit_SW_PCB.FCStd
17:58:01   43 - sub-assemblies/3D-printed_corner.FCStd
17:58:01   44 - sub-assemblies/Base.FCStd
17:58:01   45 - sub-assemblies/Bed_bottom.FCStd
17:58:01   46 - sub-assemblies/Bed_full.FCStd
17:58:01   47 - sub-assemblies/Bed_top.FCStd
17:58:01   48 - sub-assemblies/Corner.FCStd
17:58:01   49 - sub-assemblies/Electronics.FCStd
17:58:01   50 - sub-assemblies/Emergency.FCStd
17:58:01   51 - sub-assemblies/Green.FCStd
17:58:01   52 - sub-assemblies/SW_X.FCStd
17:58:01   53 - sub-assemblies/SW_Y.FCStd
17:58:01   54 - sub-assemblies/SW_Z.FCStd
17:58:01   55 - sub-assemblies/Vertical_frame_XZ.FCStd
17:58:01   56 - sub-assemblies/XZ.FCStd
17:58:01   57 - sub-assemblies/Z_axis.FCStd

However, the zip, as you showed, shows it twice
image

@leoheck
Copy link
Contributor Author

leoheck commented Oct 6, 2022

Ah, the list of files I was using did not have unique files. It is fixed now.
Zip is being created. But there are some issues when opening the main assembly file.

@leoheck
Copy link
Contributor Author

leoheck commented Oct 6, 2022

These files are not being restored

Linked file: ../cad/Spacer_6.35.FCStd
Linked file: ../cad/FreeCAD-library/2020_V-slot_Al_extrusion/2020x370_V_slot_profile.FCStd
Linked file: ../cad/Googly_eyes.FCStd 

But they exist

➜  diy-pcb-cnc git:(testing) ✗ find -name Googly_eyes.FCStd
./cad/Googly_eyes.FCStd

➜  diy-pcb-cnc git:(testing) ✗ find -name 2020x370_V_slot_profile.FCStd 
./cad/FreeCAD-library/2020_V-slot_Al_extrusion/2020x370_V_slot_profile.FCStd

➜  diy-pcb-cnc git:(testing) ✗ find -name Spacer_6.35.FCStd
./cad/Spacer_6.35.FCStd

Maybe my parser is not finding them.

@leoheck
Copy link
Contributor Author

leoheck commented Oct 6, 2022

Yeah, they are not in the above list with 57 items.

@leoheck
Copy link
Contributor Author

leoheck commented Oct 6, 2022

Bed_full has spacers
And these are links from links.
I was not expecting nested links yet.
image

@hasecilu
Copy link
Contributor

hasecilu commented Oct 6, 2022

The Import Part from A4 imports the external files as Links and Links have the Element Count property so I changed it and that generates all those sub-links

@leoheck
Copy link
Contributor Author

leoheck commented Oct 6, 2022

I found your Bed_top has issues.
What is the most updated code you have? Is it on master or is it still in the testing branch?

image

@hasecilu
Copy link
Contributor

hasecilu commented Oct 6, 2022

These files are not being restored

Linked file: ../cad/Spacer_6.35.FCStd
Linked file: ../cad/FreeCAD-library/2020_V-slot_Al_extrusion/2020x370_V_slot_profile.FCStd
Linked file: ../cad/Googly_eyes.FCStd 

Those files had the Element Count property used.

@leoheck
Copy link
Contributor Author

leoheck commented Oct 6, 2022

but look what my FC says
image

@leoheck
Copy link
Contributor Author

leoheck commented Oct 6, 2022

There is no linked object
image

@leoheck
Copy link
Contributor Author

leoheck commented Oct 6, 2022

ah, the file is missing, please, check if it was added to the repo.

@hasecilu
Copy link
Contributor

hasecilu commented Oct 6, 2022

It is in the repo but it's not in the zip file

@leoheck
Copy link
Contributor Author

leoheck commented Oct 6, 2022

yeah, I was looking the wrong file, sorry

@leoheck
Copy link
Contributor Author

leoheck commented Oct 9, 2022

@hasecilu took some time but now it exports all files of the main assembly.
Now, considering your repo, if you try to export a sub-assembly. It does not work yet. Some paths need to be manipulated since the current flow only handles nested files/folders and not files and folders that are not inside of the same folder...

An example of that would be Bed_top.FCStd where most of the files come from outside ../cad

@hasecilu
Copy link
Contributor

hasecilu commented Oct 9, 2022

Cool, it's working!

An example of that would be Bed_top.FCStd where most of the files come from outside ../cad

I'm not sure if there are file location guidelines for (sub) assemblies, moving cad inside of sub-assemblies could be a workaround but don´t know if there is a way to move linked files without breaking the links in assemblies.

@leoheck
Copy link
Contributor Author

leoheck commented Oct 10, 2022

I was thinking that I could export the parent folder that has both assembly and its parts.

So if the assembly and related files are like this:

  • myass.FCSd
  • ../partslib/part1.FCstd

Then it would normalize paths, considering the folder that has both (all) the parts.
It may work even if the paths are not related, I guess.

Also, some things to do

  • Improve toolbar images
  • Add a dialog so the user can choose the zip name and path while exporting
  • Allow this to work with any kind of assembly (assemblies that do not have parts nested).

@leoheck
Copy link
Contributor Author

leoheck commented Oct 10, 2022

Hey, @hasecilu now it exports assemblies with files in other folders. So it works with the Bed_top.FCSd the way I was thinking before. And the elegant thing would be to add a symlink to the exported assembly inside the root folder when the main assembly is not in the root folder. I will implement this tomorrow.

@hasecilu
Copy link
Contributor

Tested and working!

And the elegant thing would be to add a symlink to the exported assembly inside the root folder when the main assembly is not in the root folder. I will implement this tomorrow.

Sounds nice, could be useful when a assembly is made of many subassemblies and you need to find the main one.

@leoheck
Copy link
Contributor Author

leoheck commented Oct 10, 2022

I got it working, but it happens that FreeCad can not handle symlinks since the internal links won't be adjusted if a symlink is being used. It could be a bug on Freecad or just something that was not thought of yet.

image

Then since symlink is in another place, the linked files cannot be found anymore.
image

Freecad could identify a symlink is being used to load the file from the original place, instead.

@leoheck
Copy link
Contributor Author

leoheck commented Oct 10, 2022

I've shared this finding here, let's see how your peers are going to react.
https://forum.freecadweb.org/viewtopic.php?f=3&t=72491

@leoheck
Copy link
Contributor Author

leoheck commented Oct 10, 2022

I've pushed the code since it is harmless to the export process.
If the assembly being exported is not in the root path of the zip package, it creates a symlink (you can test it with the Bed_top)
The only issue is that Freecad opens it but the linked files are not in the right place anymore. (this should be fixed on Freecad side, I gues)

@hasecilu
Copy link
Contributor

In Link>Linked object property the path of the file is absolute and depending where you extract the zip file the absolute path of the exported zip file will change.

In my case I extracted in .../DIY-PCB-CNC/sub-assemblies/Bed_top_asm4/ but the symlink is expecting files in another directory .../DIY-PCB-CNC/sub-assemblies/cad/Plate_03.FCStd.

If I extract in: $HOME/Documents/test/Bed_top_asm4 it's expecting files in $HOME/Documents/test/cad/Plate_03.FCStd.

Basically is skipping the Bed_top_asm4 folder which is where the zip file was extracted.

I think the new icons need a color bg, the green and yellow of before were fine.
Screenshot from 2022-10-10 11-41-45

@leoheck
Copy link
Contributor Author

leoheck commented Oct 10, 2022

Ah, I will have to tweak paths a bit. This feedback is what I was expecting, thanks.

The icons are a bit blurry still, I may have to improve them better, just have to learn how. But check this new set for now, please.
image

@hasecilu
Copy link
Contributor

Probably they are blurry because of the icon size, when bigger they look crisper
Screenshot from 2022-10-10 12-35-45

@leoheck
Copy link
Contributor Author

leoheck commented Oct 10, 2022

In my case I extracted in .../DIY-PCB-CNC/sub-assemblies/Bed_top_asm4/ but the symlink is expecting files in another directory .../DIY-PCB-CNC/sub-assemblies/cad/Plate_03.FCStd.

Ah, yes. This is the issue I am talking about.
When you open a symlink, Freecad should follow the link, and then open the original file since it may have Linked files that have hardcoded or fixed paths.

@leoheck
Copy link
Contributor Author

leoheck commented Oct 10, 2022

So the symlink is being created correctly. However, Freecad cannot open it fine, when it has Linked parts. Unless you are talking about a different problem.

@leoheck
Copy link
Contributor Author

leoheck commented Oct 10, 2022

Now the user can select where the zip is exported and how to name it.

@hasecilu
Copy link
Contributor

So the symlink is being created correctly. However, Freecad cannot open it fine, when it has Linked parts. Unless you are talking about a different problem.

It's the same issue. It looks like there is no differentiation between the files:

$ file ass.FCStd
ass.FCStd: symbolic link to subass/ass.FCStd
$ file subass/ass.FCStd
subass/ass.FCStd: Zip archive data, at least v2.0 to extract, compression method=deflate

@leoheck leoheck closed this Feb 22, 2023
@leoheck leoheck deleted the list_linked_files branch May 29, 2023 18:40
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

Successfully merging this pull request may close these issues.

None yet

2 participants