Hi, I'm new to Qcad Programming. I searched through examples but I didn't find anything.
How is possible to get the coordinates of starting and ending point of a line?
Thanks in advance
Gianfranco
How to get line coordinates
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.
Re: How to get line coordinates
Hi,
For a variable line that is a line REntity or a line RShape:
What also can be used for RArc, RPolyline, RSpline ... and that as entity or as shape.
Have a look in the resource documentation:
https://qcad.org/doc/qcad/3.0/developer ... f16a98a8e6
https://qcad.org/doc/qcad/3.0/developer ... 2d225698a5
There is also getEndPoints() what returns a list (array) of RVectors of the endpoints.
Regards,
CVH
For a variable line that is a line REntity or a line RShape:
Code: Select all
var endpoint1 = line.getStartPoint();
var endpoint2 = line.getEndPoint();
Have a look in the resource documentation:
https://qcad.org/doc/qcad/3.0/developer ... f16a98a8e6
https://qcad.org/doc/qcad/3.0/developer ... 2d225698a5
There is also getEndPoints() what returns a list (array) of RVectors of the endpoints.
Regards,
CVH
Re: How to get line coordinates
@CVH Thanks for the help!
May I ask maybe another trivial question for you.
I trimmed a line and I'm trying to get the new trimmed endpoint but I get the original point ( before trim ).
What I'm missing?
Thanks again in advance.
Gianfranco
May I ask maybe another trivial question for you.
I trimmed a line and I'm trying to get the new trimmed endpoint but I get the original point ( before trim ).
What I'm missing?
Thanks again in advance.
Gianfranco
Re: How to get line coordinates
This is part of a test script:
var v=[];
v.push([10,10]);
v.push([20,20]);
v.push([30,50]);
v.push([40,40]);
v.push([50,20]);
v.push([60,10]);
// add a spline to the drawing, using
// the computed coordinates as fit points:
SplineObj=addSpline(v, false);
// Add a vertical line intersecting the spline
var LineaStartPoint = new RVector(25,0);
var LineaEndPoint = new RVector(25,60);
var LineaObj = addLine(LineaStartPoint,LineaEndPoint);
// Trim the line to the intersection point with the spline
trim(LineaObj,25,0,SplineObj,25,0,false);
// Retrieve the starting and ending point
var startpoint1 = LineaObj.getStartPoint();
var endpoint2 = LineaObj.getEndPoint();
// Draw to new lines from (0,0) to the two points
var PuntoZero = new RVector(0,0);
var linea2 = addLine(PuntoZero,startpoint1);
var linea3 = addLine(PuntoZero,endpoint2);
// auto zoom:
autoZoom();
The linea3 shoud be ending touching the spline but instead it finish to the original endpoint.
var v=[];
v.push([10,10]);
v.push([20,20]);
v.push([30,50]);
v.push([40,40]);
v.push([50,20]);
v.push([60,10]);
// add a spline to the drawing, using
// the computed coordinates as fit points:
SplineObj=addSpline(v, false);
// Add a vertical line intersecting the spline
var LineaStartPoint = new RVector(25,0);
var LineaEndPoint = new RVector(25,60);
var LineaObj = addLine(LineaStartPoint,LineaEndPoint);
// Trim the line to the intersection point with the spline
trim(LineaObj,25,0,SplineObj,25,0,false);
// Retrieve the starting and ending point
var startpoint1 = LineaObj.getStartPoint();
var endpoint2 = LineaObj.getEndPoint();
// Draw to new lines from (0,0) to the two points
var PuntoZero = new RVector(0,0);
var linea2 = addLine(PuntoZero,startpoint1);
var linea3 = addLine(PuntoZero,endpoint2);
// auto zoom:
autoZoom();
The linea3 shoud be ending touching the spline but instead it finish to the original endpoint.
Re: How to get line coordinates
Thanks for the snippet.
Running your code it is clear that the vertical line entity is trimmed to the spline entity.
With trimBoth = false only the first entity gets trimmed.
What happens here is that you add a line LineaObj and trim it later to the spline ...
... but you don't retrieve the new shape of the line after trimming.
The variable LineaObj still holds a clone of the shape you created with addLine().
See simple_create.js: function addLine() >> function addShape() >> function addEntity() >> function addObject()
Updated code below
Can be run in the Script Shell (GE) as is.
In a running GUI script the document is usually known and retrieved with e.g.: var doc = this.getDocument();
Regards,
CVH
Running your code it is clear that the vertical line entity is trimmed to the spline entity.
With trimBoth = false only the first entity gets trimmed.
What happens here is that you add a line LineaObj and trim it later to the spline ...
... but you don't retrieve the new shape of the line after trimming.
The variable LineaObj still holds a clone of the shape you created with addLine().
See simple_create.js: function addLine() >> function addShape() >> function addEntity() >> function addObject()
Updated code below
Can be run in the Script Shell (GE) as is.
In a running GUI script the document is usually known and retrieved with e.g.: var doc = this.getDocument();
Regards,
CVH
Code: Select all
// Using the simple API (if required to include it)
// include("scripts/simple.js");
// Spline coordinates as fitpoints:
var v = [];
v.push([10, 10]);
v.push([20, 20]);
v.push([30, 50]);
v.push([40, 40]);
v.push([50, 20]);
v.push([60, 10]);
// Add a fitpoint spline to the drawing:
SplineObj = addSpline(v, false); // NOTclosed periodic
// Add a vertical line intersecting the spline:
var LineaStartPoint = new RVector(25, 0);
var LineaEndPoint = new RVector(25, 60);
var LineaObj = addLine(LineaStartPoint, LineaEndPoint);
// Trim the line to the intersection point with the spline:
trim(LineaObj, 25, 0, SplineObj, 25, 0, false); // NOTtrimBoth
// Retrieve the trimmed shape:
var doc = getTransactionDocument();
var trimmedObj = doc.queryEntity(LineaObj.getId());
// Retrieve the trimmed shape its starting and ending point:
var startpoint1 = trimmedObj.getStartPoint();
var endpoint2 = trimmedObj.getEndPoint();
// Draw two new lines from the origin to the two endpoints:
var PuntoZero = new RVector(0, 0);
var linea2 = addLine(PuntoZero, startpoint1);
var linea3 = addLine(PuntoZero, endpoint2);
// Auto zoom:
autoZoom();
Re: How to get line coordinates
Great!
As I wrote I'm a rookie with Qcad and you gave me a big help.
I need to study.
Thanks a lot!
Gianfranco
As I wrote I'm a rookie with Qcad and you gave me a big help.
I need to study.
Thanks a lot!
Gianfranco