[Macro] Get an ASCII representation of the model tree

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

[Macro] Get an ASCII representation of the model tree

Post by openBrain »

EDIT : macro has been integrated and is available through addon manager. Have a look at Macro FCTree2Ascii ;) Feedback on this thread.

Hi,

Attached is a macro that outputs an ASCII representation of the model tree.
I use it mainly for documenting models, hence the specific line formatting.
ATM this is a very alpha-state macro thus the ASCII tree is just output to the Report view (and you need to copy-paste it manually for further usage).
Usage : Select in the Tree view the item(s) that you want to get tree as ASCII. If you have several items selected, the macro will consider they are all at the same level (top one) of the output tree.
Typically if you want the whole tree of a document, you have to select all the topmost objects then run the macro.
I think if this macro has interest for others, I could improve it so the ASCII output can be (not exclusive list) :
  • Copied to clipboard
  • Saved to an arbitrary file on the user's computer
  • Recorded in a text file that is embedded in the document (this is available feature in the latest 0.19 releases)
Every feedback welcome.
Attachments
FCTree2Ascii.FCMacro
(588 Bytes) Downloaded 44 times
Last edited by openBrain on Thu Mar 19, 2020 9:12 pm, edited 1 time in total.
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: [Macro] Get an ASCII representation of the model tree

Post by openBrain »

A maybe most user-friendly version that implements a basic UI where you can :
  • Copy the ASCII Tree to UI
  • Save it to a file on your computer
  • Embed it in your model inside a Text document
Attachments
FCTree2AsciiUI.FCMacro
(2.89 KiB) Downloaded 48 times
User avatar
johnwang
Veteran
Posts: 1345
Joined: Sun Jan 27, 2019 12:41 am

Re: [Macro] Get an ASCII representation of the model tree

Post by johnwang »

Wow, that is just what i want now.

I want to output the tree to a text file. The file will be an input file for a fea program.

I'll try it.

Thank you very much.

John
hfc series CAE workbenches for FreeCAD (hfcNastran95, hfcMystran, hfcFrame3DD, hfcSU2 and more)
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: [Macro] Get an ASCII representation of the model tree

Post by openBrain »

johnwang wrote: Mon Feb 24, 2020 2:02 am Wow, that is just what i want now.

I'll try it.

Thank you very much.
You're welcome. Honestly when I posted I had a doubt that someone else could find it useful. :)
This is alpha release so please provide your feedback. ;)
galou_breizh
Posts: 436
Joined: Wed Sep 15, 2010 9:38 am

Re: [Macro] Get an ASCII representation of the model tree

Post by galou_breizh »

openBrain wrote: Wed Feb 19, 2020 9:22 pm Attached is a macro
Thanks for your macro! Do you intend to write a pull request to the official macro repository for this macro (best option) or may I add it?

Thanks,
Gaël
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: [Macro] Get an ASCII representation of the model tree

Post by openBrain »

galou_breizh wrote: Mon Mar 16, 2020 3:57 pm Thanks for your macro! Do you intend to write a pull request to the official macro repository for this macro (best option) or may I add it?
Hi galou, as usual I'd like to get some feedback, then I'll PR it after I write the wiki page and get a conform header. ;)
galou_breizh
Posts: 436
Joined: Wed Sep 15, 2010 9:38 am

Re: [Macro] Get an ASCII representation of the model tree

Post by galou_breizh »

openBrain wrote: Mon Mar 16, 2020 4:03 pm Hi galou, as usual I'd like to get some feedback, then I'll PR it after I write the wiki page and get a conform header. ;)
You're the best!

So, I'll test your macro straight away and provide some feedback!
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: [Macro] Get an ASCII representation of the model tree

Post by openBrain »

galou_breizh wrote: Mon Mar 16, 2020 4:24 pm So, I'll test your macro straight away and provide some feedback!
Please test the UI version (2nd post of the thread). I think this is the one to publish. ;)
galou_breizh
Posts: 436
Joined: Wed Sep 15, 2010 9:38 am

Re: [Macro] Get an ASCII representation of the model tree

Post by galou_breizh »

Nice macro. Works perfectly.

I'd have a stylistic suggestion

Code: Select all

        retn = retn + baseline + " ├ " + obj.Label + " {"+ "".join(filter(str.isalpha, obj.Name)) + "}\n"
        if cnt == len(objs):
            baselinechi = baseline +  "   "
        else:
            baselinechi = baseline + " │ "
Or at least, please add variables for the box drawing characters. Maybe some users have problems with UTF-8 (windows users?) and could set them to the originals '\_' and '|'.

Thanks.
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: [Macro] Get an ASCII representation of the model tree

Post by openBrain »

galou_breizh wrote: Mon Mar 16, 2020 5:02 pm I'd have a stylistic suggestion
Or at least, please add variables for the box drawing characters. Maybe some users have problems with UTF-8 (windows users?) and could set them to the originals '\_' and '|'.
I admit I like the old ASCII style. :)
Attached an updated version with a style selector. ;) I also added a pattern editor so one can customize it (unfortunately custom value isn't saved). Defined variables are in the line edit tooltip. Do you think it's better ?
Attachments
FCTree2AsciiUI.FCMacro
(4.21 KiB) Downloaded 37 times
Post Reply