executing script at terminal command prompt

Discussion forum for contributors and developers who are using the QCAD version 3 ECMAScript development platform or the C++ plugin interface or who are otherwise looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

executing script at terminal command prompt

Postby andrew » Sun Oct 09, 2011 5:56 pm

Alexey wrote in bug tracker FS#305:

Hello. My question is: can I run my script under Linux QCAD using Linux command prompt.
Something like this. Print in terminal: “./qcad myscript.qs” And can the script executing without QCAD GUI? I need to make my drawing by printing specific command in linux command prompt without using GUI. So after script end his work I want to have my drawing at destination directory.

Thank you.
User avatar
andrew
Site Admin
 
Posts: 2544
Joined: Fri Mar 30, 2007 6:07 am

Postby andrew » Sun Oct 09, 2011 5:57 pm

Running a script in QCAD (with GUI):

Code: Select all
./qcad -exec complete/path/to/script.js


Running a script only (no QCAD initialization and no GUI, unless script creates one):

Code: Select all
./qcad -autostart complete/path/to/script.js


This basically replaces the default scripts/autostart.js with any custom script.

Under Mac OS X, one might also want to pass the -command-line-application switch to prevent the application from showing its icon in the dock. This switch has no effect on other platforms.

If you want to allow multiple instances of your application to run simultaneously, use the command line switch -allow-multiple-instances. By default, only one instance of an application can run at a time to prevent a situation in which multiple processes access the same data base, configuration file and other resources.
User avatar
andrew
Site Admin
 
Posts: 2544
Joined: Fri Mar 30, 2007 6:07 am

some troubles

Postby alf2006x » Mon Oct 10, 2011 12:12 pm

Hello, Andrew! Thanks a lot for your reply! But I have got errors during executing script.
I print in my ubuntu terminal this string:
./qcad_demo -autostart '/home/alf3/Downloads/qcad-2.2.2.0-1-demo.linux.x86/scripts/demo01.qs'

but error has become:
RS_FileIO::fileImport: failed to import file: /home/alf3/Downloads/qcad-2.2.2.0-1-demo.linux.x86/scripts/demo01.qs. No filter found.

and also appears qcad main window with warning message:
cannot open the file
home/alf3/Downloads/qcad-2.2.2.0-1-demo.linux.x86/scripts/demo01.qs
please check your access rights, the file format and file extension.

what am i doing wrong? please, help me.
alf2006x
Active Member
 
Posts: 42
Joined: Mon Oct 10, 2011 11:29 am

Postby andrew » Mon Oct 10, 2011 12:16 pm

I was assuming that you are talking about a QCAD 3 Beta installation. QCAD 2 has no such command line options.

QCAD 3 Beta Demo:
http://www.ribbonsoft.com/qcad_downloads.html
-> QCAD 3 Professional Beta 2, Free Trial
User avatar
andrew
Site Admin
 
Posts: 2544
Joined: Fri Mar 30, 2007 6:07 am

pdf

Postby alf2006x » Mon Oct 10, 2011 1:24 pm

can qcad 3 script export drawing to pdf file now?
alf2006x
Active Member
 
Posts: 42
Joined: Mon Oct 10, 2011 11:29 am

Postby andrew » Mon Oct 10, 2011 2:52 pm

Yes, QCAD 3 exposes almost all functionality to the script interface.

Please note that we're in the process of releasing QCAD 3 Beta 3 which will also contain dwg2pdf.sh, a bash script that launches the ECMAScript ./scripts/Tools/Dwg2Pdf/Dwg2Pdf.js. This might be a good starting point for your project.
User avatar
andrew
Site Admin
 
Posts: 2544
Joined: Fri Mar 30, 2007 6:07 am

Postby alf2006x » Mon Oct 10, 2011 7:24 pm

That's looks great! It seems I found what I've looking for a long time.

And how much will be cost QCAD 3 Professional license?
Can i buy it right now?
And one more question: can I use qcad 3 on linux with no any GUI (like GNOME etc.) installed? Just Linux server with NO GRAPHICS. Simple command prompt.

Our project is to make a system, that will collect input data with request form on our site, send it on hosting server and brings to user back drawing of product in PDF format, making on his own parameters.
alf2006x
Active Member
 
Posts: 42
Joined: Mon Oct 10, 2011 11:29 am

Postby andrew » Mon Oct 10, 2011 7:33 pm

alf2006x wrote:That's looks great! It seems I found what I've looking for a long time.

And how much will be cost QCAD 3 Professional license?
Can i buy it right now?


Yes, QCAD licenses are available through our online store at:
http://www.ribbonsoft.com/store/

A single user license is 32 Euros.

alf2006x wrote:And one more question: can I use qcad 3 on linux with no any GUI (like GNOME etc.) installed? Just Linux server with NO GRAPHICS. Simple command prompt.


That's an interesting question. You definitely need those GUI related libraries to be installed that QCAD links against. It's also possible that an X11 server has to be running under Linux. I cannot answer that for sure though. If you have a chance, please try this and report back if possible.

alf2006x wrote:Our project is to make a system, that will collect input data with request form on our site, send it on hosting server and brings to user back drawing of product in PDF format, making on his own parameters.


Sounds interesting. The QCAD ECMAScript interface was designed with such projects in mind.
User avatar
andrew
Site Admin
 
Posts: 2544
Joined: Fri Mar 30, 2007 6:07 am

Postby hungerburg » Tue Oct 11, 2011 12:43 pm

alf2006x wrote:And one more question: can I use qcad 3 on linux with no any GUI (like GNOME etc.) installed? Just Linux server with NO GRAPHICS. Simple command prompt.


Hello Alf, that really looks interesting. While installing X11 should not be a problem, I don't think the qt libraries that qcad links against will do without a DISPLAY available. A quick search turned out among others these relevant, but very old, links:

http://lists.trolltech.com/qt-interest/ ... 032-0.html
http://lists.trolltech.com/qt-interest/ ... 845-0.html
User avatar
hungerburg
Senior Member
 
Posts: 125
Joined: Fri May 28, 2010 7:35 pm

Postby alf2006x » Tue Oct 11, 2011 6:09 pm

andrew, hungerburg, thanks a lot for your respondings!

But my situation is much more tough.
I work in Linux only last week, since we make our desision to start that project. I have never use any NIX-system before.
Anyway I must do this. So I hope you will not leave me along with my task.
alf2006x
Active Member
 
Posts: 42
Joined: Mon Oct 10, 2011 11:29 am

headless QCAD

Postby hungerburg » Fri Oct 14, 2011 12:30 pm

Alf, then you are in for some learning. The technical term for a system as you describe is "headless". In order to test headless QCAD you do not need to set up a computer in this way, all you have to do in a terminal is to clear the DISPLAY variable from the environment, before launching QCAD:

Code: Select all
unset DISPLAY
qcad3 -autostart scripts/date.js


This will produce an error: "qcad-bin: cannot connect to X server", which means, that qcad cannot be run on a headless system, whithout help from Andrew, that is. Start your research here: http://developer.qt.nokia.com/search/tag/headless

Especially, QCAD would need a switch to delay initialization of the X server connection. The question is, how much of the CAD and scripting functionality will be available without that connection. This would also be good for turnaround time, between calling the app and receiving results.

Very likely, there are ways around, eg with xvfb. Refer to this blog post as an example: http://blog.kagesenshi.org/2007/06/runn ... using.html - keep in mind, that if you process requests from anywhere on the web, a setup like this needs to be secured against malicious uses.
User avatar
hungerburg
Senior Member
 
Posts: 125
Joined: Fri May 28, 2010 7:35 pm

Postby andrew » Fri Oct 14, 2011 4:54 pm

QCAD 3 Beta 3 is now available and has a new command line switch to start QCAD without connecting to an X11 server:

Code: Select all
./qcad -h

...
-no-gui             Don't use GUI. X11: don't connect to X11 server.
...


Obviously, only a limited set of the API is available in this mode (no widgets can be created, etc.).
User avatar
andrew
Site Admin
 
Posts: 2544
Joined: Fri Mar 30, 2007 6:07 am

Postby hungerburg » Fri Oct 14, 2011 8:23 pm

I immediately had to try this, and it works. And its FAST -- QCAD rocks!
Code: Select all
:) $ time DISPLAY="" qcad3 -no-gui -autostart scripts/date.js
#77-Ubuntu SMP Tue Sep 13 19:39:17 UTC 2011
x86_64

real   0m0.209s
user   0m0.240s
sys   0m0.000s
:) $

The smileys prompt above come from this .bashrc/.profile command:
Code: Select all
smiley () { if [ $? == 0 ]; then echo ':)';else echo ':(';fi; }
PS1="\$(smiley) $ "

Let's see what remains of the scripting API. Maybe I can dump rhino...
User avatar
hungerburg
Senior Member
 
Posts: 125
Joined: Fri May 28, 2010 7:35 pm

Postby alf2006x » Sun Oct 16, 2011 9:03 pm

Andrew, that is the best news for me! Thank you very very much!
My task becomes easier because I already have working script wich works under Windows and uses Autocad 2010 to make drawings.
All I have to do is scrupulously rewriting my script.

And can you see the list of command, used in my windows script to tell me is every one will work on headless QCAD 3 Beta 3 ? Now I will collect all commands in the list.
alf2006x
Active Member
 
Posts: 42
Joined: Mon Oct 10, 2011 11:29 am

Postby andrew » Mon Oct 17, 2011 10:28 am

alf2006x: The complete API should be available except for anything that requires a QWidget (user interface window on the screen).

I'm also changing the command line tools to use the new -no-gui mode. dwg2pdf.sh works with the following patch applied to EAction.js:

Code: Select all
include("WidgetFactory.js");
include("Plugin.js");
 
-if (new QFileInfo("scripts/Widgets/CadToolBar/CadToolBar.js").exists()) {
+if (new QFileInfo("scripts/Widgets/CadToolBar/CadToolBar.js").exists() &&
+        !QCoreApplication.arguments().contains("-no-gui")) {
     include("Widgets/CadToolBar/CadToolBar.js");
}
User avatar
andrew
Site Admin
 
Posts: 2544
Joined: Fri Mar 30, 2007 6:07 am

Next

Return to QCAD 3 Developers and Contributors

Who is online

Users browsing this forum: No registered users and 0 guests