Posted by
sand1024 on
Apr 02, 2025; 5:29pm
URL: https://forum.librecad.org/Pseudo-scripting-with-excel-add-layer-tp5726798p5726830.html
>"last" - mean select last entity - line, polyline etc...
Well, I see... the only thing there is the scope and definition of last... I feel that there might be more use cases, so that's why I'm asking.
1) Actually, by "last" - it is possible either to consider the entity that was create last. OR - it might be the entity that was last in user's operations i.e. - last selected, last editeid... (say, editing, moving etc)
So this is good question, what should be defined by "last".
2) Another thing - is the scope of this command. Actually, I've considered a bit wider implementation - something like this:
Instead of just using "last", it may be possible to define some kind of named set of entities. Say, via pair command like (just an example)
entities_set "name"
.....
....
end_set.
The idea is just to collect all entities created within such a set and refer them by name.
So, for example, it's possible to create several entities and move them at once (so this approach is similar to operations that supports multiple selection - yet on the command layer).
However, the question of the scope arise - in other words, what is the lifetime of the "last" and such set of entities.
If they will live just within the lifecycle of the commands script that should be executed (so they are accessible only by command of the same script file) - it's quite straightforward to implement, yet I'm not sure whether it's convenient.
If they could be shared between script files - it may lead to confusion, it's harder to implement and I'm not fully sure that this is necessary. So please let me know what do you think of this.
> Is it possible to create reserved variables at the project file level
Well, I suppose you need to read these pieces of documentation:
1) MuParser (used by command line widget)
https://beltoforion.de/en/muparser/features.php - and especially "
User-defined variables."
2)
https://docs.librecad.org/en/latest/appx/calculator.html3) Take a look to the "Application Preferences"->Paths->Variable file
The file denoted by file path in that setting allows to specify a set of variables (well, actually, on the application's init, that file is read and is sent to the command widget as an ordinary script).
But - if there are some variables definitions in that script file, they will be set in the context of the command line widget so it will be possible to refer variable values later.
For sure, using user-defined variables, it is possible to specify coordinate components and later refer them in commands (you can define such variables either via startup script or use them as part of your script file).
I suppose this is close to what you're looking for.
I'd recommend you try to play with variables in command line widget first, and then try to add support of them to your scripts.