External Spreadsheets Macro

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
turoj
Posts: 33
Joined: Wed Mar 22, 2023 6:57 pm

External Spreadsheets Macro

Post by turoj »

Macro that provides live/dynamic reloading of external spreadsheets in FreeCAD.

Reasons to maybe use:
  • May improve spreadsheet-driven modeling by using external spreadsheet editors with more functionality/stylizing/etc.
  • Auto alias feature.
  • Alternative solution for "Complex models and recomputes"
Before Using:
  • Only works with spreadsheets in text formats: tsv & csv.
  • Only tested with FreeCAD 0.20.2 on Linux using Python 3.10.9
Known Dependencies: Example Usage:
  • Create/Save FreeCAD document.
  • Create/Save external spreadsheet (ending with '.tsv'/'.csv') in a folder called 'tsv'/'csv' in the same directory of the FreeCAD document.
  • Run Macro.
  • Change auto alias options if necessary.
  • Every save/change of the external spreadsheet will automatically update FreeCAD's spreadsheet.
Demo Video:
phpBB [video]



Usage Notes:
  • Aliases will be applied to values that start with a digit or start with an equal sign. If you have equations with aliases and want FreeCAD to solve them, start with an equal sign, e.g. ' = OD/2 + offset '
  • If you edit with a text editor, it may modify and replace the file when saving. Watchdog will generate a created event. Change your text editor behaviour. E.g. in Neovim, add this line to its config file: 'autocmd FileType tsv setlocal nowritebackup' (or csv instead of tsv.)
  • Aliases cannot be renamed & moved at the same time, & cells cannot be created or deleted as well. Easier to just remember to save before and after attempting to rename alias(es).
  • External Spreadsheets stops running after the FreeCAD document is closed.

Auto Alias Options:
  1. left->right (default)
  2. top->bottom
  3. table, left_top
alias_options.png
alias_options.png (166.42 KiB) Viewed 1016 times
View or Clone:

Code: Select all

git clone https://git.turoj.xyz/external_spreadsheets.git
Last edited by turoj on Fri Apr 14, 2023 3:23 pm, edited 1 time in total.
turoj
Posts: 33
Joined: Wed Mar 22, 2023 6:57 pm

Re: External Spreadsheets Macro

Post by turoj »

Currently, I use Neovim/Vim with external tsv files with left->right auto aliasing because of:
  • Movement functionality: go to search, next paragraph (blank row), go to bottom, etc
  • Stylizing: custom font size (independent of FreeCAD), easy automatic setting of: background + highlighting + text color + bold + italic
Using Spreadsheet GUI:
before.gif
before.gif (272.58 KiB) Viewed 848 times
Using Macro:
after.gif
after.gif (421.34 KiB) Viewed 848 times
My current Neovim config for .tsv files located at ~/.config/nvim/after/syntax/tsv.vim:

Code: Select all

" custom settings applied to .tsv files only

" max character size of aliases/columns
set tabstop=15

" don't wrap text
set nowrap

" all alphabetic characters
syntax match letters /\a/
hi def letters_style ctermfg=gray
hi link letters letters_style

" all uppercase characters
syntax match upper /\u/
hi def upper_style ctermbg=blue ctermfg=white cterm=underline,bold
hi link upper upper_style

" all digits
syntax match digits /\d/
hi def digits_style cterm=bold
hi link digits digits_style
galou_breizh
Posts: 436
Joined: Wed Sep 15, 2010 9:38 am

Re: External Spreadsheets Macro

Post by galou_breizh »

@turoj Nice macro! The link is broken however.

I invite you to publish your macro to the official macro repository.

Gaël
Post Reply