Hi All, I am trying to find a way to search an entire model containing approx. 100,000 Text Fields and highlight the location of where the Text Fields only containing 2 decimals places occur.
Does any one know a way of doing this? I presume it is possible to script, but unfortunately I am not a coder…
Any help greatly appreciated! Many thanks in advance.
import rhinoscriptsyntax as rs
import re
id = rs.GetObjects("Select Text", filter = 512, preselect= False)
pattern = '\.[0-9]{2}'
for num in id:
string = rs.TextObjectText(num)
if re.findall(pattern, string):
print string
print num
rs.SelectObject(num)
You can type _EditPythonScript and paste the script above into the Python Editor.
Or create a button with the following code:
! _-RunPythonScript (
import rhinoscriptsyntax as rs
import re
id = rs.GetObjects("Select Text", filter = 512, preselect= False)
pattern = '\.[0-9]{2}'
for num in id:
string = rs.TextObjectText(num)
if re.findall(pattern, string):
print string
print num
rs.SelectObject(num)
)
This will pick up longer strings (like the 99.999 in your example). Depending on the nature of the string, you might get away with an end-string marker
pattern = '\.[0-9]{2}$'
or, if there can be characters after the decimals, include an alternate pattern which tests for delimiters such as space, +/-, punctuation. Need to check if that’s an issue with the OP.
I’d also check with the OP whether he actually wants 2 or less decimals…