Align Hatch Patterns

Hello all,

Long time Rhino user here, not quite experienced with Python.

I am trying to work out a script that matches hatch patterns, to bypass an issue with Rhino’s own “Match Pattern” command.

Specifically: For hatches created while using various CPlanes, the rotation is stored as “Relative to the Hatch Plane”. So you can match the pattern but say if the desired rotation is 45°, every hatch will turn to 45° from the cplane in which it was created.

I haven’t been able to either modify that cplane info, or even just access it, which would allow me to at least create new hatches with the desired attributes and delete the old ones.
Is there a specific hatch class attribute that I can call? I haven’t found anything in the available documentation…

Any suggestions would be extremely appreciated,
Thanks in advance!

M

Hi @skitsasm, you might take a look here: Hatch.PatternRotation.

Edit: you might also be able to script the _HatchBase command.
_
c.

1 Like

Hi Clement, thank you for your reply.

I’ve tried getting the Pattern Rotation info, which returns unfortunately angles relative to the cplane in which the hatch was created, not an absolute angle.
In the following file for instance, the left hatch returns a value of 0.78 radians (45°) while the right one returns 0, because I had changed the cplane before creating it.

hatch example.3dm (43.1 KB)

There seems to be a “Geometry Base” attribute here but I get “Cannot create instances of GeometryBase because it is abstract” when I try to see what it is.

Hi @skitsasm,

how did you measure the angles ? Please try below, it returns 45° for the left and 43.1142° for the right:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
import math

def DoSomething():
    
    hatch_id = rs.GetObject("Select hatch", rs.filter.hatch, True, False)
    if not hatch_id: return
    
    hatch_obj = rs.coercerhinoobject(hatch_id, True, True)
    hatch_angle = math.degrees(hatch_obj.Geometry.PatternRotation)
    
    print "Angle: {}".format(hatch_angle)
    
DoSomething()

Does this help ?
_
c.

@dale, for the problem described above:

it would indeed be helpful to access the Plane info a hatch was created in. If a hatch is created in say a CPlane which was 25° rotated, its PatternRotation is returned as 0.

_
c.

@clement thank you very much for the reply, again.

I had checked using the rhinoscriptsyntax command, not the Rhino class attribute.
Having a bit of trouble distinguishing between the best way to get to it since a lot of things are accessible both ways, and as I said, I’m pretty much a complete amateur.

thanks again!

Coming back to this because it’s still not producing the desired results.

Perhaps I messed up the example file I sent because in subsequent tests the returned values are still corresponding to the c-plane used in creating the hatch…

The hatch objects seem to keep some mystic memory of their creation that they’re not willing to share…
Unless this attribute (creation c-plane, for lack of a better word) is stored in all objects and is inaccessible, and only becomes relevant with hatch pattern direction…

@skitsasm, i can repeat what you see and don’t think there is a reliable solution for it.

I’ve tried to workaround this and access the hatch geometry (the first line of it) and measure angles to a temporary hatch and it’s first line using the same pattern and scale but you’ll never know if the patterns give the same line to access as the one you’re trying to measure from.

Unless there is a method to access the plane a hatch was created in, there is no way to measure this angle in relation to the world cplane properly.

_
c.
_
c.