Macro Creator (feedback wanted)

For general Flowcode discussion that does not belong in the other sections.
mnfisher
Valued Contributor
Posts: 1041
http://meble-kuchenne.info.pl
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 107 times
Been thanked: 538 times

Macro Creator (feedback wanted)

Post by mnfisher »

Another spin-off from my on-off (mostly) Android FC Viewer/editor project. This runs on Windows...

Inspired by a recent discussion on creating macros for Simulation and ideal for top-down programmers (you DO plan out your program before starting to type??)

The idea - create macros automagically.

Fire up the program and type in Macro names and their Simulation macro equivalents by clicking on the grid (for example Test and TestSim you can use mouse or arrow keys to navigate)

Then click 'Source' and 'Save As' for experimentation I recommend using a empty program as the source (and always save as a new file!)

The program then saves the file with the new macros and their simulation macros created (also exported as downloadable macros & linked in the component configuration)

Note that if no sim macro is specified then just the macro is created (with no sim link/component export) (& vice versa)

Feedback wanted - I've added a column ('locals' which is currently ignored) - and more columns could be added:
1) one idea being to create local variables automatically (for example byte a, uint16 x)
2) provide a way of specifying the 'return' type of the macros (currently set to no return value)
3) provide a way of specifying parameters to the macros
4) A way to save the list of macros (a standard set added to many programs?)
5) A way to add 'body' to macros.

Important - the program doesn't check for duplicated macro names (either in the list or in the source program). Do not be tempted to create files with duplicate macro names - FC doesn't like it...

I've put the title as Macro Magic (oops - already taken) - a better name is needed!
SimMacro.zip
(2.66 MiB) Downloaded 150 times
Martin

stefan.erni
Valued Contributor
Posts: 798
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 157 times
Been thanked: 185 times

Re: Macro Creator (feedback wanted)

Post by stefan.erni »

Hi Martin

Thanks a lot for your ideas.

I don't understand a few things yet.
Why do I need two Macro names?
Why do I need a source, can't I just create macros, that I import later where I need these macros?
Yes, also parameters and returns are absolutely necessary, also with Type Name Description.
For me, description is always important!
proposal:
Source would be an existing macro, that I can load like a template and then edit and save as.
Just load parameters, constants, variables, returns , body, but ignore the rest(icons)
5) A way to add 'body' to macros. Yes please :)

What about macro-editor or macro-header as name?

regards

Stefan

mnfisher
Valued Contributor
Posts: 1041
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 107 times
Been thanked: 538 times

Re: Macro Creator (feedback wanted)

Post by mnfisher »

Hi Stefan,

Thanks for the input:

'Source' is needed as the output is a complete .fcfx file - and adding to an existing file is easier than creating the whole one from scratch (it also allows macros to be added to an existing program file)

Two macro names - this allows a 'simulation/scada' version (if needed) (I did wonder about just auto-appending 'Sim' if the user requested a sim mode)

I think the parameters would be fairly easy to add - but how would you like them defined (for exampled flowcode recognises u8, s8, u16, s16 etc)
So 'u8 x' or 'byte x'
Local variable - as per parameters ?
Return type - again I'd probably aim to use the 'human readable' names (and just a column 'return' with a drop down selector or 'user typed')

Description is easy to add..

Body - - perhaps filename macro.fcm (as a column) - I'd intended this as a fast setup for new projects so I'm not sure how useful this would be - but certainly possible.

Martin

stefan.erni
Valued Contributor
Posts: 798
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 157 times
Been thanked: 185 times

Re: Macro Creator (feedback wanted)

Post by stefan.erni »

Hi Martin

What about you add a source.fcsx and source.fcfx in your programfolder write protected
and save it as a new renamed fcsx or fcfx with the includet macro?

There is a Auto Documentation included in Flowcode under File/export
You can use this format just add Value and init value (maybe this can also be changed in the Auto Documentation)

regards

Stefan
Auto-Doku_2021-04-09_10-42-55.png
Auto-Doku_2021-04-09_10-42-55.png (97.92 KiB) Viewed 4146 times

stefan.erni
Valued Contributor
Posts: 798
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 157 times
Been thanked: 185 times

Re: Macro Creator (feedback wanted)

Post by stefan.erni »

Hi Martin

If i write a lot of macros i lose the overview.
But when I export the macros (all at once) and then import (all at once) into a new, empty project
and starting the automatic documentation I already have an HTML file, for example as a catalog of all of my macros.
If your magic macro tool is based on this format i think i could plan my macros better right from the start
regards

Stefan
export_import_2021-04-09_16-08-05.png
export_import_2021-04-09_16-08-05.png (209.06 KiB) Viewed 4139 times
here a html docoment from the automatic documentatio as a sample

stefan.erni
Valued Contributor
Posts: 798
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 157 times
Been thanked: 185 times

Re: Macro Creator (feedback wanted)

Post by stefan.erni »

with picture....
FC_9_demo_macroHTML_and_jpg.zip
(379.64 KiB) Downloaded 153 times

mnfisher
Valued Contributor
Posts: 1041
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 107 times
Been thanked: 538 times

Re: Macro Creator (feedback wanted)

Post by mnfisher »

Not sure it would be easy to add that level of detail... Will think on it.

Just managed a couple of tweaks this evening...

Now has a return type for macros (these are as per flowcode - leave blank for none (or indeed anything that doesn't match one of the other types - so null would be fine)
Types are none, bool or boolean, byte, int, uint, long, ulong, float, string and handle.
These are all handled correctly (string is a little more involved than the others)

Description - added to macro definition. If the macro is a simulation macro then '(sim)' is appended to the description.

One oddity - it only seems to work 'once' without a restart or file -> new ?
SimMacro.zip
(2.66 MiB) Downloaded 143 times
Martin

stefan.erni
Valued Contributor
Posts: 798
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 157 times
Been thanked: 185 times

Re: Macro Creator (feedback wanted)

Post by stefan.erni »

Hi Martin

You idea looks good. But i can not create a macro with the actual version.
Do you know why your table in the SimMacro is not excel compatible? Otherwise I could manage all the macros names and the variables in excel and then copy - past. Sometimes i like copy paste

regards

Stefan

mnfisher
Valued Contributor
Posts: 1041
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 107 times
Been thanked: 538 times

Re: Macro Creator (feedback wanted)

Post by mnfisher »

Loading Excel files is probably beyond the scope of this project..
CSV files would certainly be possible - and just had a play and can get 'cut & paste' working okay too (pasting from an Excel sheet with the 'expected' layout...)

I've also fixed (though not yet posted) the problem that stopped a set of macros being added to multiple programs. Struggling to get my head around adding code to either a template (on clicking save) or to a file (clicking source) - just the way it was structured seems to makes it difficult :(
The posted version works okay (within it's constraints & with minimal (read no) error checking) (Stefan - did you get it to work in this version - I've downloaded the file and it 'seems' ok) - though it sometimes does odd things to the FC layout (just had 'project explorer' closed and oscilloscope opened?) Perhaps someone at Matrix could help by explaining the layout data in the fcfx file?

I think I'll add 'paste' and '.fcm' body functionality next and then rest it a while....

Martin

mnfisher
Valued Contributor
Posts: 1041
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 107 times
Been thanked: 538 times

Re: Macro Creator (feedback wanted)

Post by mnfisher »

So I added cut and paste...

If you have some macro details in Excel - you can select copy and paste....
FC__00050.jpg
FC__00050.jpg (13.56 KiB) Viewed 4060 times
Select a cell (note don't be 'editing' the cell) and ctrl->v
FC__00051.jpg
FC__00051.jpg (18.86 KiB) Viewed 4060 times
Then source and Save As - as before...
mm cut and paste.zip
(2.88 MiB) Downloaded 164 times
Allowing this actually reduced the program size by about 15% - it's now only 40 events!

Martin

Post Reply