Script language questions
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Script language questions
Hello.
How can I get the self script path in my script? For example, if I want to move my result file in directory with script file.
And how can I get in script the path of qcad directory?
How can I get the self script path in my script? For example, if I want to move my result file in directory with script file.
And how can I get in script the path of qcad directory?
Re: Script language questions
The global variable 'includeBasePath' is set when your script is being included. If you need that information later, please store it when your script is being included, as it will be overwritten for each newly included file.alf2006x wrote:How can I get the self script path in my script? For example, if I want to move my result file in directory with script file.
Example:
Code: Select all
function MyClass() {
...
}
MyClass.prototype = new MyBaseClass();
// store include base path for later use:
MyClass.includeBasePath = includeBasePath;
MyClass.prototype.beginEvent = function() {
this.loadSomeResource(MyClass.includeBasePath + "/MyResource.txt");
};
...
And how can I get in script the path of qcad directory?
Code: Select all
QCoreApplication.applicationDirPath()
For details, please refer to:
http://developer.qt.nokia.com/doc/qt-4. ... ionDirPath
- hungerburg
- Premier Member
- Posts: 160
- Joined: Fri May 28, 2010 7:35 pm
I wrapped block pasting like below. I am sure you can dig into the loaded document and select a block. I just paste the file as is, and it will become a block in the target.alf2006x wrote:How can I insert my block from the file?
I have got the file with name "MyDraw.dxf". It has block with name "MyBlock1". I want my script to open that file, get that block and insert it in current drawing.
Code: Select all
/** Einen Block einfügen, gegebenenfalls regional spezifisch.
* @param {Object} zeichnung die Zeichnung
* @param {String} pfad Name der Datei
* @param {Number} x X-Koordinate
* @param {Number} y Y-Koordinate
* @param {Boolean} h H-Spiegelung
* @param {Boolean} v V-Spiegelung
*/
MyScript.prototype.insert = function(zeichnung, pfad, x, y, h, v) {
var bPath = "My/" + pfad + ".dxf";
var bName = "My#" + pfad;
var bDoc = new RDocument(new RMemoryStorage(), new RSpatialIndexNavel());
var bInt = new RDocumentInterface(bDoc);
if (bInt.importFile(bPath) != RDocumentInterface.IoErrorNoError) {
this.log.w("Datei fehlt: " + bPath);
return;
}
var operation = new RPasteOperation(bDoc);
operation.setOffset(new RVector(x, y));
operation.setBlockName(bName);
operation.setScale(1.0);
operation.setRotation(0.0);
operation.setFlipHorizontal(h);
operation.setFlipVertical(v);
operation.setToCurrentLayer(true);
operation.setOverwriteLayers(false);
operation.setOverwriteBlocks(false);
zeichnung.documentInterface.applyOperation(operation);
zeichnung.documentInterface.repaintViews();
}
- hungerburg
- Premier Member
- Posts: 160
- Joined: Fri May 28, 2010 7:35 pm
I would study the source of Circle3P command. How it converts the data gathered from the mouse clicks into something, that the R… function can process. Circle3P is a funny tool, maybe a tough nut to crack with just a geometry book - please share your function, when its ready.alf2006x wrote:Can I use in my -no-gui QCAD script any commands without a prefix "R", like Circle3P?
I don't need to collect any input data from user (mouse clicks etc.) because my script works in NO-GUI mode. I just need to use command Circle3P with three params RPoint. Is it possible?I would study the source of Circle3P command. How it converts the data gathered from the mouse clicks into something
is there any easy and simple way to make this -no-gui script work without overwriting every command with input parameter 'guiAction', like Circle3P?
Code: Select all
var p1 = new RVector(0, 0);
var p2 = new RVector(10, 0);
var p3 = new RVector(5, Math.sin(RMath.deg2rad(60))*10);
operation.addObject(new RCircleEntity(document, new RCircleData(Circle3P(p1, p2, p3)));
The GUI action tools (Circle3P, Line2P, Trim, OpenFile, etc...) are interactive tools. These classes handle all user input to "do something".
Most of these tools rely on the QCAD Application Framework underneath to add an entity or an object to a drawing or modify an entity, etc.
In the same way, your script can use the functions in the QCAD Application Framework or static functions in the available scripts to achieve your goal.
Most of these tools rely on the QCAD Application Framework underneath to add an entity or an object to a drawing or modify an entity, etc.
In the same way, your script can use the functions in the QCAD Application Framework or static functions in the available scripts to achieve your goal.
yes,but in this case i must write my own function absolutely the same as qcad functions with minor changes.
it would be very comfortably for me to use qcad interactive functions with my variable params. if this is impossible i will just copy needed functions in my script and change their input parameters. i can't see other solution because my constructing of drawing use the objects, added earlier
it would be very comfortably for me to use qcad interactive functions with my variable params. if this is impossible i will just copy needed functions in my script and change their input parameters. i can't see other solution because my constructing of drawing use the objects, added earlier
Hello.
I almost understand the structure of QCAD Application Framework. That is really powerful instrument of 2D drawing.
But I have one more question.
I try to execute the script below. It rounds two lines, but do not erase original lines. I thought if I make parameter Prewiew=false it will erase original lines, but it not works.
Do I must erasing original lines myself in my script or there is some solution to make it under Round function?
[/code]
I almost understand the structure of QCAD Application Framework. That is really powerful instrument of 2D drawing.
But I have one more question.
I try to execute the script below. It rounds two lines, but do not erase original lines. I thought if I make parameter Prewiew=false it will erase original lines, but it not works.
Do I must erasing original lines myself in my script or there is some solution to make it under Round function?
Code: Select all
include(QCoreApplication.applicationDirPath()+"/scripts/Modify/Round/Round.js");
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);