Criar linhas ou arcos via ecmascrits, sem o uso do "simple.js"

Do you have a question you want to ask an existing QCAD user about QCAD and what you can do with it? Do you want to know if a particular feature exists? This is the place to ask.

Moderator: andrew

Ailton
Junior Member
Posts: 11
Joined: Wed Dec 04, 2019 2:15 pm

Re: Criar linhas ou arcos via ecmascrits, sem o uso do "simple.js"

Post by Ailton » Thu Jan 09, 2020 3:32 am

Tentei executar como sugerido mas deu o erro reportado através da figura abaixo
Attachments
ArcErro.png
ArcErro.png (170.68 KiB) Viewed 494 times

CVH
Premier Member
Posts: 540
Joined: Wed Sep 27, 2017 4:17 pm
Location: Belgium; Antwerp

Re: Criar linhas ou arcos via ecmascrits, sem o uso do "simple.js"

Post by CVH » Thu Jan 09, 2020 11:43 am

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:

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);
That wasn't hard.
I am still a novice too.

Regards,
CVH
QCADpro 3.24.3.0 / win7pro 32 bit / 4GB / 1e generation i7 2.6Ghz / HDD GeForce GT 520

CVH
Premier Member
Posts: 540
Joined: Wed Sep 27, 2017 4:17 pm
Location: Belgium; Antwerp

Re: Criar linhas ou arcos via ecmascrits, sem o uso do "simple.js"

Post by CVH » Thu Jan 09, 2020 12:20 pm

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);
QCADpro 3.24.3.0 / win7pro 32 bit / 4GB / 1e generation i7 2.6Ghz / HDD GeForce GT 520

Post Reply

Return to “Pre-sales Questions”