Basic Pattern Maker [ Windows & Linux ]

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.

ELLE_Sonny
Newbie Member
Posts: 3
Joined: Tue Nov 04, 2025 1:41 pm

Re: Basic Pattern Maker [ Windows & Linux ]

Post by ELLE_Sonny » Thu Nov 06, 2025 8:43 am

Hello
Thank you for your feedback.
So, for my first exports, I didn't modify the basic files at all. I used the (bmplc) files from the folder I opened and saved them directly as .PAT files.
When I saw that I had this error, I tried to create one myself. And then I got a vertical line, but strangely not the ones at the edges.
When I preview before exporting, I get a correct display of what I want, and what a chevron pattern looks like.

I'm going to do some more testing today.
Thanks again :)
Attachments
Capture d'écran 2025-11-06 083825.jpg
Capture d'écran 2025-11-06 083825.jpg (855.37 KiB) Viewed 3688 times
chevrontest.pat
(1.05 KiB) Downloaded 109 times
chevron03.pat
(1.31 KiB) Downloaded 110 times
chevron02.pat
(1008 Bytes) Downloaded 116 times
chevron01.pat
(1008 Bytes) Downloaded 133 times

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

Re: Basic Pattern Maker [ Windows & Linux ]

Post by CVH » Thu Nov 06, 2025 11:20 am

Looking at chevron01.pat - chevron03.pat there is something wrong with how these patterns are coded

e.g. chevron02.pat:

Code: Select all

90,2,0,0,4,0,0
90,0,0,0,4,0,0
Both patterned lines are oriented vertical upwards.
The first its pattern starts at (2.0, 0.0), for the second that is (0.0, 0.0).
The patterned lines start positions are repeated every {±0.0 units along the line, ±4.0 units perpendicular to the line}.
So far, so good.

About the pattern of each line, the sixth value and those that follow:
Literally: A dot followed by yet another dot at zero distance apart and that repeated endlessly every zero units along the line.
Essentially this would mean an endless amount of dots on the same position what is a major flaw.

Using QCAD under Windows these are represented by vertical endless lines every 2 units in X.
:arrow: The crosshairs we see in the screenshot do not appear to be QCAD native. :wink:

The complete pattern length to repeat is the sum of the absolute of values #6 - #17 for a maximum of 12 dashes.
These pattern definitions are probably converted by QCAD to XLines because the complete pattern length is zero.
No defined pattern reverts to a not patterned line.


A vertical line every 2 units in X should be coded without dashes as:

Code: Select all

90,0,0,0,2
Or as 2 entries but that doubles the work load:

Code: Select all

90,0,0,0,4
90,2,0,0,4
A dot is a zero for no length, a dash is a positive value and a space is a negative value.
For repeating dots along the patterned line a zero dash must be followed by the space between them.
e.g. A horizontal line every 2 units in Y with 4 dots per unit along the line:

Code: Select all

0,0,0,0,2,0,-0.25
e.g. A horizontal line every 4 units in Y with a dot every 4 units along the line:

Code: Select all

0,0,0,0,4,0,-4

For 'chervron my try', probably chevrontest.pat, it seems to render 1 line alternating every 4 intended.

Code: Select all

90,2,0,0,4,0,0
90,0,0,0,4,0,0
270,0,4,0,4,0,0 ; ==2
0,0,0,0,4,0,-4  ; Horizontal dotted lines
270,4,4,0,4,0,0 ; ==3
0,4,0,0,4,0,-4  ; Horizontal dotted lines ==4
Or 2 stacked out of 4, my guess is on those that are defined as downwards.
Probably where QCAD renders 3 stacked lines of all 4 XLines, 2 down and 2 upwards. :wink:
The dots are also 2 stacked dots each.
Such a pattern definition together with the 10 slanted definitions may slow down the rendering.

For this pattern I can't replicate the missing link in the top left corner. :shock:


Why not simple e_geek while it can be (over-)complicated ... :!:
This pattern can be broadly simplified to 3 definition lines and there is room to spare for a higher accuracy:

Code: Select all

90,0,0,0,2
45,0,0,.7071067811865475,.7071067811865475,2.828427,-2.82842724949238
315,2,2,-.7071067811865475,.7071067811865475,2.828427,-2.82842724949238
Just add the repeated (singular) dots where you want them to occur, ideally on a horizontal definition as described above.

BTW: It doesn't serve anything to create the same pattern in a different scale ... A hatch can be created at any uniform scale.
Not all hatch patterns with slanted lines can easily be scaled non-uniform.
For this reason BPM is limited to certain strict ratios by developer choice.

Regards,
CVH

User avatar
petevick
Premier Member
Posts: 415
Joined: Tue May 19, 2020 9:34 am
Location: North Norfolk coast UK

Re: Basic Pattern Maker [ Windows & Linux ]

Post by petevick » Thu Nov 06, 2025 5:55 pm

ELLE_Sonny wrote:
Thu Nov 06, 2025 8:43 am
Hello
Thank you for your feedback.
So, for my first exports, I didn't modify the basic files at all. I used the (bmplc) files from the folder I opened and saved them directly as .PAT files.
When I saw that I had this error, I tried to create one myself. And then I got a vertical line, but strangely not the ones at the edges.
When I preview before exporting, I get a correct display of what I want, and what a chevron pattern looks like.

I'm going to do some more testing today.
Thanks again :)
I've tried your .pat files in Qcad running in Linux, they all display correctly, including the preview. I'm wondering if it's a software/hardware graphical glitch.
Pete Vickerstaff
Linux Mint 21.3 Cinnamon, Qcad Pro 3.31.1

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

Re: Basic Pattern Maker [ Windows & Linux ]

Post by CVH » Thu Nov 06, 2025 6:03 pm

petevick wrote:
Thu Nov 06, 2025 5:55 pm
I've tried your .pat files in Qcad running in Linux
Yes they do Pete, under Windows too ... In the above I assume they are not used under QCAD.

Then QCAD is hardened for the double dot in the line pattern.
The sum of all the dashes is zero long and it renders no pattern, aka an endless line. :wink:

Regards,
CVH

ELLE_Sonny
Newbie Member
Posts: 3
Joined: Tue Nov 04, 2025 1:41 pm

Re: Basic Pattern Maker [ Windows & Linux ]

Post by ELLE_Sonny » Fri Nov 07, 2025 9:38 am

Thank you for all this information. I did indeed think that it could be transferred to any CAD software. Sorry if I misunderstood. Thank you again for your help.

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

Re: Basic Pattern Maker [ Windows & Linux ]

Post by CVH » Fri Nov 07, 2025 12:01 pm

ELLE_Sonny wrote:
Fri Nov 07, 2025 9:38 am
I did indeed think that it could be transferred to any CAD software. Sorry if I misunderstood.
It can ... It should ... I am not aware if this is specified. :wink:
All because the content of a *.pat file is based on the universal DXF standard.

Then:

Code: Select all

90,2,0,0,4,0,0
Is not entirely correct according the standard.

Code: Select all

Orientation of patterned lines = 90 degrees
Start of pattern on the line = (2.0, 0.0)
Offset to start for all next copies = +/-(0.0, 4.0)
Pattern: dash1 (zero=dot), dash2 (zero=dot), ... dash12
The pattern part itself is identical to a line type definition in a *.lin file excluding the prefix A = A-type alignment.
For hatch patterns, the internal alignment is fixed and not corrected automatically as with normal line-art.

Analog to no pattern definition at all for continuous lines, the pattern for an endless line should be <None>, <Empty> or left open.

Code: Select all

90,2,0,0,4
Digging deeper:
  • 'For a pattern there must be at least two dash specifications.
    The first dash length value is 0 or greater (a dot or pen-down segment).
    The second dash length value should be less than 0 (a pen-up segment)
    .'
This doesn't specifies that 2 is mandatory but in the case of any, the sum of dash lengths in absolute must at least be non-zero.

QCAD is (mostly) hardened against possible dubious situations or actions are taken in the case they occur or are reported.
No pattern = Empty dash list OR Zero total length to repeat, it would take forever to repeat nothing over some finite length.
QCAD even allows the first dash to be a 'pen-up segment' or two successive 'pen-up/down segments' and so on.

Regards,
CVH

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

Re: Basic Pattern Maker [ Windows & Linux ]

Post by John Hyslop » Fri Nov 21, 2025 6:34 am

Hi All,

First off, a big thanks to ELLE_Sonny for supplying the screenshots from AutoCAD.

Pete and I have decided to add AutoCAD compatibility in the next release of our software. Currently, our software is fully operational in QCAD and displays patterns without any errors whatsoever.

Just to clarify:

Our software does not claim to optimise hatch pattern files.

For example, an optimised chevron pattern could indeed be written using just 3 lines, but you would need to understand the .pat code to do this.

Our software is WYSIWYG (What You See Is What You Get), very easy to use, and does not require any programming knowledge.

Key Points:

QCAD is not AutoCAD, and AutoCAD is not QCAD.

There are subtle differences between CAD platforms, especially when it comes to handling .pat files.

Below is a quick overview of how some popular CAD packages handle .pat files:

1. AutoCAD (.pat files)

AutoCAD is the most common CAD software that uses .pat files, primarily for defining hatch patterns.

Structure: AutoCAD .pat files are plain text files that contain a series of lines. AutoCAD interprets these lines as repeating patterns.

Custom Patterns: Users can create or modify their own .pat files using a text editor, and AutoCAD will interpret these patterns when applied to a hatch.

Format: The .pat file format is specific to AutoCAD, but other programs may use a similar structure for compatibility.

2. SolidWorks (.pat files)

SolidWorks uses a different system for patterns and does not directly use .pat files.

Hatching and Patterns: SolidWorks uses its own pattern system, typically with predefined pattern libraries. However, it is possible to import some AutoCAD hatch patterns by converting them or using third-party tools.

3. Revit (.pat files)

Revit uses .pat files in a similar way to AutoCAD, but the files must be formatted in a way that Revit can interpret.

Compatibility: Revit supports importing AutoCAD .pat files, but you may need to adjust the scale or other properties for the pattern to display correctly.

4. MicroStation (.pat files)

MicroStation also supports hatch patterns but does not use .pat files in the same way AutoCAD does.

Patterning: MicroStation uses .cel files (cell libraries) and other pattern definitions, which are not always compatible with AutoCAD .pat files out of the box.

5. SketchUp (.pat files)

SketchUp does not natively support .pat files.

However, SketchUp has its own mechanism for creating fill patterns for materials, and it can import CAD files (including AutoCAD .dwg and .dxf files) that may contain patterns defined in .pat files.

Are There Shared Standards?

While .pat files often share the same name across different CAD systems, each CAD platform has its own interpretation or extension of the format.

The basic structure of the .pat file is often similar across systems like AutoCAD and Revit, but there may be slight differences in how they handle things like scale, angle, and other properties.

Can You Use One CAD Package’s Patterns in Another?

It is possible to import or convert .pat files from one CAD system to another, but this typically requires some conversion or reformatting (either manually or using conversion software).

AutoCAD and Revit are generally compatible with the same basic pattern structure, but other platforms like MicroStation or SolidWorks may not interpret them correctly without adjustments.

Conclusion

There is no absolute "standard" for .pat files, though AutoCAD and Revit have a more consistent structure.

Other programs may require conversion tools or manual adjustments to use .pat files properly.

If you're working across different CAD platforms, it’s important to consult the specific software’s documentation on hatch patterns or .pat file support and conversion.

I'll be uploading the next versions within the next few days.
Linux variants will be first, followed by Windows, which is very problematic at the moment due to SmartScreen warnings.

Happy Hatching,
John & Pete
IF IT IS TO BE IT IS UP TO ME [ Ten most powerful 2 letter words ]

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

Re: Basic Pattern Maker [ Windows & Linux ]

Post by CVH » Fri Nov 21, 2025 2:11 pm

To set the record straight, I was not referring to some universal pattern file standard but to the universal DXF standard.

Referring to the AcDbHatch specification and the pattern data that comes after group code 78, see Pattern Data (DXF) specification.
The only difference with the content of a *.pat file is group code 79 that specifies how many dash values with group code 49 to read as dash list.
Coming from a *.pat file, each definition is read to the end of the line.

For a DXF to be compatible, all other programs must use this structure for importing or exporting DXF data.
The content of a *.pat file is to initially create a patterned Hatch by the application.
Not to recreate a patterned Hatch from DXF data.

How native patterns files or linetypes definitions are structured is purely native to the application, QCAD uses the ACAD structure.
Basically not inventing the wheel twice.
The same is true for the drawing format, native is not per definition DXF or DWG.
Most obvious that you can compile a list of differences.

The 'dot, dot and nothing else' flaw doesn't originate from a difference between QCAD and ACAD.
The DXF created with such pattern lists 79:2 49:0 49:0 what is bogus, 79:1 49:0 is the same sort of flaw.
In-line repetition distance is every zero units further and backwards along the line up to an intersection with a boundary segment.
Any finite length divided by zero results in an infinite number of repetitions.
But typically the result of such an equation results in NaN ... Not a Number ... A division by zero error.
The difference between QCAD and ACAD is how such a situation is handle.


You don't need an in-depth knowledge of pattern coding to come up with the optimized chevron pattern.
It is a pattern defined in a 'Tile' or rectangular area of 4 by 1 units high and repeated orthogonal in all 4 directions.
Then BPM is limited to squared definition areas.
Logically a dash or dot is inside the definition area but it is also valid if it extends to outside the area and even when fully outside.
A simple matter of identifying the first in-line repetition and the first left or right parallel copy or clone.
  • Vertical lines are rather straight forward, these repeat in parallel every 2 units, endless lines and thus no dash pattern.
    The pen-down is the 45°(315°) diagonal of 2 by 2 and is sqrt(2^2+2^2) = sqrt(8) or 2.82842712474619... long, repeats in-line every 4 by 4.
    The offset to the next parallel is the diagonal of 0.5 by 0.5 and is sqrt(0.5) or 0.7071067811865475..., the shift is also sqrt(0.5).
    Offset and shift values their sign depends on forward or backward and on left or right.
    Why 315°for the second? It is a choice so that segments connect at (2, 2), starting at (0, 4) in the 135° direction is the other option.

    At best we include all values in full floating point notation (15-16 significant digits) but you may run out of text space when limited.
    We can truncate the length of the pen-down part to (+)2.828427 (±1ppm) what is textually shorter.
    But the sum of the dashes in absolute must be 2 times sqrt(8) to repeat every 4 by 4 :!:
    Hence, pen-up is (-)2.8284272494923801 with 17 significant digits, the 01 at the end won't matter anymore using 15-16 digits.
Regards,
CVH

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

Re: Basic Pattern Maker [ Windows & Linux ]

Post by John Hyslop » Mon Nov 24, 2025 4:10 am

BPMv1.5.1-Info.png
BPMv1.5.1-Info.png (49.35 KiB) Viewed 1063 times
BPM-Sketches - 22-11-25.zip
(978.28 KiB) Downloaded 36 times
BPM - V1.5.1 - Linux 32bit Deb.zip
(1.79 MiB) Downloaded 31 times
BPM - V1.5.1 - Linux 64bit AppImage.zip
(3.12 MiB) Downloaded 25 times
BPM - V1.5.1- Linux 64bit Deb.zip
(1.84 MiB) Downloaded 28 times
BPM - V1.5.1 - Linux i386 AppImage.zip
(2.98 MiB) Downloaded 32 times
BPM - V1.5.1 - Setup - 64bit - Windows.zip
(2.71 MiB) Downloaded 30 times
BPM - V1.5.1 - Setup - 32bit - Windows.zip
(2.59 MiB) Downloaded 24 times
Windows 64-bit and 32-bit versions have now both been updated.
The previous installers weren’t creating the INI file on first run, which caused an error message the first time the app started.
The error was harmless — the INI file was created after first use — but both installers have now been rebuilt so the setup process is smooth and error-free.

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

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”