Hello everyone,
I am a little stuck with user inputs.
I am trying to create a window where the user can write the name of the fbx they want to import then pass it on to the string that contains the file path to open that fbx. I have tried different combinations but I getting only errors. I thought I was closed, but I cant seem to understand how to pass the string variable.
Code:
if(`window -exists expWindow`){
deleteUI expWindow;
}
//Create Prompt Dialog Window...
string $userInput = `promptDialog -t "Anim Import" -message "File Name" -button "Process"`;
//If button is clicked, run the following commands...
if ($userInput == "Process"){
//Query the text in Prompt Dialog's name field...
string $userInput_text = `promptDialog -q -text $userInput`;
//Import FBX File with the specified namespace.
$myFilePath = "D:/Desktop/Animations" + $userInput + ".fbx";
file -import -type "FBX"
-ignoreVersion -ra true -mergeNamespacesOnClash false
-namespace $userInput -options "fbx" -pr -importFrameRate true
-importTimeRange "override" $myFilePath;
}
But I get one warning and one error:
// Warning: Line 5.91 : Redeclaration of variable "$userInput" shadows previous declaration at line 1. Previous value will be overwritten by explicit initializer. //
D:/Desktop/Animations/Process.fbx// Error: line 21: File not found. //
I don't know why it is printing Process. I thought I was close but I can't figure out how to pass on the user input to the end of the string.
I would love your help ! Thank you.
Replies
the $userInput will always be exactly "Process" because its the condition of the if statement.
Try to use this line for your user input:
$text = `promptDialog -query -text`;
Maybe this will help you:
string $text;
string $result = `promptDialog
-title "Rename Object"
-message "Enter Name:"
-button "OK" -button "Cancel"
-defaultButton "OK" -cancelButton "Cancel"
-dismissString "Cancel"`;
if ($result == "OK") {
$text = `promptDialog -query -text`;
print ($text + "\n");
}