MoBu: Trying to find local MoBu scripts folder via Python

Hi,
I’m curious if anyone out there knows how to find Motionbuilders scripts folder via Python. I’m asking because not all of our artists have the same directory configuration and I’d like to be able to find their unique path to MoBu’s scripts folder for multiple users.

In Maya, I can use the workspace command to find were the local scripts folder is located.
Example: cmds.workspace( q=True, dir=True )

Is there anything like this available in Motionbuilder?

Much Thanks!

Tony

Not sure what you are trying to do overall, but to get a folder mapped as a favorites folder in the asset browser by name, you need to look in one of the config files.

Inside “C:\Users\suneke\Documents\MB\2014-x64\config\CPHWRK0756.History.txt”:

[Templates]
Favorite1 = C:\Program Files\Autodesk\MotionBuilder 2014\bin\config\Scripts
Favorite2 = C:\Program Files\Autodesk\MotionBuilder 2014\bin\x64/…/…/Tutorials

Here is how you get a handle to that file from within MotionBuilder:
config = FBConfigFile("@History.txt")

Note that this folder is likely not in the python path, so you can’t do import of files that are here.

Can you elaborate on what you are trying to achieve?

We have a character pipeline were we use a master Maya file to derive various LOD’s and versions of the character procedurally. In other words, the master asset gives birth to stripped down versions for the game engine, cinematics, LOD’s, and a MotionBuilder version for our animators.

The process of creating these child versions is scripted to make character updates as painless as possible. All iterations are done on a master Maya file, then in a single click, all the other versions are created and saved to their proper location in the file depot.

Because we use version control ( p4), we have different paths on different computers for our artists. Some may have a P drive, some may be on a C drive. In Maya, we use the project settings to derive were these procedurally generated assets need to live relative to their unique drive letters.

This works well until I get to Motionbuilder. In a single click, my maya script does stuff and sends the character to MotionBuilder. Once in MoBu, I run another script that creates the control rig, characterizes, makes groups, etc.

Issue 1: My MoBu setup tool also recreates Maya set driven keys with relation constraints. I merge in the constraints and connect them procedurally. Up till now, I’ve been putting the constraints file into C: Temp. I would rather put them in my P4 depot so I can administrate them remotely.

Issue2: I would also like for MotionBuilder to automatically save my files in the correct location. So I’m hoping that if I can find something like MotionBuilders scripts folder, I can derive were the file actually goes from there.

I think I could do both with help from Maya by exporting the directory info into a .metadata ( text) file with the MoBu character and having MotionBuilder subsequently look for that info when it’s doing it’s thing. It would maybe be simpler if MotionBuilder had something like a cmds.workspace command.

I hope this makes sense and thanks for taking a minute to read. Super wordy I know.

Tony

It seems like what you need to know is where Artists have the root of some P4 workspace - then make everything relative to that. Is that correct?

I’m not sure how you intend for the MotionBuilder scripts folder to help you with that, unless you somehow know that all artists will have a specific folder within their p4 workspace mapped as a favorite in the asset browser. Is this the case?

Most studios deal with defining a “project root” somehow and if you do not already do something similar, you can for instance define an environment variable or a registry key adn look that up from python. If you want to keep if simple though, you can perhaps just ask Perforce for it’s current workspace.

Other people will be better suited to help that me I’m sure :slight_smile:

Thanks for the reply Sune!

Yes, you are correct, really what I want is the p4 root or similar. Finding scripts folder was a hacky idea I had. Prob not the best solution. Anyway, thanks again for letting me bounce this off you. I’ll poke at it and re-post when I come up w/ a solution.

Cheers!

If you have the P4Python extensions available you can do something like this:

>>> import P4
>>> p4_api = P4.P4( )
>>> p4_api.connect( )
>>> root = p4_api.run_info( )[ 0 ][ 'clientRoot' ]
>>> print( root )
D:\projects

If P4Python is unavailable you can still use subprocess.Popen to call out to p4.exe to run the “info” command, pipe it to a file and parse the output in Python.

Thanks for the suggestion Adam. I dug into it a little and it seems I will need to compile my own p4 module for use with Python 2.7. I have folks who are going to help me with this but in the mean time, I’m doing it by writing a text file from Maya into C:Temp. Hacky but will work until I get a functioning p4 module.

#---Create temp text file with info for motionbuilder 
tempDirectory = 'C:\Temp' 
if not os.path.isdir(tempDirectory):
    os.makedirs(tempDirectory)

myMoBuDirectoryPath = currentFilePath.replace('Maya', 'MoBu') 
print(myMoBuDirectoryPath)
if not os.path.isdir(tempDirectory):
    os.makedirs(tempDirectory)  
    
tempFileDirectory = 'C:\Temp\MoBuPathTemp.txt'
foo = open(str(tempFileDirectory), 'w')
foo.write( myMoBuDirectoryPath )
foo.close()

Jason compiled and posted the Perforce Python API for 2014 Maya/MotionBuilder here:
http://www.jason-parks.com/artoftech/?p=579

Guys,

Real quick, I found this regarding my original post. Looks like you can fine local scripts folder this way:

directory = os.path.expanduser(’~’) + ‘\Documents\MB’
print (directory)

C:/Users/UserName/Documents\Documents\MB

Thanks! was looking for this too. :slight_smile: