FreeCAD_Assembly4 icon indicating copy to clipboard operation
FreeCAD_Assembly4 copied to clipboard

New features (list and export linked files)

Open leoheck opened this issue 3 years ago • 7 comments

Hey @Zolko-123, I would like to implement these functions in Assembly 4. Do you accept them as a good addition?

  • List Linked files in Console (List and Tree Format) in the same Button
  • Export the Assembly files to a folder, o maybe to a zip file

leoheck avatar Oct 04 '22 13:10 leoheck

List Linked files in Console (List and Tree Format) in the same Button

yes, that's good, but we had something similar already, you should check whether that helps:

def on_button_list_parts(self):            
    self.level = 0
    for obj in App.ActiveDocument.RootObjects:
        if str(obj) == "<Part object>":
            print("Level " + str(self.level) + " Top", str(obj.Label))
            self.find_sub(obj)

def find_sub(self,obj):
    self.level += 1            
    for subobj in obj.OutList:
        if str(subobj) != "<App::Origin object>":
            if str(subobj) == "<Part object>":
                self.space = 2 + self.level
                App.Console.PrintWarning("Level " + str(self.level ) +", " * self.space + str(subobj.Label)+"\n")
                self.find_sub(subobj)
    self.level -= 1        

also, look at the Macro "TreeToAscii" . If I remember right the output was in a text window which is better than the console.

Export the Assembly files to a folder, o maybe to a zip file

that would be very good, yes. SolidWorks has this functionality which is very practical. It might by quite difficult though.

Zolko-123 avatar Oct 04 '22 15:10 Zolko-123

Yesterday I made this function here list/tree. Posted it here. Personally, I feel it looks quite good. Right now it showing the result in the console https://forum.freecadweb.org/viewtopic.php?f=20&t=34806&start=1140#p630370

The code is here (Gist on Github) https://gist.github.com/leoheck/0933ca63db54e2f7f22ada0e2a4f811b

Export the Assembly files to a folder, o maybe to a zip file

that would be very good, yes. SolidWorks has this functionality which is very practical. It might be quite difficult though.

I was thinking this would be easy. Why do you think this would be difficult?

leoheck avatar Oct 04 '22 16:10 leoheck

Why do you think this would be difficult?

only a feeling. Might be wrong though. This might be the case of not seeing the forest because of the tree

Zolko-123 avatar Oct 04 '22 16:10 Zolko-123

I made a quick attempt on this, and here it is. https://github.com/Zolko-123/FreeCAD_Assembly4/pull/370

image

There are 2 buttons to list files, currently in the console (a list of unique and absolute filenames and a tree of relative file paths) There is another button to export a zip, in the current folder. ~The limitation here, to preserve the files' structure and keep the assembly working when unpacked is to keep files under the main assembly folder. It is currently not exporting the package if there are external files.~

It requires

from anytree import Node, RenderTree
from zipfile import ZipFile

Edit: Actually, there is no limitation on files out of the folder. It was a bug in the file path that is fixed already.

leoheck avatar Oct 05 '22 21:10 leoheck

@Zolko-123 do you have a code to share that launches a file browser?

Right now I am hardcoding saving the exported zip in the same directory as the assembly file, but it would be better to present the file browser so the user can tell where it wants the file and its name.

leoheck avatar Oct 10 '22 15:10 leoheck

look in AnimationExportLib

Zolko-123 avatar Oct 10 '22 18:10 Zolko-123

Thank you.

leoheck avatar Oct 10 '22 19:10 leoheck

See #410

Zolko-123 avatar Apr 10 '23 22:04 Zolko-123