[Macro] Get an ASCII representation of the model tree
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
-
- Posts: 437
- Joined: Wed Sep 15, 2010 9:38 am
Re: [Macro] Get an ASCII representation of the model tree
I implemented saving the pattern and the style. There is no need to click on 'Generate' anymore. Please double-check.
Re: [Macro] Get an ASCII representation of the model tree
Thanks for that. Actually I don't really like it for several reasons :galou_breizh wrote: ↑Tue Mar 17, 2020 10:41 am I implemented saving the pattern and the style. There is no need to click on 'Generate' anymore. Please double-check.
- I'm not sure whether macros should authorized themselves to store parameters... But I can trust you on this point
- Parameter will be saved each time the genLine is modified, that's probably stressing the filesystem.
- Tree is updated each time the genLine is modified. That will generate a bunch of errors during writing.
Some more remarks :
- Your code actually doesn't save the style. Probably you forgot a line.
- Your way to get default parameter value is a bit strange. The mechanism already exist. For example instead of g_tree_style = p.GetString('TreeStyle') or 'Modern', you can write g_tree_style = p.GetString('TreeStyle', 'Modern')
What are your thoughts about that ?
- Attachments
-
- FCTree2AsciiUI.FCMacro
- (4.95 KiB) Downloaded 27 times
-
- Posts: 437
- Joined: Wed Sep 15, 2010 9:38 am
Re: [Macro] Get an ASCII representation of the model tree
Why not? This is for user-friendliness.
I don't think so. The filesystem is able to save 4K videos in realtime.
I added the try: ... except: cause and it was catching most such errors.
I'll respect this choice, as the one from the original author.
I indeed did.
Thanks, your way is better. My way is sometimes used in Python, though it's not a typical construct. I actually use the parameter system seldomly.
I think it's a nice macro. I think you can publish it. I "may" change the style a bit, then...
Re: [Macro] Get an ASCII representation of the model tree
Not mine. Also saving video never write twice the same disk area. My concern is more about overwriting the same area again and again.galou_breizh wrote: ↑Tue Mar 17, 2020 1:24 pmI don't think so. The filesystem is able to save 4K videos in realtime.
I think I saw that after I wrote.
I'd like to have community feedback on that so the majority will lead.
Feel free to feedback about coding style before I publish. I sometimes write macros, so better if I conform my coding style to expectations (whether it could be against a standard or specific rules).I think it's a nice macro. I think you can publish it. I "may" change the style a bit, then...
-
- Posts: 437
- Joined: Wed Sep 15, 2010 9:38 am
Re: [Macro] Get an ASCII representation of the model tree
I prefer the classical PEP-8 style. The most important in my opinion are good variable names, i.e. style corresponding to the function (class, function, variable, global vs. local, hidden, ...) and an expressive name. I'll have a look when I find the time.
Re: [Macro] Get an ASCII representation of the model tree
Hi galou. Made a reforging about variable casing and all. Should be better (not perfect yet, I can't dare to have same casing for functions & variables, will come ).galou_breizh wrote: ↑Wed Mar 18, 2020 12:33 pm I prefer the classical PEP-8 style. The most important in my opinion are good variable names, i.e. style corresponding to the function (class, function, variable, global vs. local, hidden, ...) and an expressive name. I'll have a look when I find the time.
Pull request is launched and Macro FCTree2Ascii has been set up.
-
- Posts: 437
- Joined: Wed Sep 15, 2010 9:38 am
Re: [Macro] Get an ASCII representation of the model tree
Integrated, thanks!
-
- Posts: 437
- Joined: Wed Sep 15, 2010 9:38 am
Re: [Macro] Get an ASCII representation of the model tree
I was just thinking about the macro name. What about "TreeToText" rather than "Tree2Ascii". I find "To" nicer than "2" within text and "Text" because this can be Unicode-Art rather than Ascii-Art.
Gaël
Gaël
Re: [Macro] Get an ASCII representation of the model tree
Actually I like the current name (maybe because I chosen it ). But also I'm afraid that changing the name will be painful about changing the header, the wiki and the whole nine yards... So I'm a bit reticent ATM. But if you feel brave enough to do it, feel free to do so.galou_breizh wrote: ↑Thu Mar 19, 2020 9:17 pm I was just thinking about the macro name. What about "TreeToText" rather than "Tree2Ascii". I find "To" nicer than "2" within text and "Text" because this can be Unicode-Art rather than Ascii-Art.
Ken tuch'
Re: [Macro] Get an ASCII representation of the model tree
I think this is really nice, I have been doing this for a while, but by hand. May I suggest some improvements ?
1) Make the spacing 4 spaces wide (not 3)
2) make the branch ├─ and not ├
Code: Select all
line 38:
'Modern' : [' ├─ ', ' │ '], # Unicode U+251C, Unicode U+2502
line 68:
baselinechi = baseline + ' '
3) make the last branch └─ and not ├─
End result would be:
Code: Select all
└─ Model (Model)
├─ Origin (Origin)
│ ├─ X_Axis (X_Axis)
│ ├─ Y_Axis (Y_Axis)
│ ├─ Z_Axis (Z_Axis)
│ ├─ XY_Plane (XY_Plane)
│ ├─ XZ_Plane (XZ_Plane)
│ └─ YZ_Plane (YZ_Plane)
├─ LCS_0 (LCS_0)
├─ Constraints (Constraints)
├─ Variables (Variables)
├─ Sketch_master (Sketch_master)
├─ LCS_arm (LCS_arm)
├─ base (base001)
│ ├─ Origin001 (Origin001)
│ │ ├─ X_Axis001 (X_Axis001)
│ │ ├─ Y_Axis001 (Y_Axis001)
│ │ ├─ Z_Axis001 (Z_Axis001)
│ │ ├─ XY_Plane001 (XY_Plane001)
│ │ ├─ XZ_Plane001 (XZ_Plane001)
│ │ └─ YZ_Plane001 (YZ_Plane001)
│ ├─ LCS_1 (LCS_1)
│ └─ Body (Body)
│ ├─ Origin004 (Origin004)
│ │ ├─ X_Axis004 (X_Axis004)
│ │ ├─ Y_Axis004 (Y_Axis004)
│ │ ├─ Z_Axis004 (Z_Axis004)
│ │ ├─ XY_Plane004 (XY_Plane004)
│ │ ├─ XZ_Plane004 (XZ_Plane004)
│ │ └─ YZ_Plane004 (YZ_Plane004)
│ ├─ Pad (Pad)
│ │ └─ Sketch (Sketch)
│ ├─ Pad001 (Pad001)
│ │ └─ Sketch001 (Sketch001)
4) if Label and Name are identical, it's useless to print both (it's actual harmful, because it removes the information that the object has NOT been renamed). And according to the Selection View, they output Name (Label), the reverse of this macro.