Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Hatch patern code

20 REPLIES 20
SOLVED
Reply
Message 1 of 21
djurk_haas
1297 Views, 20 Replies

Hatch patern code

Hello,

To make my own hatch pattern (code in *.pat file), I am analyzing an existing code of a pattern (see code below).
Can someone tell me how to get the values ​​of the Offset-x, offset-y and Gap.
In the appendix a drawing in which I have retrieved the values ​​(red line = gap and magenta lines are the offset x / y) but now I get stuck. How can I reproduce these values ​​without a drawing?

 

*xxxx-Test,3 POINT STAR
210.0686, 0.500,0.420, 13.892369,0.045549, 0.439090,-21.515408
329.9314, 0.500,0.420, 8.062129,0.045549, 0.439090,-21.515408
270.0000, 0.500,0.860, 1.000,1.000, 0.440000,-0.560

Tags (1)
20 REPLIES 20
Message 2 of 21
cadffm
in reply to: djurk_haas

What do you mean with "How to get the values"?

It is 

Thinking..

Or math & calculation

 

Sorry, I don't understand your real question.

 

For others who don't know about hatch pattern definition:

https://help.autodesk.com/view/ACD/2024/ENU/?guid=GUID-7E1BFC62-C5F2-48C6-84D7-71FAD4DF0BEF

abd following links

 

Sebastian

Message 3 of 21
Kent1Cooper
in reply to: djurk_haas


@djurk_haas wrote:

....

Can someone tell me how to get the values ​​of the Offset-x, offset-y and Gap.

....

*xxxx-Test,3 POINT STAR
210.0686, 0.500,0.420, 13.892369,0.045549, 0.439090,-21.515408
329.9314, 0.500,0.420, 8.062129,0.045549, 0.439090,-21.515408
270.0000, 0.500,0.860, 1.000,1.000, 0.440000,-0.560


ANGLE, ORIGINX,ORIGINY, X-OFFSET, Y-OFFSET, PEN-DOWN, -PEN-UP [= GAP]

 

Help lays it all out for you.

 

But be aware that the OriginX and OriginY numbers are relative to 0°-to-the-right, not to the ANGLE of the lineset, but the X-OFFSET and Y-OFFSET numbers are relative to the ANGLE of the lineset.

Kent Cooper, AIA
Message 4 of 21
djurk_haas
in reply to: cadffm

Indeed math and calculation but I have no idea how to calculate the length of the offset x/y and gap with the following data from the  (one) line of the hatch:
Handle: 3b1
Angle: 210.0686
X starts: 500,0000
Y starts: 420.0000
X end: 120,0000
Y end: 200.0000
Length 0.4391

X Distance 1000 (distance between paternline)
Y Distance 1000 (distance between paternline)

Offset-X: ???
Offset-Y: ???
Gap: ???

Message 5 of 21
Kent1Cooper
in reply to: djurk_haas

The attached drawing shows you what those numbers mean in the pattern, using similar colors to those I used in my previous message, for just the first lineset defined in that pattern.  Given the length of the pen-up part of it, you wouldn't be able to see the numbers in a pasted-in image, which is why I attach a drawing file that you can open, and Zoom in to see what's going on.  The yellow Point is 0,0 from which the XY origin distances are measured.  I emphasized the first two segments in that lineset with pink wider Polyline underlays.

 

This pattern could be defined in a way that keeps all of that much closer in, depending on how precise you need the positioning between the "stars," and how close to 210° / 330° angles you want the legs.  And I would do it with 0,0 as the origin for all three linesets.  But this is what's happening under that definition.

 

[EDIT -- something was a little off; I replaced the attached drawing.]

Kent Cooper, AIA
Message 6 of 21
Kent1Cooper
in reply to: Kent1Cooper


@Kent1Cooper wrote:

....

This pattern could be defined in a way that keeps all of that much closer in, depending on how precise you need the positioning between the "stars," and how close to 210° / 330° angles you want the legs.  And I would do it with 0,0 as the origin for all three linesets.  ....


For example:

 

90, 0,0, 0,1, .44,-.56
209.7448813, 0,0, 2.23262522,-.12403473, .44,-7.62225775
330.2551187, 0,0, 2.23262522,.12403473, .44,-7.62225775

 

The "positioning between the stars" is the same 1 unit in each direction.  The two non-orthogonal angles are a little farther from 210° / 330°, but only about 1/4 of a degree off.

 

Other considerations:  Trailing zeroes do absolutely nothing for you.  And a zero before the decimal point of a number less than 1 is not needed.

Kent Cooper, AIA
Message 7 of 21
djurk_haas
in reply to: Kent1Cooper

Thanks for the explanation, but I'm still looking for how to determine the value for offset-x/y and gap.
In your example how did you determine the underlined values:

 

90, 0,0, 0,1, .44,-.56
209.7448813, 0,0, 2.23262522,-.12403473, .44,-7.62225775
330.2551187, 0,0, 2.23262522,.12403473, .44,-7.62225775

 

Message 8 of 21
richard_387
in reply to: djurk_haas

To get these values, I use trigonometry and a spread sheet to help me get sufficient accuracy.

With non-rational numbers, accuracy is the key for getting the hatch pattern to stay together the further one moves from the datum. I try to use at least 9 decimal places where needed.
A hatch pattern definition file has a few rules - one being a size limit per line of 80 spaces, and another being the need for a blank line at the end of the file. This last one can be overcome by putting an asterisk * on the last blank line. AutoCAD tolerates that and it is a visual reminder.
I find the first thing to do when defining a hatch pattern is to draw out the pattern by hand (as you have done). One can see that the repeatability of the pattern is 19across and 11up. This leads to the angle of the line which is tan-1 (11/19).
The sideways offset is 12acrosss by 7up. This length has to be resolved into a distance along the main line and and offset.
You may have noticed that all the main angles are ratios of integers. I believe this helps preserve accuracy.
I drew out the diagram below several years ago, and find it greatly helps in placing the various quantities in the appropriate place in the definition line.

Message 9 of 21
Kent1Cooper
in reply to: djurk_haas


@djurk_haas wrote:

.... In your example how did you determine the underlined values:

90, 0,0, 0,1, .44,-.56
209.7448813, 0,0, 2.23262522,-.12403473, .44,-7.62225775
330.2551187, 0,0, 2.23262522,.12403473, .44,-7.62225775


I just drew it.  I made a "star" at precise 90° / 210° / 330° angles and 0.44-unit arm lengths, and looked for a grid point not too far away and not far off the 210° direction from my origin.

Kent1Cooper_0-1692879701489.png

The white points are a 1-unit grid.  The dashed grey line is at 210° from the origin at upper right, and passes quite close to the grid point with the cyan Circle:

Kent1Cooper_1-1692879798739.png

So I adjusted the "aim" of the 210°-direction "arm" to go in that direction.  I copied a bunch of "stars" around at 1-unit grid spacing:

Kent1Cooper_2-1692879941920.png

and just measured a bunch of stuff -- the adjusted angle, the distance in DIMROTATED fashion from my origin to the closest-to-grey-line nearby segment running in the same direction, and perpendicular to that, and the pen-down-pen-up lengths:

Kent1Cooper_3-1692880781733.png

Kent Cooper, AIA
Message 10 of 21
djurk_haas
in reply to: richard_387

Thanks for the clear explanation.
Is it too much to ask to send me the spreadsheet.
Perhaps you have already created what I am now trying to create.

 

djurk_haas_0-1692882045525.png

 

Message 11 of 21
richard_387
in reply to: djurk_haas

I am very sorry but I have not got a spreadsheet. Hatch patterns need a line of code for each line, and some patterns have only a few lines and some have a lot more, so to automate that is quite beyond me. I use manual inspection to see how much each line has to be tweaked to give me an angle with an integer ratio. I don't know whether such a fussy concern with the lines could be automated. There are automatic hatch creators, but if one zooms in, one can see that the lines do not quite end at the same point!

So I use the spreadsheet purely as a tool to do trigonometrical calculations to greater accuracy than AutoCAD.

With the pattern that you are looking at, it is possible to get to an angle of 210.0000254 or even closer, but the pen up distances would be in the region of 1140.

 

I see you are only analyzing an existing hatch pattern, but with my diagram of the hatch pattern definition, you should be good to set out on your own. Are we allowed to see what pattern you will be creating?

Message 12 of 21
djurk_haas
in reply to: richard_387

 Are we allowed to see what pattern you will be creating?

 

Ofc ourse see attachement and code below:

 

*5219-Techniek,Schroevendraaier met sleutel
;Angle X start Y start X Distance Y Distance Length Gap between
0 , 0.2857491 , 0.2581132 , 1 , 1 , 0.03 , -0.97
45 , 0.3157491 , 0.2581132 , 0.7071067811865, 0.7071067811865, 0.2381030764794, -1.17611048589364
315 , 0.249392 , 0.2948739 , -0.707106781186, 0.7071067811865, 0.0519874805023, -1.36222608187077
45 , 0.5492296 , 0.5367375 , 0.7071067811865, 0.7071067811865, 0.1600000212275, -1.25421354114553
315 , 0.4177563 , 0.4928346 , -0.707106781186, 0.7071067811865, 0.0938431107797, -1.32037045159335
90 , 0.249392 , 0.2944703 , 1 , 1 , 0.03 , -0.97
45 , 0.3073367 , 0.2921272 , 0.7071067811865, 0.7071067811865, 0.2050000139395, -1.20921354843353
45 , 0.283406 , 0.3160579 , 0.7071067811865, 0.7071067811865, 0.2050000139395, -1.20921354843353
45 , 0.249392 , 0.3244703 , 0.7071067811865, 0.7071067811865, 0.2381030764794, -1.17611048589364
45 , -0.4719836 , 0.5579507 , 0.7071067811865, 0.7071067811865, 0.1599999505168, -1.25421361185621
135 , 0.5492296 , 0.5367375 , 0.7071067811865, -0.707106781186, 0.0299999951413, -1.38421356723176
45 , 0.5280164 , 0.5579507 , 0.7071067811865, 0.7071067811865, 0.1599999505168, -1.25421361185621
55.9624 , 0.6923622 , 0.6493581 , 0.8286704271912, 0.5597368337877, 0.0800000015122, -2.15677249617153
55.9624 , 0.6923622 , 0.6493581 , 0.8286704271912, 0.5597368337877, 0.0800000015122, -2.15677249617153

 

 

Message 13 of 21
Michiel.Valcke
in reply to: djurk_haas

I'm not going to mingle with the entire math discussion, but you can try the lisp in attachment. I picked it somewhere a while ago. You can make a one on one rectangle and draw your design (DRAWHATCH command gives your the details) use the SAVEHATCH command to save it. So instead of doing all this theoretical work, you can just draw it.

Message 14 of 21
djurk_haas
in reply to: Michiel.Valcke

Thanks for your lisp routine, but unfortunately it does not generate the desired result.
Green is the desired result and purple is the output of the lisp.

djurk_haas_0-1693217208299.png

 

Message 15 of 21
richard_387
in reply to: djurk_haas

Thank you for the picture and your code so far.

 

I would comment that the hatch definition does not like semicolons inside the pattern. For comment, put the semicolons and comments before the title and data lines. Or put an asterisk at the end of the data lines and any comment there.

The other point is that your lines exceed the 80 space limitation. No blank spaces are needed. You must be choosy in where the accuracy is best needed and for example, the starting coordinate of each line need only be to four decimal places. The repeat length is important being the sum of the sixth and seventh items in the list (the dash length and the pen up length). If you have the dash length as four decimal places, then the pen up length can be to nine decimal places, as long as the sum of the two is the calculated repeat length.

 

If, however you do not want to go through the math discussion, try the offered lisp and see what that produces.

 

In anycase, I will go through the pattern in my own way, but it may take a while.

Message 16 of 21
Michiel.Valcke
in reply to: djurk_haas

there's a limit in the precision of the lisp that is true. 

Message 17 of 21
Kent1Cooper
in reply to: djurk_haas

This looks like a job for SUPERHATCH.  It still wants a rectangular basis area, but it doesn't need to be square, or 1 unit in either direction.

Kent Cooper, AIA
Message 18 of 21


@Michiel.Valcke wrote:

.... try the lisp in attachment. I picked it somewhere a while ago. ....


[That came from >here<.  I recognized the name, and went looking there just to check whether there might be a newer version, but alas, no.]

 

@djurk_haas , is anything in what you drew other than LINE or POINT entities?  That Hatch Maker routine wants only those two kinds.

Kent Cooper, AIA
Message 19 of 21
djurk_haas
in reply to: Kent1Cooper

I'm sorry the drawing must be to a grid of 0,01, I just saved my existing drawing.

After adjesting de drawint to the grid the output is great!

 

djurk_haas_0-1693408475587.png

 

Message 20 of 21
richard_387
in reply to: djurk_haas

I am pleased you have got your code. Presumably, by the solutions marked, you managed to get what you want from programmable means. So I will not be posting my manual effort.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report