Page 1 of 1
script qcad3 et arguments
Posted: Thu Dec 08, 2011 7:42 pm
by patsol
Bonsoir,
Je voudrais pouvoir passer un argument à un script que je lance en console
j'ai tenté d'utiliser QScriptValue sans succès.
Quelqu'un peut m'aider?
Posted: Thu Dec 08, 2011 7:57 pm
by andrew
Example:
File myscript.js:
Code: Select all
var args = QCoreApplication.arguments();
for (var i=0; i<args.length; i++) {
print("Argument number " + i + ": " + args[i]);
}
Launching the script:
Code: Select all
./qcad -autostart myscript.js somefile.txt -x 400
Output:
Code: Select all
Argument number 0: qcad
Argument number 1: -autostart
Argument number 2: myscript.js
Argument number 3: somefile.txt
Argument number 4: -x
Argument number 5: 400
See also API reference of QCoreApplication.arguments():
http://doc.qt.nokia.com/latest/qcoreapp ... #arguments
Posted: Thu Dec 08, 2011 9:59 pm
by patsol
thank you a lot, super Andrew!
Si j'osais, je demanderais encore comment traiter tous les fichiers d'un répertoire. En gros, l'équivalent de FindFirst...FindNext.
Mais ça serait vraiment abuser!
Merci encore!
PS
Je n'ai pas pu installer QCad3 sur mon Linux courent. Sous Windows, j'ai quelques bugs que je vais essayer de décrire correctement.
Posted: Thu Dec 08, 2011 10:32 pm
by andrew
patsol wrote:Si j'osais, je demanderais encore comment traiter tous les fichiers d'un répertoire.
QDir.entryList(...) (returns file names) or QDir.entryInfoList(...) (returns array of QFileInfo objects):
Code: Select all
// create QDir object that represents a directory:
var dir = new QDir("/Users/andrew");
// get directory listing:
var fileInfos = dir.entryInfoList(
// name filter(s):
["*"],
// we don't want to get information about '.' or '..', we want all directories and all files:
new QDir.Filters(QDir.NoDotAndDotDot, QDir.Dirs, QDir.Files),
// sort by name:
QDir.Name
);
// print some of the available information:
for (var i=0; i<fileInfos.length; i++) {
print(fileInfos[i].fileName(), fileInfos[i].isDir() ? "Directory" : "File", fileInfos[i].size());
}
Output:
Code: Select all
Desktop Directory 612
Documents Directory 238
Downloads Directory 442
mydrawing.dxf File 182074
...
See also:
http://doc.qt.nokia.com/latest/qdir.html#entryList
http://doc.qt.nokia.com/latest/qfileinfo.html
patsol wrote:Sous Windows, j'ai quelques bugs que je vais essayer de décrire correctement.
Please report to our bug tracker if possible (French is fine, we will translate):
http://www.ribbonsoft.com/bugtracker/in ... &project=1
toujours mon script....
Posted: Sat Dec 10, 2011 10:16 am
by patsol
et pour écrire du texte?
vraiment désolé, mais je ne m'en sors pas avec la doc.
Posted: Sat Dec 10, 2011 10:53 am
by andrew
For documentation about creating documents and adding entities, please refer to:
http://www.ribbonsoft.com/doc/qcad/3.0/ ... awing.html
Text entities can be added in the same way as line entities in the examples.
Here's an example for a text entity:
Code: Select all
...
// creating a text entity:
var text = new RTextEntity(document,
new RTextData(
new RVector(10,10), // position
new RVector(10,10), // alignment point
10.0, // height
10.0, // text width (ignored for now)
RS.VAlignTop, // alignments
RS.HAlignCenter,
RS.LeftToRight,
RS.Exact,
1.0, // line spacing factor
"Text string\\PSecond line", // the text
"Arial", // font
false, // bold
false, // italic
0.0, // angle
false // simple text without formatting
)
);
...
Posted: Sat Dec 10, 2011 11:55 am
by patsol
Merci, mais c'est là dessus justement que je buttais:
Code: Select all
<native>(RVector(10, 10, 0) , RVector(10, 10, 0) , 10, 10, 0, 1, 0, 1, 1, 'Text stringPSecond line', 'Arial', false, false, 0, false) at -1
<anonymous>() at scripts/Examples/MathExamples/UcsImport.js:-1
<global>() at -1
113 false // simple text without formatting
Posted: Sat Dec 10, 2011 12:03 pm
by andrew
Please post the complete exception and the relevant code segment, thanks.
Posted: Sat Dec 10, 2011 12:25 pm
by patsol
Code: Select all
Uncaught exception at scripts/Examples/MathExamples/UcsImport/UcsImport.js:113: Error: :-1:-1: RTextData(): no matching constructor found.
<native>(RVector(10, 10, 0) , RVector(10, 10, 0) , 10, 10, 0, 1, 0, 1, 1, 'Text stringPSecond line', 'Arial', false, false, 0, false) at -1
<anonymous>() at scripts/Examples/MathExamples/UcsImport/UcsImport.js:-1
<global>() at -1
113 false // simple text without formatting
en effet, il manquait la premiere ligne!
Code: Select all
// creating a text entity:
var text = new RTextEntity(document,
new RTextData(
new RVector(10,10), // position
new RVector(10,10), // alignment point
10.0, // height
10.0, // text width (ignored for now)
RS.VAlignTop, // alignments
RS.HAlignCenter,
RS.LeftToRight,
RS.Exact,
1.0, // line spacing factor
"Text string\\PSecond line", // the text
"Arial", // font
false, // bold
false, // italic
0.0, // angle
false // simple text without formatting
)
);
Posted: Sat Dec 10, 2011 1:27 pm
by andrew
Sorry, I think this only works with the current development version.
Try this simpler variation:
Code: Select all
var td = new RTextData();
td.setText("My Text");
td.setTextHeight(10.0);
td.setPosition(new RVector(10.0,10.0));
td.setAlignmentPoint(new RVector(10.0,10.0));
// set more attributes...
var text = new RTextEntity(document, td);
Text data attributes are documented at:
http://www.ribbonsoft.com/doc/qcad/3.0/ ... _data.html
résolu
Posted: Sat Dec 10, 2011 2:40 pm
by patsol
Ok Andrew,
Ça me va très bien comme ça.