[Macro] Get an ASCII representation of the model tree

Need help, or want to share a macro? Post here!
openBrain
Posts: 5899
Joined: Fri Nov 09, 2018 5:38 pm

[Macro] Get an ASCII representation of the model tree

Postby openBrain » Wed Feb 19, 2020 9:22 pm

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 28 times
Last edited by openBrain on Thu Mar 19, 2020 9:12 pm, edited 1 time in total.
openBrain
Posts: 5899
Joined: Fri Nov 09, 2018 5:38 pm

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

Postby openBrain » Sat Feb 22, 2020 8:28 pm

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 28 times
User avatar
johnwang
Posts: 681
Joined: Sun Jan 27, 2019 12:41 am

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

Postby johnwang » Mon Feb 24, 2020 2:02 am

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
Posts: 5899
Joined: Fri Nov 09, 2018 5:38 pm

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

Postby openBrain » Mon Feb 24, 2020 10:11 am

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: 362
Joined: Wed Sep 15, 2010 9:38 am

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

Postby galou_breizh » Mon Mar 16, 2020 3:57 pm

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
Posts: 5899
Joined: Fri Nov 09, 2018 5:38 pm

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

Postby openBrain » Mon Mar 16, 2020 4:03 pm

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: 362
Joined: Wed Sep 15, 2010 9:38 am

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

Postby galou_breizh » Mon Mar 16, 2020 4:24 pm

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
Posts: 5899
Joined: Fri Nov 09, 2018 5:38 pm

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

Postby openBrain » Mon Mar 16, 2020 4:28 pm

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: 362
Joined: Wed Sep 15, 2010 9:38 am

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

Postby galou_breizh » Mon Mar 16, 2020 5:02 pm

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
Posts: 5899
Joined: Fri Nov 09, 2018 5:38 pm

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

Postby openBrain » Mon Mar 16, 2020 6:45 pm

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 21 times