How to search all Rhino .3dm files in a directory for specific text?

rhino
python

#1

I know I’ve made a note in a drawing having the phrase “ball bearing” but I’m exasperated looking through all the files one-by-one and am wondering if there’s a better way than opening each file and searching for it.
Huge thanks in advance. ~ David


#2

Hi David,

if you made the note in the notes panel then you can may extend this script:

import Rhino
import System

def BatchReadNotes(dir):
    files = System.IO.Directory.GetFiles(dir, '*.3dm', System.IO.SearchOption.AllDirectories)

    for file in files:
        notes = Rhino.FileIO.File3dm.ReadNotes(file)
        print "file: {0} - notes: {1}".format(file,notes)

if( __name__ == '__main__' ):
    dir = 'D:\\YourDir\\Dir'
    BatchReadNotes(dir)

Jess


#3

Thanks Jess! Evidently the text wasn't in a text panel.
I guess it was in a text box.
Thanks again.
David


#4

Thanks Jess! Evidently the text wasn't in a text panel.
I guess it



From: Jess Maertterer ;
To: ;
Subject: [McNeel Forum] [Scripting] How to search all Rhino .3dm files in a directory for specific text?
Sent: Tue, Nov 15, 2016 1:01:20 PM

Jess
November 15

Hi David,

if you made the note in the notes panel then you can may extend this script:

import Rhino
import System

def BatchReadNotes(dir):
files = System.IO.Directory.GetFiles(dir, '*.3dm', System.IO.SearchOption.AllDirectories)

for file in files:
notes = Rhino.FileIO.File3dm.ReadNotes(file)
print "file: {0} - notes: {1}".format(file,notes)

if( name == 'main' ):
dir = 'D:\YourDir\Dir'
BatchReadNotes(dir)

Jess


Visit Topic or reply to this email to respond.

To unsubscribe from these emails, click here.


#5

Hi David,
the format of your post is a bit messed up. I understand that you found the file?
Otherwise it would be possible to read the geometry into memory and search for objects, geometry, names, text…

Jess


#6

I’m not surprised that the format of my post was a bit messed up. I was replying on my cell phone since there is no internet service at the residence I just moved into. I have to drive to the local university library (Texas Tech in Lubbock, TX) to get a secure network connection.

I was able to copy the code and run it successfully. It went through all the files in the directory but didn’t find any text in any notes.

I’ve no clue as to how to read geometry into memory and search for objects, geometry, names, text, etc.

Thanks again.

David


#7

David,

do you remember how you made the note? If you made it with a _TextObject then I think there is no way to find it. If you made it with the _Text _Leader or _Dot command, then it should be possible.

Jess

BTW: Where did Frank N. Furter go? :wink:


#8

Hi Jess,

I am also looking for a way to search for Rhino files based on key words found in the “Notes” panel, but I have no idea what to do with your script…
Do I print it on a CD cover and feed it to my CD-ROM player ?
Do I read it out loud wearing a voodoo costume whilst I chop-off a goat’s head ?


#9

Hi @osuire,
Mitch made a nice summary of the different ways how to use scripts:

HTH,
Jess


#10

Hi Jess,

Since I don’t program using Python, I failed to identify your script as a Python script, since I also didn’t notice the section in which the message was posted :confused:
If I understand well, I need to run this script from within Rhino, and it will allow to search for Rhino files in a folder, based on key words ?


#11

The script below will simply print for each file in the selected directory the filename and it’s notes to the command history.

import Rhino
import System
import rhinoscriptsyntax as rs

def BatchReadNotes(dir):
    files = System.IO.Directory.GetFiles(dir, '*.3dm', System.IO.SearchOption.AllDirectories)

    for file in files:
        notes = Rhino.FileIO.File3dm.ReadNotes(file)
        print "file: {0} - notes: {1}".format(file,notes)

if( __name__ == '__main__' ):
    dir = rs.BrowseForFolder()
    if dir:
        BatchReadNotes(dir)

This could be made more comfortable…
What are you searching for?
Jess


#12

Hi Jess,

What I’m looking for is a way to convince McNeel to expose the content of the Notes to the Windows indexing engine so that searching for Rhino files could be done using key words in the Windows file explorer as it can be done for many formats containing text.
Failing that, I guess I could settle with a python script performing a similar task from within Grasshopper with a little bit of Human UI magic.

Cheers,


(Dale Fugier) #13

It’s on the list.

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

– Dale


(Nathan 'jesterKing' Letwory) #14

I suppose that makes my added YT item a duplicate https://mcneel.myjetbrains.com/youtrack/issue/RH-41374


(Dale Fugier) #15

Hi @nathanletwory,

Yep, sure does. I’ve updated the new item.

Thanks,

– Dale