Login  Register

Pseudo scripting with excel - add layer

Next Topic
 
classic Classic list List threaded Threaded
11 messages Options Options
Embed post
Permalink
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Pseudo scripting with excel - add layer

Goran
5 posts
Hello,
I made a rather complex script generator in *.xls format for autocad, which functioned in such a way as to create a series of commands that are pasted into the command line using ctrl+c and ctrl+v and generate the desired design.
After a while I came across librecad and realized that librecad can import a text file with a set of commands
I "translated" the instruction sets so that the commands are understandable in librecad.
7-script.txt

I have attached an example of such a generated draft:
3-clmn_exmpl.dxf

 My problem is that I use 5 different layers for drawing. Therefore, I have to repeat this procedure 5 times. Is it possible to set from the script itself that the drawing is done in layer 1, then in layer 2, etc... and I can later adjust the layer properties (color, line thickness, etc.)


(I use the 'Read ASCII points' plugin to generate text.)

Best Regards

Linux MINT

Version: 2.2.0.2-14-g10ad9444
Compiler: GNU GCC 9.4.0
Compiled on: Jun  4 2024
Qt Version: 5.12.9
Boost Version: 1.75.0
System: Linux Mint 20.3



Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Pseudo scripting with excel - add layer

dxli
1982 posts
All available commands are defined here:

https://github.com/LibreCAD/LibreCAD/blob/master/librecad/src/cmd/lc_commandItems.h

The best way is to add a command to add layer.

It appears that we should add more reasonable commands for macro command usages.



Goran wrote
Hello,
I made a rather complex script generator in *.xls format for autocad, which functioned in such a way as to create a series of commands that are pasted into the command line using ctrl+c and ctrl+v and generate the desired design.
After a while I came across librecad and realized that librecad can import a text file with a set of commands
I "translated" the instruction sets so that the commands are understandable in librecad.
7-script.txt

I have attached an example of such a generated draft:
3-clmn_exmpl.dxf

 My problem is that I use 5 different layers for drawing. Therefore, I have to repeat this procedure 5 times. Is it possible to set from the script itself that the drawing is done in layer 1, then in layer 2, etc... and I can later adjust the layer properties (color, line thickness, etc.)


(I use the 'Read ASCII points' plugin to generate text.)

Best Regards

Linux MINT

Version: 2.2.0.2-14-g10ad9444
Compiler: GNU GCC 9.4.0
Compiled on: Jun  4 2024
Qt Version: 5.12.9
Boost Version: 1.75.0
System: Linux Mint 20.3
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Pseudo scripting with excel - add layer

Goran
5 posts
Thank you for our answer, but....
dxli wrote
All available commands are defined here:

https://github.com/LibreCAD/LibreCAD/blob/master/librecad/src/cmd/lc_commandItems.h

The best way is to add a command to add layer.

It appears that we should add more reasonable commands for macro command usages.
.... I  don't know how to do that!

 Who can explain or help me with this?

Best regards
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Pseudo scripting with excel - add layer

dxli
1982 posts
Sorry. My message was only intended to explain the situation, and the suggestions are for developers.

As an open source project, the available development time is always the major limit.

I am currently busy something work-in-progress. Either, I can do the adding layer command, or sand1024 can add this one. Of course, any new feature goes to the development branch, not the stable releases.


Goran wrote
Thank you for our answer, but....
dxli wrote
All available commands are defined here:

https://github.com/LibreCAD/LibreCAD/blob/master/librecad/src/cmd/lc_commandItems.h

The best way is to add a command to add layer.

It appears that we should add more reasonable commands for macro command usages.
.... I  don't know how to do that!

 Who can explain or help me with this?

Best regards
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Pseudo scripting with excel - add layer

sand1024
113 posts
@dxli
Yes, I've also considering adding something similar regarding commands and support of pseudo-macros.

My idea was slightly extend the existing commands and the lack of layer creation/activation is important there.  Also, what might be promising - is generation of the script needed for creation of entities based on existing drawing/selection (a kind of macros).  

Together with support of variables, that will let to create interesting and useful use cases.  And if it will be possible to run such scripts via command line - this feature may increase automation capabilities.

I've planned to add this slightly later, as so far I have just generic rough idea of how such the set of commands that may expand the existing one may looks like.  

However, as a quick fix for now - I could just add command for setting specified layer as a current one.  

@Goran
If you have any ideas regarding support of such kind of scripting based on your experience - please share them.
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Pseudo scripting with excel - add layer

Goran
5 posts
Hello sand1024
sand1024 wrote
@dxli
.....
However, as a quick fix for now - I could just add command for setting specified layer as a current one.  

@Goran
If you have any ideas regarding support of such kind of scripting based on your experience - please share them.
In my experience, besides the ability to create a new layer, one of the essential commands is the command 'last',
which is used to select the last used or drawn entity.

Also, it would be very useful to use the Move/Copy command from the command line to create multiple copies,
something like a rectangular array in AutoCAD. Here's an example of using a script behind AutoCAD:

(command) _pline 31,2480 @0,330
(command) -array last R 1 2 18
(command)

The command '-array' creates an array of copies of the last drawn object.
'last' means that the array is created based on the last selected object.
'R' indicates a rectangular array.
'1 2' means the array has 1 row and 2 columns.
'18' represents the spacing between the array elements.

A line command like 'mv last R 1 10 18' would be desirable, meaning 'copy in one row,
10 copies of the last drawn entity at a spacing of +18 units in which the drawing is made.'
Another variation would be 'mv last R 1 10 -18', meaning 'copy 1 rows, 10 copies of the last
 drawn entity at a spacing of -18 units in which the drawing is made.' There could also be an
option like 'mv R -1 10 -18'.
Additionally, it would be convenient if a user coordinate system could be created.
The script always draws from the 0,0 coordinates, and it would be desirable for 0,0 to be
 repositioned by the user without having to move all the elements in the drawing.

My experience is that all the 'dirty work' of calculations can be done in Excel,
or even better in LibreOffice Calc, and that this approach can produce quite powerful
 parametric scripts for drawing highly complex designs!

Best Regards, Goran
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Pseudo scripting with excel - add layer

sand1024
113 posts
oh, I see - these are good points indeed.  

And what is the main purpose of the "last" - just making several copies? Or something else is possible?  
So far I hardly can imagine other applications than creation of array. Basically, if I'm correct - the "move" command you've described - is just an option to specify the array, right?

As for moving coordinates - I got it - yes, it will be easy to add as we have UCS now in 2.2.2. Good point, I'll add a command for setting it.

>My experience is that all the 'dirty work' of calculations can be done in Excel,

Yes, but in addition to this I've also considering something like setting variables in script and referring them as part of command attributes. For example, some length, radiuses, coordinates may be a good candidates for such variables.  But for sure they may be pre-calculated earlier, so resulting script to execute may contain values only.
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Pseudo scripting with excel - add layer

Goran
5 posts
sand1024 wrote
....And what is the main purpose of the "last"....
"last" - mean select last entity - line, polyline etc.... yes, it's useful for copy in first place, but you can, for example, insert block reference, and run script -> select last block entity, copy on desired position, select last and rotate, select last and.....do something else what you need.

sand1024 wrote
> ...if I'm correct - the "move" command you've described - is just an option to specify the array, right? ...<
"Yes, I think this command has all the prerequisites to be used for "array". In my opinion, it would only be necessary to adjust the call, that is, the way it can be called from the command line or from a script."

sand1024 wrote
>I've also considering something like setting variables in script and referring them as part of command attributes...<
 

What just came to mind is something that might be handy for non-programmers like me. Is it possible to create reserved variables at the project file level, named like var1, var2, var3, ..., var99? These variables would be used for interaction between a script and the current drawing/draft.

Example:
I want to draw a rectangle using a script by selecting two points that are opposite corners of the rectangle. Variables var1 and var2 would store the (x, y) coordinates of the first corner, and var3 and var4 would store the (x, y) coordinates of the opposite corner. Additionally, var3 could, for example, represent an offset for an inner rectangle, which I could set by typing a value into the command line.

Is something like this even possible? Please be gentle—keep in mind you’re talking to someone who isn’t a programmer. My questions might be unrealistic! 😊
Best regards, Goran
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Pseudo scripting with excel - add layer

sand1024
113 posts
>"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.html
3) 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.







Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Pseudo scripting with excel - add layer

Goran
5 posts
Thank you for your time and effort!
I will try to answer your questions.
sand1024 wrote
    Actually, by "last" - it is possible either to consider the entity that was created last. OR - it might be the entity that was last in user's operations i.e. - last selected, last edited... (say, editing, moving etc)

So this is a good question: what should be defined by "last".
The "last" command belongs to the selection category.
The original definition of the "last" command is: "Selects the most recently created visible object. The object must be in the current space (model space or paper space), and its layer must not be frozen or turned off."

However, considering the last edited, moved, etc. entity would likely be more practical.
sand1024 wrote
    Another thing - is the scope of this command. ...

However, the question of scope arises - in other words, what is the lifetime of the "last" and such entities.

If they exist only within the lifecycle of the command script being executed (accessible only by commands in the same script file) - implementation is straightforward, though I'm unsure if this is convenient.

If they could be shared between script files - this might cause confusion, be harder to implement, and I’m not convinced it’s necessary. Please share your thoughts.
IMHO, "last" is a temporary command for short-term use. As a script creator, I’m almost always focused on the last created entity. Everything else might be too complicated to implement.
sand1024 wrote
 > Is it possible to create reserved variables at the project file level

Well, I suggest reviewing these resources:

    MuParser (used by the command line widget):
    https://beltoforion.de/en/muparser/features.php (see "User-defined variables").

    LibreCAD Calculator Documentation:
    https://docs.librecad.org/en/latest/appx/calculator.html

    Check "Application Preferences" → Paths → Variable file.

This should align closely with your needs.
Thank you for your suggestions! I’ll experiment with variables.

Personally, the most important features for me are implementing "change current layer to layer X" or "Add new Layer" as script commands (in the command line).
 
Best regards, Goran
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Pseudo scripting with excel - add layer

dxli
1982 posts
Just one more direction:

Please have a look at emanuel's work on scripting:

https://forum.librecad.org/VIDEO-progress-scripting-td5726821.html

He is working (independently and intrepidly) to grow LibreCAD into a scripting CAD.

I have a dream. Some day, LibreCAD can be a Web CAD.

Goran wrote
Thank you for your time and effort!
I will try to answer your questions.
sand1024 wrote
    Actually, by "last" - it is possible either to consider the entity that was created last. OR - it might be the entity that was last in user's operations i.e. - last selected, last edited... (say, editing, moving etc)

So this is a good question: what should be defined by "last".
The "last" command belongs to the selection category.
The original definition of the "last" command is: "Selects the most recently created visible object. The object must be in the current space (model space or paper space), and its layer must not be frozen or turned off."

However, considering the last edited, moved, etc. entity would likely be more practical.
sand1024 wrote
    Another thing - is the scope of this command. ...

However, the question of scope arises - in other words, what is the lifetime of the "last" and such entities.

If they exist only within the lifecycle of the command script being executed (accessible only by commands in the same script file) - implementation is straightforward, though I'm unsure if this is convenient.

If they could be shared between script files - this might cause confusion, be harder to implement, and I’m not convinced it’s necessary. Please share your thoughts.
IMHO, "last" is a temporary command for short-term use. As a script creator, I’m almost always focused on the last created entity. Everything else might be too complicated to implement.
sand1024 wrote
 > Is it possible to create reserved variables at the project file level

Well, I suggest reviewing these resources:

    MuParser (used by the command line widget):
    https://beltoforion.de/en/muparser/features.php (see "User-defined variables").

    LibreCAD Calculator Documentation:
    https://docs.librecad.org/en/latest/appx/calculator.html

    Check "Application Preferences" → Paths → Variable file.

This should align closely with your needs.
Thank you for your suggestions! I’ll experiment with variables.

Personally, the most important features for me are implementing "change current layer to layer X" or "Add new Layer" as script commands (in the command line).
 
Best regards, Goran