Help converting a label system

I have a script that uses
a list to check against,

it grabs the last 2 pieces of a material name with “hitID = int(hitMat[-2:])”

like Sensor_01

it would turn into


this works great, until I get to 10,

can some one help me change the system so that it does not break if I get to 10?
I would just use lables like A B C D etc, but the script is set to do math using the label…

is there a easy way to do item = item -“Sensor_”

hitMat = hitPoly.material_name
# check the material name if it contains a string value
if ‘Sensor_’ in hitMat:
# get the suffix of the material name
hitID = int(hitMat[-2:])
# get the material’s pair from the pairs list
pair = pairs[hitID-1]

You’d probably want to use regex. I’ve not much experience with it but there are many tools on the Internet that can help you. It’s available in the python standards library

thank you, I am looking at all the /*[] 's and going crosseyed :slight_smile:

I will take some time and try and master it :slight_smile:

Thank you kind sir :slight_smile:

how about this???

if hostID => 10
hitID = int(hitMat[-3:])

The reason it’s breaking when you get to 10 is because of hitMat[-2:]. If you change this to -3 and start using the naming convention Sensor_001 you should be able to handle more objects. Or [-4:] and use Sensor_0001 etc…

I tried that about 2 hrs ago,
Index out of range

not that I know why,

I tried

if ‘Sensor_’ in hitMat:
if hostID=>10:
hitID = int(hitMat[-3:])
if hostID<10:
# get the suffix of the material name
hitID = int(hitMat[-2:])
here is the script in full @ the moment it generates a null without failing

Check this out:

import re


def get_suffix_int(string):
    regex = re.compile('.*?(\\d+)',re.IGNORECASE|re.DOTALL)
    search =
    if not search:
    int_a =
    return int_a


JOY!!! thank you kind sir

import re
txt=‘Sensor_005’re1=’.*?’ # Non-greedy match on fillerre2=’(005)’ # Integer Number 1rg = re.compile(re1+re2,re.IGNORECASE|re.DOTALL)m = m: print “(”+int1+")"+"

now to figure out how to turn re-write it to edit the material list and output a “index”

It’s a function and an import statement. Simply copying the function and import then passing a name to the function will return the integer as a string.

Another option you have is to String.split("_") your names.

str = "Sensor_01"
str2 = "Sensor_100"


This assumes that you don’t use “_” in the same of your sensors.

Thank you, that makes this much easier,

hitID = int(hitMat.split("_")[1])


dataset = [‘Sensor_01’, ‘Sensor_02’, ‘Sensor_03’]

for i in range(len(dataset)): dataset[i] = dataset[i].replace(‘Sensor_’, ‘’)
print data-set

Ok so it is now working :slight_smile:

Now I just need to work on firing the script if the property “FaceIndex_X” changes from “empty” instead of using hostID,

then I will have it pass the property “FaceProperty_X”

Edit:Sorry about double posting