Monday, March 21, 2011

SOFTIMAGE: How to convert those annoying 4 spaces into beautiful tabs

If you recycle code from other people you might find sometimes code indented with spaces instead of tabs. At least, to us that's quite annoying, so if you want to transform all your "4 spaces" into tabs do this:

- In the "Script Editor" go to "File" - "Preferences..."
- Enable "Show Whitespace"
- Go back to the code and be sure you have visible at least a group of 4 spaces (····) and a tab (→)
- Select a set of those 4 spaces and press Ctrl + H. That'll open the "Replace" tool with the 4 spaces added to the "Find what:". Don't try to simply press space four times in there, that won't work. Don't press any of the buttons from that window yet.
- Go back to the code, copy the tab symbol (→) and return to the "Replace" window. Paste it into the "Replace with:" blank. Now you are ready to press "Replace All"
- ZUUUUUUUUUUUUUMBA!!!

In case you want to post code in your blog...

This blog has a pretty cool javascript application to format code to post it later in your blog. Check it out :)

http://formatmysourcecode.blogspot.com/

Anyway... if you know a better site, or one with color formatting let us know.

SOFTIMAGE: Starting with IF EXIST

Hi all. We'd like to start this blog with a simple script to check if the given object exists or not. The function returns "True" or "False" depending if it can or can't find the object, so you can check very easily with an IF if what you want is in the scene. VEEEEEEEERY useful, and "A MUST" to have at the top of your scripts.


#CHECK IF AN OBJECT EXISTS

def Exist(input):
    if Application.Dictionary.GetObject ( input, False  ) != None:
        return True
    else:
        return False

#TESTS
if Exist("sphere"):
    print "The object 'sphere' exists in the scene"

if not Exist("cone"):
    print "The object 'cone' doesn't exist in the scene"