Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk® MotionBuilder® / Python / Passing enums from concatenated strings
  RSS 2.0 ATOM  

Passing enums from concatenated strings
Rate this thread
 
60654
 
Permlink of this thread  
avatar
  • Total Posts: 6
  • Joined: 14 September 2011 12:38 AM

Hello everyone,

I’m not sure if this is a MotionBuilder question, but here goes…

I’m trying to procedurally generate enums based off of input from a UI, I can grab the info and format it to which enums I want to use, but am having difficulty passing this as an argument (as it’s now a string).

Has anyone had any success doing this?

Any help appreciated, thanks in advance.



Replies: 0
avatar
  • RyanTTF
  • Posted: 10 October 2011 07:05 AM

Without any code or a simplified example it is a bit difficult to understand the problem. However, if you have a string and want to turn it into an Integer in python you simply wrap the variable in int() you can also force objects to

str()#string
#and
eval()#which will evaluate a string

Although I think you already know of these, because you are using Classes and enums which is not low level code. I recommend you post a quick example or error you are receiving.



Replies: 0
avatar

Hi Ryan,

Sorry for the delayed response.
Here’s a simplified example of what I was asking. The first block should be executed separately, then the second block.

#BLOCK 1
FBModelMarker('test')
m.Show True
m
.Look FBMarkerLook.kFBMarkerLookSphere

#BLOCK 2
##passing an enum as a string fails...
enumString 'FBMarkerLook.kFBMarkerLookHardCross'
m.Look enumString

In my tool, enumString is what I create procedurally. But when I try to use this string, I get an argument error. Kinda makes sense, but I’m not sure what to do in order for it to let me parse the variable as an enum.

Any thoughts appreciated!

Thanks.



Replies: 0
avatar
  • RyanTTF
  • Posted: 20 October 2011 10:48 AM

Now I am sorry for the delayed response haha.

So the problem is that you are passing a string “FBMarkerLook.kFBMarkerLookHardCross” where the m.Look is searching for a specific argument.

by wrapping your string in eval() python no longer treats your string the same way.

if you do

FBModelMarker('test')
m.Show True
enumString 
'FBMarkerLook.kFBMarkerLookHardCross'

m.Look eval(enumString)

Let me know if that works. I did not receive any errors…



Replies: 0