script qcad3 et arguments

Veuillez poser ici vos questions, vos commentaires, concernant l'utilisation ou les problèmes rencontrés avec QCAD professionnel

Moderators: andrew, J-J

script qcad3 et arguments

Postby patsol » Thu Dec 08, 2011 7:42 pm

Bonsoir,

Je voudrais pouvoir passer un argument à un script que je lance en console
Code: Select all
qcad -autostart MonScript

j'ai tenté d'utiliser QScriptValue sans succès.

Quelqu'un peut m'aider?
patsol
Junior Member
 
Posts: 15
Joined: Wed Nov 30, 2011 1:15 pm

Postby andrew » Thu Dec 08, 2011 7:57 pm

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
User avatar
andrew
Site Admin
 
Posts: 2383
Joined: Fri Mar 30, 2007 6:07 am

Postby patsol » Thu Dec 08, 2011 9:59 pm

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! :wink:
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.
patsol
Junior Member
 
Posts: 15
Joined: Wed Nov 30, 2011 1:15 pm

Postby andrew » Thu Dec 08, 2011 10:32 pm

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
User avatar
andrew
Site Admin
 
Posts: 2383
Joined: Fri Mar 30, 2007 6:07 am

toujours mon script....

Postby patsol » Sat Dec 10, 2011 10:16 am

:roll: et pour écrire du texte?
vraiment désolé, mais je ne m'en sors pas avec la doc.
patsol
Junior Member
 
Posts: 15
Joined: Wed Nov 30, 2011 1:15 pm

Postby andrew » Sat Dec 10, 2011 10:53 am

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
    )
);
...
Last edited by andrew on Sat Dec 10, 2011 12:04 pm, edited 1 time in total.
User avatar
andrew
Site Admin
 
Posts: 2383
Joined: Fri Mar 30, 2007 6:07 am

Postby patsol » Sat Dec 10, 2011 11:55 am

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
patsol
Junior Member
 
Posts: 15
Joined: Wed Nov 30, 2011 1:15 pm

Postby andrew » Sat Dec 10, 2011 12:03 pm

Please post the complete exception and the relevant code segment, thanks.
User avatar
andrew
Site Admin
 
Posts: 2383
Joined: Fri Mar 30, 2007 6:07 am

Postby patsol » Sat Dec 10, 2011 12:25 pm

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
    )
);
patsol
Junior Member
 
Posts: 15
Joined: Wed Nov 30, 2011 1:15 pm

Postby andrew » Sat Dec 10, 2011 1:27 pm

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
User avatar
andrew
Site Admin
 
Posts: 2383
Joined: Fri Mar 30, 2007 6:07 am

résolu

Postby patsol » Sat Dec 10, 2011 2:40 pm

Ok Andrew,
Ça me va très bien comme ça.
8)
patsol
Junior Member
 
Posts: 15
Joined: Wed Nov 30, 2011 1:15 pm


Return to QCAD Professional

Who is online

Users browsing this forum: No registered users and 0 guests