Dear Support
I'm using QCAD 3.24 professional in Windows. I'm creating a CLI script, that ideally can interact with a session and take stdin command prompts.
The reason for this because loading the qcad executable every time I want to run the same script is slow about 0.5 sec, so I would like to keep QCAD session open and run the script in different documents.
Best Regards
Daniel Hung
How do I run a script that takes stdin commands
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files and screenshots.
Post one question per topic.
-
- Junior Member
- Posts: 10
- Joined: Thu Nov 14, 2019 4:15 pm
Re: How do I run a script that takes stdin commands
The easiest way to communicate with a running instance of QCAD is to start another instance of QCAD and pass some arguments.
For example:
1. Run QCAD and let it running
2. On a command line, run QCAD again with parameters.
Examples
This will open a file in the running instance of QCAD:
This will run a scripts in the running instance:
For example, to trigger File > Open:
Alternatively, you could also create a script that listens on stdin for input and create some kind of a protocol to communicate with QCAD.
For example:
1. Run QCAD and let it running
2. On a command line, run QCAD again with parameters.
Examples
This will open a file in the running instance of QCAD:
Code: Select all
qcad.exe somefile.dxf
Code: Select all
qcad.exe -exec script.js
Code: Select all
qcad.exe -exec scripts/File/OpenFile/OpenFile.js
-
- Junior Member
- Posts: 10
- Joined: Thu Nov 14, 2019 4:15 pm
Re: How do I run a script that takes stdin commands
Dear support
But all this is provided that qcad is a run as a full foreground application, like running the program as "C:\\Program Files\\QCAD\\qcad.exe" which would launch the gui.
if I run QCAD as "C:\\Program Files\\QCAD\\qcad.exe" -platform offscreen -no-gui your suggestion doesn't seem to work?
I want to wrap this in a Python script and run it as a fully automated background process.
Best Regards
Daniel Hung
But all this is provided that qcad is a run as a full foreground application, like running the program as "C:\\Program Files\\QCAD\\qcad.exe" which would launch the gui.
if I run QCAD as "C:\\Program Files\\QCAD\\qcad.exe" -platform offscreen -no-gui your suggestion doesn't seem to work?
I want to wrap this in a Python script and run it as a fully automated background process.
Best Regards
Daniel Hung
Re: How do I run a script that takes stdin commands
-no-gui can be used for command line tools only, for example:daniel_frac wrote: ↑Mon Jan 27, 2020 4:10 pmif I run QCAD as "C:\\Program Files\\QCAD\\qcad.exe" -platform offscreen -no-gui your suggestion doesn't seem to work?
Code: Select all
qcad.exe -no-gui -autostart mycommandlinetoolscript.js
https://qcad.org/en/tutorial-command-line-tool-scripts
It does not make sense to start the QCAD application itself without a GUI, as QCAD is an interactive GUI application that cannot run without GUI. With -autostart you can provide an alternative script as application to launch. Perhaps, you can do this with your own scripts instead of keeping a QCAD instance open. It all depends much on your use case and the type of scripts you are implementing.
-
- Junior Member
- Posts: 10
- Joined: Thu Nov 14, 2019 4:15 pm
Re: How do I run a script that takes stdin commands
Hi
Yeah that's exactly what I do. In fact my launch script code is:
qcad.exe -platform offscreen -no-gui -allow-multiple-instances -quit -ignore-script-files -autostart myscript.js
The problem is that even with -ignore-script-files it seem to take 0.5 sec to load every instance of the execution. I have -allow-multiple-instances to permit parallel execution but to scale I will relying in hardware rather than optimise my workflow from the software side, which is what I want.
What do you mean by this?
"Perhaps, you can do this with your own scripts instead of keeping a QCAD instance open. It all depends much on your use case and the type of scripts you are implementing."
Can I create a js script that uses stream pipes? If that's the case I'm happy to interact with the executed script by qcad, but as far as I can tell that cannot be done with the ECMAscript implementation provided by QCAD.
I do wrap the whole process in python using a subprocess library, which allows for pipe workflows but the application that I'm running needs to support it (pipes) on the first place.
Best Regards
Daniel Hung
Yeah that's exactly what I do. In fact my launch script code is:
qcad.exe -platform offscreen -no-gui -allow-multiple-instances -quit -ignore-script-files -autostart myscript.js
The problem is that even with -ignore-script-files it seem to take 0.5 sec to load every instance of the execution. I have -allow-multiple-instances to permit parallel execution but to scale I will relying in hardware rather than optimise my workflow from the software side, which is what I want.
What do you mean by this?
"Perhaps, you can do this with your own scripts instead of keeping a QCAD instance open. It all depends much on your use case and the type of scripts you are implementing."
Can I create a js script that uses stream pipes? If that's the case I'm happy to interact with the executed script by qcad, but as far as I can tell that cannot be done with the ECMAscript implementation provided by QCAD.
I do wrap the whole process in python using a subprocess library, which allows for pipe workflows but the application that I'm running needs to support it (pipes) on the first place.
Best Regards
Daniel Hung
Re: How do I run a script that takes stdin commands
Yes, that's the recommended way to run a command line tools.daniel_frac wrote: ↑Tue Jan 28, 2020 1:14 pmqcad.exe -platform offscreen -no-gui -allow-multiple-instances -quit -ignore-script-files -autostart myscript.js
Perhaps, you can delete some unused plugins to speed up the execution?
I never had the need to read from stdin in QCAD, sorry. It might not be possible out of the box (i.e. without a C++ plugin providing some interface with stdin).Can I create a js script that uses stream pipes?
-
- Newbie Member
- Posts: 9
- Joined: Sat Nov 19, 2022 3:20 pm
Re: How do I run a script that takes stdin commands
Hello there,
I found a way to implement this. You can create a UNIX socket communication between QCAD and you application trough javascript engine. It allows you to do it. I've done it for my project.
These kinds of stuff more related with QT app engine. It has lots of modules that you can directly use in Javascript engine. FYI.
I found a way to implement this. You can create a UNIX socket communication between QCAD and you application trough javascript engine. It allows you to do it. I've done it for my project.
These kinds of stuff more related with QT app engine. It has lots of modules that you can directly use in Javascript engine. FYI.