Introduction to Maya - Modeling Fundamentals Vol 1
This course will look at the fundamentals of modeling in Maya with an emphasis on creating good topology. We'll look at what makes a good model in Maya and why objects are modeled in the way they are.
# 1 15-02-2016 , 07:00 AM
Registered User
Join Date: Feb 2016
Posts: 6

How do I convert an item from an array into a string variable

I'm trying to get a string array containing the selected objects ( $objectsArray[ ] ), and then I would like to only get the first item from that array and put it into a regular string variable ( $onlyFirstObject )

string $objectsArray[] = `ls -selection`;
string $onlyFirstObject = $curvesArray[0];

This doesn't work. What's the correct way to get only the first item in a string array, and store it in a string variable?

# 2 15-02-2016 , 05:58 PM
PixalZA's Avatar
Lifetime Member
Join Date: May 2011
Location: Riyadh, Saudi Arabia
Posts: 525
You have a small typo in the script. Set $onlyFirstObject to $objectsArray[0].


Earth: The crazy asylum of the universe.
# 3 15-02-2016 , 08:44 PM
Gen's Avatar
Super Moderator
Join Date: Dec 2006
Location: South FL
Posts: 3,522
The first element in an array is always at position zero.

Code:
string $mySelection[] = `ls -sl`;
string $firstObj = $mySelection[0]
$mySelection[0] is already a string variable, just not as elegant as $firstObj


- Genny
__________________
::|| My CG Blog ||::
::|| My Maya FAQ ||::
# 4 18-02-2016 , 05:08 AM
NextDesign's Avatar
Technical Director
Join Date: Feb 2004
Posts: 2,988
Just a nit-pick, but you should check if the length of the array is greater than zero before you choose the first element. user added image


Imagination is more important than knowledge.
Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads