Arc linewidths in scripting

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
ScottP
Junior Member
Posts: 14
Joined: Wed Jul 08, 2020 5:08 pm

Arc linewidths in scripting

Post by ScottP » Tue Aug 25, 2020 5:27 pm

I'm trying to set the linewidth or Global Width of several entities in scripting. The following code correctly sets the linewidths of Polylines and Lines, but not Arcs... see the attached pics showing the huge resulting Arc linewidths.
In QCAD GUI, there's no linewidth or Global Width property to set for these arcs. Am I missing something straightforward here?

Code: Select all

var width = 10;
if(entityPointer.getType() == RS.EntityArc || entityPointer.getType() == RS.EntityLine){
	var shapes = entityPointer.getShapes();
	for(var n=0; n<shapes.length; n++) {
		startTransaction(di);
		addShape(shapes[n],new RColor(255,255,255,255) ,"CONTINUOUS", width);
		endTransaction();
}
for RS.EntityPolyline, it's "shapes =entityPointer.getExploded();"


Thanks for the help! :)
Attachments
wrong arc linewidths1.png
wrong arc linewidths1.png (6.8 KiB) Viewed 6251 times
wrong arc linewidths.png
wrong arc linewidths.png (60.78 KiB) Viewed 6251 times

CVH
Premier Member
Posts: 3416
Joined: Wed Sep 27, 2017 4:17 pm

Re: Arc linewidths in scripting

Post by CVH » Tue Aug 25, 2020 7:57 pm

Hi,
Little baffled by the approuch. :shock:

A) Lineweights are a distinct set up to 2.11mm
B) Only Polylines have widths, global over the entire poly or locally per segment start/end.

Breaking it down:
Given an entity from the document called entityPointer.

For the .getType = RS.EntityPolyline your shapes are the individual polyline segments resulted
from the explosion of the Poly. (Exploded according Prefs in App.Prefs)
>> Meaning you are adding the individual polyline segments back with props: white, continuous, 10 width (10>2.11 !!)

For the .getType = RS.EntityArc and RS.EntityLine you are trying to get shapes.
Any idea what kind of shapes you expect from an Arc or a Line? :roll:

Shapes from an explosion are new shapes. These you can (re-)add with the Simple API and with props.
The basic shapes Line, Arc, Poly, ... are document shapes (entities) themselves.
For these you have to alter the props of these entities in the document.

RAddObjectsOperation is better suited
This is not your usage but it's a start. :wink:
https://qcad.org/rsforum/viewtopic.php?t=7486

Regards,
CVH

ScottP
Junior Member
Posts: 14
Joined: Wed Jul 08, 2020 5:08 pm

Re: Arc linewidths in scripting

Post by ScottP » Tue Mar 30, 2021 10:36 pm

Thanks CVH! Big delay getting back to this.

Of the basic shapes (polylines, arcs, lines), it looks like only polylines have width properties to set in the API. If arcs and lines were explodable into polylines then I could have set nondiscrete widths for them. Oh well. I'll just use the discrete list of allowed lineWeights up to 2.11mm instead of width-setting functions for nondiscrete values.

For anyone's future reference, I've gathered the below from the API and QCAD website.

EXPLODE:
Converts block references, polylines, splines, ellipses, texts, dimensions and hatches into more basic entities.
- Dimensions are split up into lines, triangles and text entities.
- Text entities are split into polylines (or lines, arcs and splines).
- Splines are converted into polylines with tangentially connected arc segments.
- Ellipses [and Circles?] are converted into polylines with arc segments [or not! - see setting in App.Preferences for Explode()].
- Polylines are split up into loose segments [of arcs and lines only?]
- Hatches are split up into lines.
- Solid fills are converted to the outline of the solid fill.
AND
RPolyline.getExploded() returns List of RLines and RArcs describing this polyline.
RSpline.getExploded() returns List of RLines describing this spline.
RTriangle.getExploded() returns List of RLines describing this triangle.
getExploded() is Implemented in RPolylineData, RPolyline, RSpline, RLeaderData, and RTriangle.
AND
Polylines, Splines and Triangles are members of RExplodable Class

Together, all of the above speaks to me that:
Basic Arcs are not explodable
Basic Polylines are not explodable
Basic Lines are not explodable

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: Arc linewidths in scripting

Post by andrew » Wed Mar 31, 2021 7:09 am

ScottP wrote:
Tue Mar 30, 2021 10:36 pm
If arcs and lines were explodable into polylines then I could have set nondiscrete widths for them.
Exploding in QCAD means to create more basic shapes from complex shapes.

There are different tools to create a polyline from an arc or line:
Draw > Polyline > Polyline from Segments
Draw > Polyline > Polyline from Selection

Or
Right-click on the (isolated) arc or line and choose "Auto create polyline".
Basic Polylines are not explodable
Polylines can be exploded into lines and arcs (one line or arc for each segment). Each segment of a polyline is either a line or arc segment.

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”