Notifications
Clear all

[Closed] Extract number from object name?

…and then use it as an integer?

Is this possible?

Basically, i’m trying to use it as a multiplier. If the object name is object04, i want to multiply by 4, etc.

I’m admittedly not not much for scripting, but i’ve got a string of objects i’m trying to wire together, and this would save a lot of manual editing if I can just copy an object 100 times or so that has the wire code embedded in it.

4 Replies

You can collect the objects into an array and use the index as multiplier (methinks)


theObjects = $object* as array
sort theObjects --if you didn't create the objects in the right order or renamed them
for i in 1 to theObjects.count do 
(
theObject = theObjects[i]
Multipier = i
)

Might work

Edit: Missed a line… :banghead:

Note that Piflik’s approach will always start at one, even if the first object in the (sorted) array is, say, Sphere05.

Here’s another approach:


obj = $GeoSphere05
$GeoSphere:GeoSphere05 @ [0.000000,0.000000,0.000000]
numberString = subString obj.name ((trimRight obj.name "0123456789").count + 1) -1
"05"
numberInt = numberString as integer
5

nevermind

I did a lot more searching and found the tank tread tutorial and was actually able to adapt that to what I was trying to do.

Took a while since I don’t really know scripting, but it worked and I actually learned a little bit, too.

Thanks