Criar linhas ou arcos via ecmascrits, sem o uso do "simple.js"
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files and screenshots.
Post one question per topic.
Re: Criar linhas ou arcos via ecmascrits, sem o uso do "simple.js"
Tentei executar como sugerido mas deu o erro reportado através da figura abaixo
- Attachments
-
- ArcErro.png (170.68 KiB) Viewed 5575 times
Re: Criar linhas ou arcos via ecmascrits, sem o uso do "simple.js"
hi,
Still in the Pre-Sales section??
Sure it fails.
So far I know 'ShapeAlgorithms.createArcFrom3Points' takes 2-3 RVectors as input.
It has no means to break an 'obj' or whatever down into bits.
What I see is that you are trying to use Arc3P.js and preset the users clicked points and other stuff.
But I don't understand that you are doing that from the script Shell.
Did you read the instructions when activating the Shell?
The advice is to stick with simple API.
I can't imagine that you are going to enter those lines and vars everytime over and over again.
Lets start over:
with the functional Arc2PR from Anrdew:
var doc = getDocument();
var di = getDocumentInterface();
var operation = new RAddObjectsOperation();
include('scripts/Draw/Arc/Arc2PR/Arc2PR.js');
var obj = {};
obj.point1 = new RVector(50,50);
obj.point2 = new RVector(75,100);
obj.radius = 50;
obj.reversed = false; // true for clockwise
obj.alternativeSolution = false; // true for longer of the two possible arcs
var arc = Arc2PR.prototype.getArc2PR.call(obj, false);
var entity = new RArcEntity(doc, new RArcData(arc));
operation.addObject(entity);
di.applyOperation(operation);
With a 3-point circle there is only one solution .... no need for obj.alternativeSolution.
A 3-point start at point1 and ends at point3 .... no need for obj.reversed.
In Arc3P.js, there is no getArc function .... we will have to do this for ourselfs.
We don't even need Arc3P.js .... the only thing we have to do is casting a 3 point arc.
What Arc3P.js does by ShapeAlgorithms.createArcFrom3Points.
So I take what suites me of both:
That wasn't hard.
I am still a novice too.
Regards,
CVH
Still in the Pre-Sales section??
Sure it fails.
So far I know 'ShapeAlgorithms.createArcFrom3Points' takes 2-3 RVectors as input.
It has no means to break an 'obj' or whatever down into bits.
What I see is that you are trying to use Arc3P.js and preset the users clicked points and other stuff.
But I don't understand that you are doing that from the script Shell.
Did you read the instructions when activating the Shell?
The advice is to stick with simple API.
I can't imagine that you are going to enter those lines and vars everytime over and over again.
Lets start over:
with the functional Arc2PR from Anrdew:
var doc = getDocument();
var di = getDocumentInterface();
var operation = new RAddObjectsOperation();
include('scripts/Draw/Arc/Arc2PR/Arc2PR.js');
var obj = {};
obj.point1 = new RVector(50,50);
obj.point2 = new RVector(75,100);
obj.radius = 50;
obj.reversed = false; // true for clockwise
obj.alternativeSolution = false; // true for longer of the two possible arcs
var arc = Arc2PR.prototype.getArc2PR.call(obj, false);
var entity = new RArcEntity(doc, new RArcData(arc));
operation.addObject(entity);
di.applyOperation(operation);
With a 3-point circle there is only one solution .... no need for obj.alternativeSolution.
A 3-point start at point1 and ends at point3 .... no need for obj.reversed.
In Arc3P.js, there is no getArc function .... we will have to do this for ourselfs.
We don't even need Arc3P.js .... the only thing we have to do is casting a 3 point arc.
What Arc3P.js does by ShapeAlgorithms.createArcFrom3Points.
So I take what suites me of both:
Code: Select all
include('scripts\ShapeAlgorithms.js')
var doc = getDocument();
var di = getDocumentInterface();
var operation = new RAddObjectsOperation();
operation.setText("Adding Arc3P");
var point1 = new RVector(50,50);
var point2 = new RVector(75,100);
var point3 = new RVector(100,50);
var shape = ShapeAlgorithms.createArcFrom3Points(point1, point2, point3);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// shape is not always an Arc, it can be a Line too.
// or non valid, or undefined, .... but I know this one will be valid
// see: Arc3P.js ... Arc3P.getOperation
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var newEntity = new RArcEntity(doc, new RArcData(shape));
operation.addObject(newEntity);
di.applyOperation(operation);
I am still a novice too.
Regards,
CVH
Re: Criar linhas ou arcos via ecmascrits, sem o uso do "simple.js"
5 Arc's
Code: Select all
include('scripts\ShapeAlgorithms.js')
var doc = getDocument();
var di = getDocumentInterface();
var operation = new RAddObjectsOperation();
operation.setText("Adding some Arc3P");
var point1 = new RVector(50,50);
var point3 = new RVector(100,50);
var point2, shape;
for (var k=0; k<5; k++) {
point2 = new RVector(75,100+5*k);
shape = ShapeAlgorithms.createArcFrom3Points(point1, point2, point3);
var newEntity = new RArcEntity(doc, new RArcData(shape));
operation.addObject(newEntity);
}
di.applyOperation(operation);