HatchPatternTable.FindName bug

rhinocommon
python

#1

Hi @Alain,

i am trying to find the solid hatch pattern in Rhino 6 using the new FindName method. If i open a blank new file using any template and run this:

import scriptcontext

solid_index = scriptcontext.doc.HatchPatterns.FindName("Solid")
print solid_index

it returns None. The solid hatchpattern exists in the file, once i open the _Options dialog, click on the Hatch page entry and close the _Options dialog, then run the script again, it returns:

HatchPattern: Solid (0)

I can repeat the same behavior using the now obsolete method:

scriptcontext.doc.HatchPatterns.Find("Solid", False)

which returns first an index of -1 then 0. It does not give any deprication message in V6 and works in V5.
_
c.


(Dale Fugier) #2

Hi @clement,

What you have observed is true. Rhino doesn’t populate the Hatch table until you do something related to hatching. This is to keep the 3dm file small and efficient.

In Rhino 6, the Solid hatch pattern is hard-wired to a index of -1. So you can always retrieve it if needed.

index = sc.doc.HatchPatterns.CurrentHatchPatternIndex
print index
name = sc.doc.HatchPatterns[index].Name
print name

– Dale


#3

Thanks @dale,

i see that i can get and verify the Solid hatchpattern in V6 like this:

solid_index = -1
    solid_pattern = scriptcontext.doc.HatchPatterns.Item[solid_index]
    if solid_pattern.Name != "Solid": 
        print "SOLID NOT FOUND"
        return

But i still cannot get a hatch created. This is my code:

hatches = Rhino.Geometry.Hatch.Create(curves, solid_index, 0.0, 1.0)
print hatches
for hatch in list(hatches):
    print scriptcontext.doc.Objects.AddHatch(hatch)

and this is the output:

Array[Hatch]((<Rhino.Geometry.Hatch object at 0x00000000000000A3 …
00000000-0000-0000-0000-000000000000
00000000-0000-0000-0000-000000000000

Is there a reason why -1 is used as the default index ? I mean in the past decade this has always been a number reserved for “not found”, imho it is slightly confusing.

The reason why i try to create a hatch is btw. that i cannot get text entities to work properly in V6 using a custom font. If i add that text entity to the document, the name dropdown in the properties for Font remains empty and to my surprise a new dimension style is created with the name of the custom font. Somehow this dimension style is then used as default. If i then create a new dimension, all dimensions use that as style. Is this expected ?

_
c.


#4

@dale, here is an example script and example curve where it fails to add a hatch:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def DoSomething():
    crv_id = rs.GetObject("Curve", 4, True, True)
    if not crv_id: return
    crv = rs.coercecurve(crv_id, -1, True)
    hatches = Rhino.Geometry.Hatch.Create(crv, -1, 0, 1, 0.001)
    if hatches.Count != 0:
        obj_id = scriptcontext.doc.Objects.AddHatch(hatches[0])
        print obj_id
        scriptcontext.doc.Views.Redraw()
    
DoSomething()

hatch_fail.3dm (38.0 KB)

I’ve been using the new Rhino.Geometry.Hatch.Create method which has a tolerance argument as shown here. For the hatch pattern index i’ve used -1. The hatches are returned from the method, however if i try to add it to the doc, i only get an invalid id. The curve is reported as closed, creating a _Hatch from it in Rhino using the GUI works, but not via code.

_
c.


#5

@dale, it seems to fail with a simple circle as well using Rhino (6.6.18132.13361, 12.05.2018):

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def DoSomething():
    circle = Rhino.Geometry.Circle(10.0)
    curve = circle.ToNurbsCurve()
    hatches = Rhino.Geometry.Hatch.Create(curve, -1, 0, 1, 0.001)
    if hatches.Count != 0:
        print hatches
        obj_id = scriptcontext.doc.Objects.AddHatch(hatches[0])
        print obj_id
        scriptcontext.doc.Views.Redraw()
    
DoSomething()

_
c.


(Dale Fugier) #6

Hi @clement,

There is a lot going on there. I’ve made a YouTrack item so I can spend some time figuring this all out.

https://mcneel.myjetbrains.com/youtrack/issue/RH-46103

– Dale


#7

@dale, thanks. If i use zero instead of -1 it seems to work. But that makes no sense.

_
c.