PDA

View Full Version : Extract number from object name?


cboath
01-30-2009, 03:18 PM
....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.

Piflik
01-30-2009, 05:01 PM
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 :D

Edit: Missed a line... :banghead:

ZeBoxx2
01-30-2009, 05:23 PM
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

MoonDoggie
01-30-2009, 05:34 PM
nevermind :)

cboath
02-04-2009, 01:40 PM
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 :)

CGTalk Moderation
02-04-2009, 01:40 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.