Hello everyone,
I'm a beginner in scripting, i'm writing a script which will help me to draw maps .
this script i wrote work nice, but now, i would like that the function next() repeat again and again until i say stop.
is'it possible? does anyone give me an exemple or explain?
thank you for help.
(the function next() include a dialog box and draw a line, scaled and rotated)
here's the script :
/**
* e01 fonction principale
*/
function main() {
var doc;
var view;
var line;
var i;
doc = new Document;
view = new View;
centre = inputcentre(); // la variable du centre (debut de chaque points)
cenplus = centre.y+1; //ceci est la variable du point y (+1) de la fonction scale
addLayer();// ajout de deux layers
next();
view.redraw();
view.zoomAuto();
print("fin du script");
}
/*
*E02 creation de 2 layers
*si ils existent deja, il ne serons pas ecrases.
*/
function addLayer() {
var doc = new Document;
var pens = [ new Pen(255,0,0), new Pen(0,255,0) ];
var layers = [ "topo", "rayons" ];
for (var i = 0; i < layers.length; i++) {
doc.addLayer(layers, pens);
doc.setActiveLayer(layers);
}
}
/**
* E03
* definition du point "CENTRE" du rayonnement lazer
* input centre dialog-box var = centre
*/
function inputcentre() {
var dialog = new Dialog;
dialog.caption = "position point centre";
dialog.okButtonText = "OK";
dialog.cancelButtonText = "Abort";
var cx = new LineEdit;
cx.label = "X ";
cx.text = " ";
dialog.add(cx);
var cy = new LineEdit;
cy.label = "Y";
cy.text = " ";
dialog.add(cy);
if (dialog.exec()) {
print("Centre = " + cx.text + "/" + cy.text);
}
var ret = new Vector(cx.text, cy.text);
return ret;
}
/*
*E04 fonction next , defini la longueure, l'angle de la ligne et la dessine.
*/
function next() {//*******
var dialog = new Dialog;
var doc = new Document;
dialog.caption = "distance pour le point 'next'";
dialog.okButtonText = "OK";
dialog.cancelButtonText = "Abort";
var dis = new LineEdit;
dis.label = "distance pour le point 'next'";
dis.text = " ";
dialog.add(dis);
var deg = new LineEdit;
deg.label = "degres pour le point 'next'";
deg.text = " ";
dialog.add(deg);
if (dialog.exec()) {
print("degres pour le point next =" + deg.text);
print("distance vers le point next =" + dis.text);
}
var line, v1, v2;
v1 = new Vector(centre.x,centre.y);
v2 = new Vector(centre.x,cenplus);
v2.rotate(centre.x,centre.y, -0.0174532925*deg.text);
v2.scale(centre.x,centre.y, dis.text);
line = new Line(doc, v1, v2);
doc.addEntity(line);
var ret = dis.text;
return ret;
var ret = deg.text;
return ret;
}
/*
*1 degre = 0.0174532925 radian
*/
// EOF.
repeat a function .
Moderator: andrew
if !
hello,
i've put an 'if' at the end of the main function , and the 'dis' and 'deg' are now global variables.
but i can't check if it work as i want, because qcad.exe make an error and windows close it! (win xp pro)
maybe something is wrong in my script ?
thank you if you can help.
_________________________
function main() {
var doc;
var view;
var line;
doc = new Document;
view = new View;
centre = inputcentre();
cenplus = centre.y+1;
addLayer();
next();
view.redraw();
view.zoomAuto();
if (dis.text>=1) { // HERE IS the IF
next();
}
print("fin du script");
}
function addLayer() {
var doc = new Document;
var pens = [ new Pen(255,0,0), new Pen(0,255,0) ];
var layers = [ "topo", "rayons" ];
for (var i = 0; i < layers.length; i++) {
doc.addLayer(layers, pens);
doc.setActiveLayer(layers);
}
}
function inputcentre() {
var dialog = new Dialog;
dialog.caption = "position point centre";
dialog.okButtonText = "OK";
dialog.cancelButtonText = "Abort";
var cx = new LineEdit;
cx.label = "X ";
cx.text = " ";
dialog.add(cx);
var cy = new LineEdit;
cy.label = "Y";
cy.text = " ";
dialog.add(cy);
if (dialog.exec()) {
print("Centre = " + cx.text + "/" + cy.text);
}
var ret = new Vector(cx.text, cy.text);
return ret;
}
function next() {//*******
var dialog = new Dialog;
var doc = new Document;
dialog.caption = "distance pour le point 'next'";
dialog.okButtonText = "OK";
dialog.cancelButtonText = "Abort";
dis = new LineEdit;
dis.label = "distance pour le point 'next'";
dis.text = " ";
dialog.add(dis);
deg = new LineEdit;
deg.label = "degres pour le point 'next'";
deg.text = " ";
dialog.add(deg);
if (dialog.exec()) {
print("degres pour le point next =" + deg.text);
print("distance vers le point next =" + dis.text);
}
line();
}
function line() {
doc = new Document;
var line, v1, v2;
v1 = new Vector(centre.x,centre.y);
v2 = new Vector(centre.x,cenplus);
v2.rotate(centre.x,centre.y, -0.0174532925*deg.text);
v2.scale(centre.x,centre.y, dis.text);
line = new Line(doc, v1, v2);
doc.addEntity(line);
var ret = dis.text;
return ret;
var ret = deg.text;
return ret;
}
/*
*1 degre = 0.0174532925 radian
*/
// EOF.
i've put an 'if' at the end of the main function , and the 'dis' and 'deg' are now global variables.
but i can't check if it work as i want, because qcad.exe make an error and windows close it! (win xp pro)
maybe something is wrong in my script ?
thank you if you can help.
_________________________
function main() {
var doc;
var view;
var line;
doc = new Document;
view = new View;
centre = inputcentre();
cenplus = centre.y+1;
addLayer();
next();
view.redraw();
view.zoomAuto();
if (dis.text>=1) { // HERE IS the IF
next();
}
print("fin du script");
}
function addLayer() {
var doc = new Document;
var pens = [ new Pen(255,0,0), new Pen(0,255,0) ];
var layers = [ "topo", "rayons" ];
for (var i = 0; i < layers.length; i++) {
doc.addLayer(layers, pens);
doc.setActiveLayer(layers);
}
}
function inputcentre() {
var dialog = new Dialog;
dialog.caption = "position point centre";
dialog.okButtonText = "OK";
dialog.cancelButtonText = "Abort";
var cx = new LineEdit;
cx.label = "X ";
cx.text = " ";
dialog.add(cx);
var cy = new LineEdit;
cy.label = "Y";
cy.text = " ";
dialog.add(cy);
if (dialog.exec()) {
print("Centre = " + cx.text + "/" + cy.text);
}
var ret = new Vector(cx.text, cy.text);
return ret;
}
function next() {//*******
var dialog = new Dialog;
var doc = new Document;
dialog.caption = "distance pour le point 'next'";
dialog.okButtonText = "OK";
dialog.cancelButtonText = "Abort";
dis = new LineEdit;
dis.label = "distance pour le point 'next'";
dis.text = " ";
dialog.add(dis);
deg = new LineEdit;
deg.label = "degres pour le point 'next'";
deg.text = " ";
dialog.add(deg);
if (dialog.exec()) {
print("degres pour le point next =" + deg.text);
print("distance vers le point next =" + dis.text);
}
line();
}
function line() {
doc = new Document;
var line, v1, v2;
v1 = new Vector(centre.x,centre.y);
v2 = new Vector(centre.x,cenplus);
v2.rotate(centre.x,centre.y, -0.0174532925*deg.text);
v2.scale(centre.x,centre.y, dis.text);
line = new Line(doc, v1, v2);
doc.addEntity(line);
var ret = dis.text;
return ret;
var ret = deg.text;
return ret;
}
/*
*1 degre = 0.0174532925 radian
*/
// EOF.