Page 2 of 2

Posted: Sun Jan 15, 2012 7:48 pm
by alf2006x
Ok, thanks.

And can I send to my script some parameters through the command line command?
I need to send to my script the path to text file with different parameters.

I mean something like this:
alf@ubuntu:~$ /home/alf/qcad/qcad-trial -no-gui -autostart /home/alf/MyScripts/TestScript2.js -p'/home/alf/MyScripts/params.txt'

, where '-p' is key of parameter for the script

Posted: Sat Jan 21, 2012 5:38 pm
by hungerburg
alf2006x wrote:Ok, thanks.

And can I send to my script some parameters through the command line command?
I need to send to my script the path to text file with different parameters.
There may be better ways, I do it like that:

Code: Select all

$ DISPLAY="" /opt/qcad/qcad -no-gui -allow-multiple-instances -autostart Headless.js presets.txt 2> /dev/null
In Headless.js, the second argument "presets.txt" is available as the value of the global variable "args[1]". The name of the script "Headless.js" is in args[0]. As far as I know, there are no named parameters, only positional ones.

Posted: Mon Jan 23, 2012 9:11 pm
by alf2006x
Thanks a lot, hungerburg.

But that was one part of global question. The issue is to bring to my script an array of parameters from internet user form thru the php script. Our php programmer tells me that this task could be doing by Json format.
Is it good idea? And is it correct solution to begin working this way?

Posted: Tue Jan 24, 2012 12:43 am
by hungerburg
alf2006x wrote:Json format. Is it good idea? And is it correct solution to begin working this way?
JSON is great for transferring data objects. QT script has a built in parser, that is to be secure and robust. I use someting like below:

Code: Select all

/**
 * JSON Datei in Objekt laden.
 * @param {String} fn Datei Pfad und Name
 * @returns {Object} Objekt aus Datei
 */
function fromFile(fn) {
	var fh = new QFile(fn);
	var fi = new QFileInfo(fh);
	if (!fi.exists()) { throw new Error("Preset laden: " + fn + " gibt es nicht"); }
	try {
		var ts, res = "";
		fh.open(QIODevice.OpenMode(QIODevice.ReadOnly, QIODevice.Text));
		ts = new QTextStream(fh);
		ts.setCodec("UTF-8");
		while(!ts.atEnd()) { res += ts.readLine(); }
		return JSON.parse(res);
	} catch (e) {
		throw new Error("Preset laden: " + e.message);
	} finally {
		fh.close();
	}
}
var preset = fromFile("foo.json");

Posted: Tue Jan 24, 2012 5:50 pm
by alf2006x
hungerburg, what IDE (editor, debugger) do you use to write your QCAD scripts?

Posted: Wed Jan 25, 2012 10:39 am
by hungerburg
Alf, I use the free version of komodo edit: it helps with balancing braces and shows many typos, syntax errors etc. It can auto complete functions of my own project, but not the R functions of qcad. It even helps with jsdoc. I use the qcad built in debugger.

Posted: Tue Jan 31, 2012 8:00 pm
by alf2006x
hungerburg, please help!
I can't remove source Entities (lines)
My script is below.
What am I doing wrong? And is it correct way to remove start lines? Or I should use some way "UpdatePreview()" function?

Code: Select all

var Operation = new RAddObjectsOperation();
var DelOperation = new RDeleteObjectsOperation();

var p1 = new RVector(0, 0);
var p2 = new RVector(10, 0);
var p3 = new RVector(5, Math.sin(RMath.deg2rad(60))*10);

var lineentity1 = new RLineEntity(document, new RLineData(p1, p2));
var lineentity2 = new RLineEntity(document, new RLineData(p2, p3));

Operation.addObject(lineentity1);
Operation.addObject(lineentity2);

var success = Round.round(Operation,lineentity1,p1,lineentity2,p3,true,1.5,false);
DelOperation.deleteObject(lineentity1);
DelOperation.deleteObject(lineentity2);

qDebug("lines is rounded: %s", success);

Operation.apply(document);
DelOperation.apply(document);

Posted: Fri Feb 03, 2012 6:38 pm
by hungerburg
hello Alf, I hear you! Please be aware, that my thoughts will be strongly biased.

For various reasons, I advise against sourcing qcad UI related functions in your code, especially if you are developing a console only application. From reading your snippet, I suppose that you want to create two lines that are joined with a rounded corner. The easiest way I imagine is to draw the lines a little short and the joining arc in between. A more general approach probably was, to create a function, that can round any two lines. Probably lift the rounding code from the qcad UI function and wrap it into your own convenience function. Looks like that is what you are doing, though in the way you do it, I cant see, what the UI function does.

Anyway, without running your code, I cannot tell for sure, what is failing, you may have to be more specific.

Posted: Fri Feb 03, 2012 7:59 pm
by alf2006x
Hello, hungerburg. I'm very glad to hear you.

Have you any script that makes some difficult drawing? And if you have one can you show it to me? It is very tough to me to understand how to make the drawing in QCAD. There are very few examples in QCAD documentation.
If you send on alf2006x@yandex.ru any examples I will be very grateful to you.

Posted: Sun Feb 05, 2012 10:21 pm
by hungerburg
Thank you Alf for asking, here to the most tricky piece in all of my qcad scripts, except of course the many spaghetti in some parts ;) See the other thread: http://www.ribbonsoft.com/rsforum/viewt ... =5642#5642