0

Part 1: Copy Script

I have scripts on my computer that I want to continue to develop. These scripts work as embed scripts in maya files, so that people who open the file will get the tool upon opening it. I want to build in an update function, so that when I open the file, the version in the file will check against my local version, and if my local version is a higher version number, it will update to my script. I know how to replace the string value in maya, but i'm not certain how to copy the string value from an existing python file.

How can I copy the text from within a script to a string value? (preferably containing /n and indentation, while I'm at it)

version = 3.1
Try:
    import ToolBox
    if ToolBox.version > version:
        #do copy stuff

Part 2: Multiple Script Files

My script uses several separate files (simplified concept bellow)

file Hammer
    class Type():
        #force stuff
    def strike():
        #strike stuff
file Nail
    Class Type():
        #Type stuff
    def bindTogether():
        #bind stuff
file Wood
    #wood stuff..

file ToolBox
    Import Hammer
    Import Nail
    Import Wood
    def buildBox():
        #buildBox stuff using hammer, nail and wood

Can I import these into a class within my script and use them pretty much the same as I am now? If not, what can I do?

File Toolbox
    Class Hammer:
        class Type():
            #force stuff
        def strike():
            #strike stuff
    Class Nail:
        Class Type():
            #Type stuff
        def bindTogether():
            #bind stuff
    Class Wood:
        #wood stuff

    def buildBox():
        #buildBox stuff using hammer, nail and wood
  • First you need to compare version strings properly http://stackoverflow.com/questions/11887762/how-to-compare-version-style-strings – stark Sep 14 '15 at 21:50
  • Thanks for the tip! Thinking on this problem, I'm wondering if I might not try to copy open script but instead us the open file function in Python to get the text that way. If that works, I can then grab lines and parse together the lines into a large string, which is easy to input in the maya script node. The only question then, if this works, is whether I can class within class and still have it function how I like? – Colin Knueppel Sep 14 '15 at 23:41

1 Answers1

0

I think you want to reconsider the approach you're proposing. Distributing things piecemeal is asking for trouble: if your users get different code depending on what's going on on your machine and also on the order in which they do things, you can potentially get lots and lots of different states on different machines so each user can get their own unique set of bugs. You want to distribute the tools and download the tools as a unit so the user gets a complete suite of tools at a time, not one at a time.

The simplest way to do give your users an environment variable that points to a network share. Your userSetup.py can use that to copy the contents of the whole share to the users when they start up; that way the users get the same versions of everything. You need to be careful to delete any existing .pyc files as part of the process, since leftover pycs can fool python into using the wrong code.

Another option to consider is using Maya module files. Once you give every user a module file that points at your network share everybody can work directly off a network share. It doesn't scale well for hundreds of users but for a dozen or so it works fine: see http://techartsurvival.blogspot.com/2014/01/mayas-mildy-magical-modules.html

If you want to read up on some of the issues involved try:

theodox
  • 12,028
  • 3
  • 23
  • 36
  • The core functionality of the program will remain the same. The updates will add additional tools to a tools tab. While I understand your point, I know my circumstance. I can't always be certain that everyone on my team, who happen to be all over the world and sometimes on laptops, will have access to the latest scripts. But I do know they'll have the maya file. Having it just work regardless of lacking supplementary files is really the ideal tools approach in my situation. – Colin Knueppel Sep 15 '15 at 01:35
  • It's pretty easy to add a simple bailout if the net share is unavailable so the users. But your example involves importing and then calling code, not just data -- and if the files on either end (the host file or the plugin) are mismatched the whole thing will break -- the core code won't know about the existence of new tools and the new tools may expect different libraries or apis. – theodox Sep 15 '15 at 15:59
  • The tool I created is a timeline manager. It creates nodes within the scene under the timeline object and writes attributes for things like start, end, loop, relative to start, etc.. With the script embedded, and the information on nodes within the scene, one only needs open the file, and the timeline tool opens and states which animations are there. The nicety of this approach is that anyone can take the file, me or my successor, and see the animations regardless of what scripts may or not be still existent. There's nothing to maintain. It works beautifully except the updating. – Colin Knueppel Sep 15 '15 at 17:17
  • You're stuffing it all into a scriptNode? – theodox Sep 15 '15 at 17:18
  • Yeah. Executes on startup. Window appears with anim list to select from. – Colin Knueppel Sep 15 '15 at 18:42
  • You can write the whole thing as a python package, zip it, then stuff the binary contents of the zip file into a fileInfo. When you need to code, look for it in the user's $MAYA_APP_DIR; if there's no zip, write the contents of the fileInfo to disk as a zip and then insert the zip into `sys.path` – theodox Sep 15 '15 at 21:30
  • I like this last idea. I can not only have it work out of the file, but it makes an automatic distribution among the files. I could even program it to almost be an infectious update process, where newer files would upload into older files. Pretty neat. :). I see the last link you posted shows how to make the zips. I'll need to investigate this for a future update. Thanks! – Colin Knueppel Sep 17 '15 at 02:59