Notifications
Clear all

[Closed] Problem Executing String

Here’s the problem I’m having. The script I have reads in a list of bones from a file and puts them into an array. Then, it creates a skin modifier and adds the array of bones to it. The problem is, the first time I run the script, the skin is created, but the bones are not added. But if I run the script again, it works. And continues to work each time afterwards. So the problem is just with the first time running the script.

I added a print funtion to check that the data was read in okay, and it was. The bones just aren’t added to the skin. I’m adding the bones to the skin like this.

str = "skinOps.addBone sel[1].modifiers[#Skin] $" + boneList[i] + " 1";
try (
execute str;
)
catch (
append missingBone boneList[i];
)

The boneList variable is the array which the data has been read to.
Thanks all,
Stev

8 Replies
1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

May I ask you why you want to use Execute() in the first place?
Execute() in MAXScript should be used only when everything else does not work. (This is not MEL, you know ;))
Removing the string quotes and the execute call should still result in the same code, and it would run much faster too!

I think (although I can’t be sure without seeing the rest of your code) that your boneList is in local scope, and when you use the execute method it executes the string outside of the scope of your script. To fix this you might want to add the name of the rollout or script where your boneList is initiated to your execute string then access the boneList as a property of that rollout or script, example:


str = "skinOps.addBone sel[1].modifiers[#Skin] $" + yourRolloutOrScript.boneList[i] + " 1";

You should then be able to execute the line successfully… If this isn’t your situation then I sincerely apologize!

Okay, this sounds like it could be the problem. The boneList isn’t located in a rollout. So what is the syntax for using the script name? Let’s say the it’s called “loadBones.ms” How would it look?

Thanks,
Stev

Come to think of it, I don’t think you can externally access values as properties unless they exist within a rollout or utility. A work-around would be to initialize your boneList as a global variable, then when your execute str calls on the boneList array, it should find it immediately. So you would just pull your information from your external file as normal, and write it to


global boneList = #()

The rest should work correctly… if not, then we’re completely on the wrong path

d3coy: I tried using the global variable before, and that didn’t work.

Bobo: I’m going to try that. It’s been a while since I originallly wrote this and I can’t remeber why I used the execute.

Thanks y’all,
Stev

Hey Bobo,

I remember now why I used execute(). The data in the boneList variable is a string. And the skinOps.addBone argument needs a node, right? So how can I use the variable string to execute the command?

Stev

1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0
theNode = GetNodeByName boneList[i]
if isValidNode theNode do skinOps.addBone sel[1].skin theNode 1

GetNodeByName() turns a string name into the node, or undefined if the name does not exist in the scene. isValidNode is equivalent to (theNode != undefined)
I even wrote a FAQ entry about this in the MAXScript Reference for cases like this

Working perfectly now. You’re the man Bobo.

Thanks!
Stev