Page 1 of 1

importer un fichier texte

Posted: Sat Dec 03, 2011 9:55 pm
by patsol
Bonsoir,

Voilà, j'ai un fichier texte (des séries de vecteurs) à importer dans QCAD3. Avec Qcad2, j'avais fait un script OK:
quels sont les équivalents de
FileDialog.getOpenFileName
file = new File()
file.open()
file.readLine())

Et puis surtout, comment lance-t-on un script depuis une fenêtre ouverte de QCAD?
Merci!!!!!

Posted: Sat Dec 03, 2011 11:21 pm
by andrew
Pour traduire ce texte en français, s'il vous plaît
utilisez http://translate.google.com, merci.


You might want to have a look at the script examples that come with QCAD 3, for example scripts/Examples/MathExamples/Spiral/Spiral.js which draws a spiral from line segments.

You can duplicate the 'Spiral' script as a starting point:
1. Copy directory scripts/Examples/MathExamples/Spiral to scripts/Examples/MathExamples/MyScript.
2. Rename scripts/Examples/MathExamples/MyScript/Spiral.js to scripts/Examples/MathExamples/MyScript/MyScript.js.
3. Rename the ECMAScript class 'Spiral' in MyScript.js to 'MyScript'.
4. Adjust the titles (strings) in MyScript.js in method MyScript.init

You have now an exact copy of the Spiral script. To launch your script, choose menu Examples -> Mathematics -> Your menu title

For generic, non-CAD specific functions, you can use almost the entire Qt API:
http://doc.qt.nokia.com/4.7/classes.html

Code: Select all

var filename = QFileDialog.getOpenFileName(null, qsTr("Open a File..."),
                   QDir.homePath(), qsTr("Text Files (*.txt);;All Files (*)"));
var file = new QFile(filename);
var flags = new QIODevice.OpenMode(QIODevice.ReadOnly | QIODevice.Text);
if (file.open(flags)) {
    var textStream = new QTextStream(file);
    var line = textStream.readLine();
    ...
}

Posted: Sun Dec 04, 2011 8:31 am
by patsol
Merci Andrew, je regarde ça tout de suite.