Read File component is not working

After update to Rhino 7, Read File component is not working.
When I was using rhino 7 wip, it worked well.
Error message is “There is no valid parser avalable”

Hi - I can’t tell what’s on your yellow note but that seems to be working fine here on Rhino 7 on Mac:
Skjermbilde 2020-12-21 kl. 17.05.07
Can you upload a file that doesn’t work for you?
-wim

Thank you for your reply.
This is the gh file that doesn`t work on my Rhino 7 on Mac(version: 7.1.20343.09492)

test_read_file.gh (3.5 KB)

@wim can you check this file?

It seems to work fine in Rhino 6. Is your file really a text file?

It works in Rhino 6. But not in Rhino 7 on mac.
It seems like Rhino 7 on mac issue.

Hi -

This is what I get with your file (changed to point to a file on my system):

I’m afraid I don’t know what’s going on with that.
-wim

My Rhino version is 7.1.20343.09492
Your version is different.
Is there any version issue?

He is not alone, there is another discussion on that

I’ve now downloaded that public release that is about 5 hours older but that gives the same result here:

I know - I’ve answered and tested in that other thread as well.
David is not the developer on the Mac. I’ve asked a different developer to take a look and he will be back in the office in January.
-wim

1 Like

Thanks. it looks like same problem.
Error message is exactly same.

Thank you. I will wait for next update.
Before that I will use my custom python component to read file.

Yes, here’s a custom GHPython component that I oftentimes use instead of File, because it also has the ability to remove empty lines. Otherwise it does exactly the same stuff and should work in Rhino 7.

import Grasshopper as gh
import os

def read_lines(fpath, empty=True):
    """Reads the contents of a file line by line.
    
    Args:
      fpath: An absolute path to a file to read
      empty: By default True to remove empty lines
    
    Raises:
      OSError: '<fpath>' is not a valid file path
      RuntimeError: Unable to read 'fname'
    
    Returns:
      The individual lines of data in a list.
    """
    lines = []
    if not os.path.exists(fpath) or not os.path.isfile(fpath):
        raise OSError("'{}' is not a valid file path".format(fpath))
    try:
        with open(fpath) as f:
            for line in f:
                if not empty and (line == '\n' or line == '\r\n'):
                    continue
                lines.append(line)
    except:
        basedir, fname = os.path.split(fpath)
        raise RuntimeError("Unable to read '{}'".format(fname))
    return lines

## -----------------------------------------------------------------------------

if __name__ == "__main__":
    # Manaage inputs
    if Path is None:
        e = "Input parameter Path failed to collect data"
        ghenv.Component.AddRuntimeMessage(
            gh.Kernel.GH_RuntimeMessageLevel.Warning, e
            )
    if PerLine is None:
        PerLine = True
    if Empty is None:
        Empty = True
    
    
    if Path is not None:
        # Read data from file
        lines = []
        try:
            lines = read_lines(Path, Empty)
        except Exception as e:
            ghenv.Component.AddRuntimeMessage(
                gh.Kernel.GH_RuntimeMessageLevel.Error, str(e)
                )
        # Output data
        if PerLine:
            Data = lines
        else:
            Data = "".join(lines)

You can use it until the bug is fixed and beyond, if you want to.

read_file.gh (4.6 KB)

2 Likes

Great! Thank you for your help!

you’re a real life saver - thank you!

hi all
i have a problem in HoneyBee_masses2zones. when i connect Brep to HoneyBee-intersectmasses and then HoneyBee m-masses2zones,it has a error.
the error is:

  1. Checking normal directions failed:
    AttributeError("‘NoneType’ object has no attribute ‘Centroid’",)
  2. Runtime error (MissingMemberException): ‘NoneType’ object has no attribute ‘Centroid’

Traceback:
line 5454, in getSrfCenPtandNormal, “”
line 5358, in getGHSrfNormal, “”
line 5367, in decomposeZone, “”
line 165, in main, “”
line 180, in script

could you help me please


newM.gh (653.0 KB)

Hi Mahsa -

For help with the Ladybug Tools, please visit https://discourse.ladybug.tools/.
-wim

1 Like

does this only work with txt files? im trying to get it to read word files (.docx) and its note working, just get whatever is in the screenshot

Hi Josh -

What you get in Grasshopper is the same as what you would get when opening any file in Microsoft Notepad. What you see in the screenshot is expected.
-wim