How to get coordinates according to step value

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.

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

Re: How to get coordinates according to step value

Post by CVH » Tue Dec 05, 2023 7:47 am

Proof of concept Nifty solution.
See attached file with Layer states.

As is provided (Layer state 1) you find textual info and 2 lines in different weights.
In Screen-based Linetypes (NL) the thinner line may look as one without a weight.
Toggle NL off and you see the real pen sizes.

Exploded the TTF text to outer contours and replaced the line-art with contours.
(Activated Layer state 2 by keying in Y2)

Selected everything and hatched that with a custom pattern SEM_Dots at scale 0.4 (Included below)
(Activated Layer state 3 by keying in Y3)

Taking only the Hatch (Y4) (A single hatch entity with a multiple of boundary loops)

Exploded its patterned area where pattern dots become drawing points (Y5)
For the change in visual appearance between Y4 and Y5:
- Pattern dots are very short line segments rendered with a Lineweight, Screen-based or not.
- Points entities are rendered pixel based and the size is fix and thus zoom state independent.
BTW: XP of a solid filled hatch returns the outline, that of a patterned fill returns the pattern shapes.

In a few simple steps the drawing art visualized in layer '0' (Y1) is decomposed in 8673 points on layer '3) Points' (Y5)
Replacing the line-art with contours is not supported right out the box. :(
But that is feasible as long as offsets of line-art are flawless. :wink:

From there on it is a question of exporting the point entities their coordinates as CSV.
Maybe it is an idea to sort these coordinates to produce a zigzag toolpath.
I then also need how these export values need to be formatted, how many decimal digits, decimal point, list separator, LF or CR/LF.

Regards,
CVH
Attachments
Poc_WildWolfCJ_SEMexample.dxf
(1.25 MiB) Downloaded 196 times
SEM_Dots.pat
Hatch pattern file
(356 Bytes) Downloaded 214 times

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

Re: How to get coordinates according to step value

Post by CVH » Wed Dec 06, 2023 5:57 am

There is however yet another problem.
With loose entities connected or touching within the sum of both Lineweights the hatched area overlaps and True XOR True is not hatched.

The solution I see is to hatch each loop separate with doubling the dots and thus point duplicates as result.
Duplicate positions (RVectors) can be filtered out.

Busy...

WildWolfCJ
Full Member
Posts: 84
Joined: Fri Oct 20, 2023 7:21 am

Re: How to get coordinates according to step value

Post by WildWolfCJ » Wed Dec 06, 2023 8:15 am

HI CVH
Thank you for your patient and detailed reply. This is a very clever method.
I still have the following questions:

1 How to import SEM_Dots.pat into QCAD as a filling file? I created a new dxf file for hatching and did not find the SEM_Dots item. Please check test_hatch.jpg

2 The step value discussed now is fixed at 0.4, but this value can be dynamically adjusted. How should this be handled?

3 Poc_WildWolfCJ_SEMexample.dxf contains four layers of 0 Outlines hatched points, but usually only a DXF file containing 0 layers can be obtained. How to automatically obtain coordinates through JS script (do not run the QCAD GUI interface, directly output the coordinate file through the command line)?

4 From there on it is a question of exporting the point entities their coordinates as CSV.
The coordinate format can be defined as follows
polyline1 handle
X1 , Y1
X2, Y2
.
.
.
Xn, Yn
Polyline 2 handle
X1 , Y1
X2, Y2
.
.
.
Xn, Yn
....
polyline n handle
X1 , Y1
X2, Y2
.
.
.
Xn, Yn
Attachments
test_hatch.jpg
test_hatch.jpg (186.91 KiB) Viewed 78516 times

WildWolfCJ
Full Member
Posts: 84
Joined: Fri Oct 20, 2023 7:21 am

Re: How to get coordinates according to step value

Post by WildWolfCJ » Wed Dec 06, 2023 8:52 am

CVH wrote:
Wed Dec 06, 2023 5:57 am
There is however yet another problem.
With loose entities connected or touching within the sum of both Lineweights the hatched area overlaps and True XOR True is not hatched.
If two areas overlap, the overlapping area only needs one coordinate value.
thank you for your reply

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

Re: How to get coordinates according to step value

Post by CVH » Wed Dec 06, 2023 9:36 am

WildWolfCJ wrote:
Wed Dec 06, 2023 8:15 am
1 How to import SEM_Dots.pat into QCAD as a filling file?
You need to include the pat file under ...\QCAD\patterns\metric and/or ...\QCAD\patterns\imperial.
Where the 3 dots refer to your QCAD installation path.
You need Admin rights for that, alternatively it can be included under the QCAD user path.
WildWolfCJ wrote:
Wed Dec 06, 2023 8:15 am
2 The step value discussed now is fixed at 0.4,
Pattern is 1 drawing unit based, Hatch Scale defines the actual dot spacing.
In the Poc file you could for example alter the Hatch scale to 0.2 resulting in four times the amount of pattern dots.
- Select Hatch entity on layer '2) Hatched' -> DP -> YI (Layer 1 is fine) Acknowledge.
- (Still selected) Alter Pattern Scale to 0.2
- (Still selected) XP to points resulting in 36562 points.
WildWolfCJ wrote:
Wed Dec 06, 2023 8:15 am
3 Poc_WildWolfCJ_SEMexample.dxf contains four layers of 0 Outlines hatched points, but usually only a DXF file containing 0 layers can be obtained.
The PoC file is an example file with each step in it. Original art is on Layer 0.
After contours, hatching, explosion the result is displayed on the Points layer.
The intermediate steps can be visualized by cycling Layer State 1-5 with Y1 - Y5
This is how it is attacked with GUI tools, new drawing entities, each step in detail on an additional layer.
Scripting the GUI methods will not create new entities, only intermediate RShapes and the export to CSV.
WildWolfCJ wrote:
Wed Dec 06, 2023 8:15 am
How to automatically obtain coordinates through JS script (do not run the QCAD GUI interface, directly output the coordinate file through the command line)?
For that we first need to write a script that does the intermediate steps as per PoC.
As GUI script, an addon, what is easier to trial and error.
Such a script or at least the functionality can be called from the Command Line.
WildWolfCJ wrote:
Wed Dec 06, 2023 8:15 am
The coordinate format can be defined as follows
Understood, comma separated thus decimal dot, still require how a value and the lines must be formatted.
Number of decimal places, Windows/Unix/Mac EOL.
Dots per handle are possible ( ... Resulting in duplicated dots where line-art meets other art)
Is it not more opportune to export everything at once ... Filtered on duplicates ... With a zigzag toolpath?

With large art, small step sizes I now predict that QCAD may choke on the vast amount of points.

CSV export is for the final stage.
Let's first tackle the contours of line-art given the pen size. :wink:

Regards,
CVH

WildWolfCJ
Full Member
Posts: 84
Joined: Fri Oct 20, 2023 7:21 am

Re: How to get coordinates according to step value

Post by WildWolfCJ » Fri Dec 08, 2023 3:21 am

HI CVH Thank you for your patient answer.

1
You need to include the pat file under ...\QCAD\patterns\metric and/or ...\QCAD\patterns\imperial.
This problem has been solved,Please see the attachment test1.jpg

2
Pattern is 1 drawing unit based, Hatch Scale defines the actual dot spacing.
This problem has been solved,Please see the attachment test2.jpg

3
Scripting the GUI methods will not create new entities, only intermediate RShapes and the export to CSV.
Yes, I just need to follow this idea now to handle closed and unclosed polylines with pen width using JS, I'm stuck on how to write the JS script
This script should be like this, accept the external DXF file, traverse the polyline with pen width, and then generate the corresponding coordinate file

4
Number of decimal places, Windows/Unix/Mac EOL.
Is it not more opportune to export everything at once ... Filtered on duplicates ... With a zigzag toolpath?
Just consider the situation on Windows and keep the decimal point to 6 places.
It is more reasonable to process polylines one by one

5
With large art, small step sizes I now predict that QCAD may choke on the vast amount of points.
Will the command line script not starting the QCAD GUI interface also cause slow operation?
Attachments
test2.jpg
test2.jpg (469.3 KiB) Viewed 78448 times
test1.jpg
test1.jpg (263.96 KiB) Viewed 78448 times

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

Re: How to get coordinates according to step value

Post by CVH » Fri Dec 08, 2023 10:31 am

WildWolfCJ wrote:
Fri Dec 08, 2023 3:21 am
Will the command line script not starting the QCAD GUI interface also cause slow operation?
Intermediates can be done offscreen ... Command Line tools run QCAD without GUI.
For now I need them on screen in the GUI to develop the addon and create/verify the required functionality.
I don't like to fly blind, run before I can walk ... IMHO a preview before SEM is mandatory.

WildWolfCJ_Offsets_Preview1.png
WildWolfCJ_Offsets_Preview1.png (74.03 KiB) Viewed 78408 times

The magenta shapes are the visualization for the offsetting process.

You may discover several other custom tools in the CAD Main Tools Panel ... :wink:
Nosy - EPB - Tile2Hatch - Flexpainter(current art) - Rounding all corners of a polyline - Involute/Math functions - ...
Among several others under Misc - Under a User toolbar ...

I don't need to start from scratch, many code is copy/paste/adapt.
Busy ...

John Hyslop
Premier Member
Posts: 474
Joined: Mon Sep 30, 2019 6:21 am
Location: Melbourne - Australia

Re: How to get coordinates according to step value

Post by John Hyslop » Fri Dec 08, 2023 11:19 am

Hi WildWolfCJ

If you want to create your own dot patterns have a look at these Apps.. they are free and do not rely on scripting , meaning they run independently / stand alone and the patterns can be copied to both the community and pro versions of Qcads hatch pattern folders..
Points can easily be created in seconds and BPM offers an easy way to create them BHT can create offset and also shifting points..
Here are some screenshots plus forum links too..always happy to help..

Basic Hatch Tool [ by John Hyslop ]
https://qcad.org/rsforum/viewtopic.php? ... =45#p39904
BHT-Points.png
BHT-Points.png (19.36 KiB) Viewed 78397 times
Basic Pattern Maker [ by John Hyslop & Pete Vicerstaff ]
https://qcad.org/rsforum/viewtopic.php? ... 995#p42607
BPM-Points.png
BPM-Points.png (34.12 KiB) Viewed 78397 times
They are both extremely easy to install and use and if you have any questions regarding these apps please feel free to PM myself or forum user PeteVick..

Happy Hatching
Cheers
John Hyslop :D
IF IT IS TO BE IT IS UP TO ME [ Ten most powerful 2 letter words ]

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

Re: How to get coordinates according to step value

Post by CVH » Fri Dec 08, 2023 7:09 pm

@John Hyslop
John Hyslop wrote:
Fri Dec 08, 2023 11:19 am
If you want to create your own dot patterns ...
Only one base pattern is (was) required as example.
The questions was not how to create it, the questions were how to install and apply it.
WildWolfCJ wrote:
Fri Dec 08, 2023 3:21 am
1) This problem has been solved,Please see the attachment test1.jpg
2) This problem has been solved,Please see the attachment test2.jpg
The topic among others by WildWolfCJ is how to rasterizise CAD line-art suitable for SEM output.
How are BHT & BPM related to SEM output?
How does that relate to outlines of line-art with various Lineweights?

Rasterizing with hatch dots may not even be a feasible solution for large art, QCAD hatching may timeout.
Exploding a large 'dotted' area may choke (crash) QCAD, there is an end to how many drawing entities it can handle at once.

Step by step, let's first get the boundaries related to pen-size, QCAD does not explode Lineweights.

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

Re: How to get coordinates according to step value

Post by CVH » Sun Dec 10, 2023 12:57 pm

WildWolfCJ,

Making progress:
Entities on layer 0 are converted to outlines accounting for Lineweights in a single operation ... A single click.
For visual representation these offsets or boundaries are included on layer 'Results' (Magenta).
Toggle LN to off state to see the match with the actual pen size of the various Lineweights.
Added some remarks (Cyan).
The code includes trapping errors, estimations on the number of SEM dots and the enclosed area to fill.
I would be happy to trial one of your drawing files. :wink:
WildWolfCJ_Weights.dxf
(218.71 KiB) Downloaded 157 times

Next up: Multi-block text into simple text with own format/font ...

Regards,
CVH

WildWolfCJ
Full Member
Posts: 84
Joined: Fri Oct 20, 2023 7:21 am

Re: How to get coordinates according to step value

Post by WildWolfCJ » Mon Dec 11, 2023 10:39 am

HI CVH
Thank you very much for your patient reply
We are on the right path now and you fully understood the details of my needs.
For now I need them on screen in the GUI to develop the addon and create/verify the required functionality.
Have you developed this plug-in? Can you send it to me for reference?
Entities on layer 0 are converted to outlines accounting for Lineweights in a single operation ... A single click.
For visual representation these offsets or boundaries are included on layer 'Results' (Magenta).
Toggle LN to off state to see the match with the actual pen size of the various Lineweights.
Added some remarks (Cyan).
The code includes trapping errors, estimations on the number of SEM dots and the enclosed area to fill.
The js script you developed has been able to generate outlines of solid objects with different pen widths. This is really an amazing job. The situation you handled is more detailed and meticulous than I imagined.
I would be happy to trial one of your drawing files. :wink:
Your DXF file is already more complex and detailed than the DXF we are using now. The DXF files I am testing now are relatively simple.

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

Re: How to get coordinates according to step value

Post by CVH » Mon Dec 11, 2023 11:08 am

WildWolfCJ wrote:
Mon Dec 11, 2023 10:39 am
Have you developed this plug-in? Can you send it to me for reference?
Yes (but not from scratch) and at the moment not really, it is piggy-backed on another addon.
Meaning that I run A but get results from B.
The button that I refer to is in fact a tool for the locus of equidistant points between two entities (Point, Line, Arc) :lol:
https://mathcurve.com/courbes2d.gb/equi ... ance.shtml
WildWolfCJ wrote:
Mon Dec 11, 2023 10:39 am
This is really an amazing job
Busy with removing overlaps and then I stumble for the nth time on problematic QCAD resources.
E.g. A test on self-intersecting polylines with bulge factors keep on returning intersection points for the magenta offsets of the ellipse.
About 48 each :shock: .
Easy to reject when you know that an ellipse can not self-intersect but these are merely handled as loops without a reference to their origin.
A merged loop from the 4 lines for example can no longer be considered as related to any of the 4 original lines.
The tool can not distinguish between for example a loop of a spline or that of the ellipse or those of the 4 lines.
WildWolfCJ wrote:
Mon Dec 11, 2023 10:39 am
The DXF files I am testing now are relatively simple.
Here the topic is a Polyline but I merged all your requests to "Line-art".

Regards,
CVH

WildWolfCJ
Full Member
Posts: 84
Joined: Fri Oct 20, 2023 7:21 am

Re: How to get coordinates according to step value

Post by WildWolfCJ » Tue Dec 12, 2023 3:01 am

HI CVH Thank you for your patient reply.
Busy with removing overlaps and then I stumble for the nth time on problematic QCAD resources.
E.g. A test on self-intersecting polylines with bulge factors keep on returning intersection points for the magenta offsets of the ellipse.
About 48 each
Easy to reject when you know that an ellipse can not self-intersect but these are merely handled as loops without a reference to their origin.
A merged loop from the 4 lines for example can no longer be considered as related to any of the 4 original lines.
The tool can not distinguish between for example a loop of a spline or that of the ellipse or those of the 4 lines.
You have considered all kinds of details and I think it fully meets my needs.

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

Re: How to get coordinates according to step value

Post by CVH » Thu Dec 14, 2023 1:36 pm

Closing in on the issues with offsets of ellipses or ellipse arcs ....

There is a reason why the dark blue center markers of arcs of an ellipse offset form the symmetric spiky pattern in the image below.
They are on an evolute of the ellipse. :wink:

WildWolfCJ_Offsets_Preview2.png
WildWolfCJ_Offsets_Preview2.png (27.23 KiB) Viewed 77238 times
  • Remark those center markers that are on the original white ellipse, these are rounding's to connect arcs ...
    ... Or better, inversion of rounding's.
    Typically cutting the connected arcs as going forth, back up a bit an going forth again.
  • Also remark the tiny yellow dots on the outer offset.
    These are very tiny line segments :!: called bridges to close a gap between arcs while not requested by preference.
    While perfectly connected at both endpoints these return self-intersections for one endpoint only ... Start- or endpoint.
    The SIPs nature is anti-symmetric over both ellipse axis
Needs further investigation.
IMHO the offset of an ellipse approximated with tangentially connected arcs should be ... Tangentially connected arcs.
But I know that bulge > arc > bulge is not flawless, poly.appendShape(shape) does not trim and is not flawless, isTangent for two arcs or an arc and a line is a math issue and intersections of these may fail especially when arcs are internally tangent or 'almost' tangent.

...

WildWolfCJ
Full Member
Posts: 84
Joined: Fri Oct 20, 2023 7:21 am

Re: How to get coordinates according to step value

Post by WildWolfCJ » Mon Dec 18, 2023 10:39 am

HICVH
I've been very busy these days, so I'm sorry for the slow reply.
Has the script for this function been completed? Can I use this function now? The method I am using now has too many loopholes

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”