A Shell Script That Uses Imagemagick's Identify to Generate a List of Corrupt Images
I have a folder of a ton of images and it has a lot of corrupt images in there. Instead of manually editing them out, I made a shell script to use the error code from ImageMagick’s “identify” command to flag them as corrupt and generate a list of those files that can then be easily moved or deleted by another shell script.
while read FILE
identify "$FILE" ; if [ $? -eq 139 ]; then echo "$FILE" >> ~/Desktop/deadfiles.txt; fi
The “$? -eq 139” part is using the segmentation fault error code (if error code is equal to 139) to identify the dead files. Pipe a list of images to the script with “find” and the script will do all the work of finding the corrupt images with identify:
30,000+ images dealt with and no false positives. If you ever need something like this, feel free to use my deadfilefinder. If you’re interested in the sed command I used to prefix and suffix the file paths for the move at the end, it’s:
I just had a Nuke scene script go bad for whatever reason and I am in the process of rebuilding my Time Machine backups so I was screwed until I realized that Nuke files are plain text (this is what makes the contents searchable with Spotlight in OS X). So I opened the script file in BBEdit and pasted the scene nodes into a new Nuke clipboard and then pasted the combined clipboard into Nuke.
I left out the main scene info so I’m guessing that’s where the problem was.
Automator Action for V-Ray Nightlies Unrar and Install
I install a lot of V-Ray nightly builds so I made a one-stop right click Automator service to handle the whole unrar with password and sudo install process. Install unrar into /usr/local/bin/ and grab the Service: nightlies.workflow.zip
Then open it in Automator, put the nightly password in the unrar command (it’s removed in the Service and I won’t give it out) after the -p with no space so it’s unrar -pPASS. It’s the dumbest use of command line flags I’ve ever seen but that’s how it works. Then save the .workflow file to ~/Library/Services and witness the magic of saved time.
Another Unix Maya Shell Script Renderer Tip: Auto-set Project Path
The cool thing about declaring variables inside a shell script is that you get to use all your Unix tools to filter those first. That means you have tons of ways to parse input, simply by setting up your variable declaration like this:
So, to get a command line render to set the Maya project directory automatically by the Maya file’s parent path, we just have to use two commands to get the directory where the file is and strip out “/scenes” to set the -proj path:
projectpath=`dirname "$@" | sed 's%/scenes%%g'`
dirname is a built-in utility that gives the directory name for a file. That is then piped ( | ) to sed, which does a find and replace of “/scenes” with nothing. That gives us just a path without the file name and without scenes, which is our project path. Then our $projectpath variable is used in our render shell script:
That obviously assumes that you’re using the traditional Maya project/scenes/file structure to set up your Maya projects. So, this should save you from having to worry about what project is currently active and ending up with images from different projects mixed up.
Dear Mr. Girard.
I found your solution concerning the mystical vanishing of the one-click-interop-plugin in maya 2012. I have a little different problem: The plugin is loaded, the "send to mudbox"-button opens mudbox 2012, but the scene won't open? status is reported as "connected to mudbox", the *.fbx for interchanging can be found in temp-folder - but the scene doesn't open automatically. I use maya 2012 and mudbox 2012 trial on two identically installed machines (win 7 x64). one system has no problem with that function, the other has. any ideas or ever heard something similar? Kind regards, Dirk.
ya, I’m seeing this occasionally too. Mudbox and Maya interop is currently flaky at best, regardless of OS.
Make An Interactive Render Shell Script for OS X and Linux
With relatively no knowledge of shell scripting, it’s easy to make an interactive shell script that takes your input and turns them into variables. It’s perfect for making a render batch script, where you often have a lot of constants (your renderer, threads, etc.) that you don’t want to type, but you have something like the frame end and start points that you want to specify on a per-render basis. There are some GUI utilities that do this but the command line method uses no additional resources and lets you tell it exactly what your variables will be from now on. Just add some prompts with “echo” and that will look like it asks for input which is specified with “read”:
The variable is the part after “read” so that render command at the end takes the path input ($@) and sends it to the render command with your input variables. In C or shell scripts, variables are declared without the $ at the start but in MEL, they are declared with the $. The double quotes around the variables ensure that any spaces in the names or paths will not cause problems for the shell, which can trip on those otherwise. That simple shell script makes for a pretty nice little tool:
Even after years of knowing to keep this in mind, I invariably find myself forgetting to enable reflections and refractions for OBJ meshes that have been imported into Maya. There is a longstanding bug (or at least an annoying default behaviour) where imported OBJ meshes have their reflection and refraction flags turned off. You have to turn these on for every object or else you won’t get reflections and refractions. Considering how prevalent OBJ files are as a go-between for apps like Headus UV Layout, Mudbox, ZBrush, etc., that’s a pretty bad problem. So, to save myself wasted time, I added this MEL script to my Render button in V-Ray Tuner. Grab the code here. Put it in your scripts folder and run it with “source render_with_warn.mel;”
It won’t prevent any rendering, but it will give me a warning that it found a mesh with the .visibleInReflections set to 0 and select the meshes. See it in action with a demo of the problem:
Super Fast Lossless JPEG Rotate Service / OS X Droplets
I needed to do some lossless JPEG rotation today and discovered NConvert, which is amazingly fast. It’s so fast that I decided to make my Automator services threaded so that each image conversion is launched in its own thread. The shell script code from my Automator service/droplets:
The & at the end of the line means “launch in the background,” so doing this for multiple selected images just happens all at once:
That & thread spawning will work for any command line app, so if you want to update my FBX Converter or other sips conversion services that use the same “while read/do” syntax, go nuts. Obviously, it’s probably a bad idea to do a few hundred of those at once but for small batches, where it’s around the number of cores in your machine, it’s fine.
The Maya 2012 Bonus Tools are out and have lots of great stuff in them. The 3DS import plug-in is fixed for 64-bit versions of Maya for Mac. Here’s a quick tip to make the menus shorter so you don’t have a long “Bonus Tools” eating up valuable real estate in the menu bar. Open the bonusToolsMenu.mel from the shared scripts folder (on OS X it’s in /Users/Shared/Autodesk/maya/2012/scripts/) and replace the line:
string $bonusMenu = `menu -label "Bonus Tools"
string $bonusMenu = `menu -label "BTs"
and you’ve got a nice short menu:
Update: in Maya 2014, this menu file has moved to /Users/Shared/Autodesk/ApplicationAddins/MayaBonusTools2014/Contents/scripts/bonusToolsMenu.mel
Made Two Upload and Link Copy File Services for Dropbox and FTP
After getting tired of Tinygrab flaking out (it was fun - thanks for the uploads), I decided just to make two Automator right click services to handle uploading and sharing links. They work pretty nicely:
The Automator code is quite simple:
Download the service files, Drop in your relevant Dropbox or FTP account info and install ncftp and you’re ready to go once they are installed into your ~/Library/Services folder. The only issue is that you need to store a password in your ncftp service for it to work, so some people may not like that. I made a no-access FTP user account just for this purpose. Also, if you’d rather copy the file to the Dropbox folder, not move it, replace the “mv” in the service with “cp” and it will copy the file. The sed bits at the end replace spaces with %20 so that the links work correctly if your file has spaces in the name. Enjoy.
Fix for Missing "Send to Mudbox" menu in Maya 2012
I had this go missing and after some back and forth with the peeps at Autodesk, the fix is to remove your Maya preferences folder and have it create new ones. You can then quit Maya, copy back your old prefs and the menu will still appear. Weird.
Z-fighting is one of those things that, if you don’t know what you’re looking at, will drive you crazy until someone tells you what’s going on. For a long time when first learning Maya and then later when making a map for Quake 3, I experienced this frustrating phenomenon so I thought I’d make a post to tell you what it is and how to get rid of it.
Feast your eyes on this nasty bit of garbled mesh:
That is two pieces of geometry (a grey plane in front and a red one in back) in very close proximity. What is happening is your video card is unable to determine which object is in front, so it’s showing a bit of both. The problem gets worse when you work with cameras that are far away and have a long focal length. To fix this in Maya, select your camera and either reduce the Far Clip Plane or increase the Near Clip Plane:
Mine was deliberately set to something very low and very high respectively to show the problem that can happen from using very distant values. Increasing my Near Clip to 10 completely got rid of the problem:
Obviously that’s a very high near-clip value so, if you’re working close up, you’ll need to lower the Z-clip so that you can once-again do tight work on your models. If you are experiencing this problem in renders, it’s most likely lamina faces — maybe you hit extrude and didn’t move the faces.
If you’re looking for the source code and XCode project, I made a backup of the old 2009 version: grab from here. I don’t support these products in any way and I can’t build them on request. See the link to Comet’s info page above to see when this might come in handy to you.
Using Undo Feedback from the Maya Script Editor to Do Edits
After using Maya for a while, I realized that when you undo something, the command is shown in the Script Editor feedback and that this could be used as a quick way to do repeated transformations without opening the Script Editor (the operation is shown quietly in the Script Editor if you want to avoid using undo but you need to open the SE window otherwise). Make a translation or whatever, undo it and copy and paste that value into the MEL command field to have done again. Then when you need that exact operation again for another edit, select the MEL command field, hit up arrow and it’s recalled for the next operation:
It’s a good way of storing edits that aren’t added to the History but that you might want to do repeatedly. For Unix shell or command prompt newbs, hitting up arrow always recalls the last operation you did with the terminal so this recall behaviour is a classic Unix behaviour. Similar to the Unix bash history, the MEL or Python command history can be recalled by hitting up arrow repeatedly. It’s a handy active workspace but, unlike Unix shells, it’s not stored in a central file, so it will be cleared when Maya quits or crashes.
Mac Cocoa Code Editing Tip: Select a Vertical Block of Text
There’s a cool trick in Cocoa-based text editors (BBEdit, Terminal, TextMate, etc.) that lets you select text in a vertical block when you hold the option (alt) key while dragging:
Obviously it’s not clear what you’re selecting in Pages, since it’s not using a monospaced font. Anyway, I’ve used this a few times to strip out file lists from console output. If you have BBEdit, it installs a command line utility that can send standard output to BBEdit:
Often the source material you have for a texture isn’t ideal, forcing you to do some finicky Photoshop work to remove distortion. This has always been most complicated when you have a curved surface and you need to build a straight edge out of it for texture painting. The Photoshop Edit/Transform/Warp can help with these but it’s never perfect, so you end up layering and mixing edits, which is slow. Photoshop CS5’s Puppet Warp is the ideal way to fix these things:
You can see how there’s minimal blurring going on there. If you have something more complex as a source shape, you might need to do it in parts:
I just picked that one off of Google Images as an example – you can tell the blurry parts aren’t really a great for texturing. Puppet Warp is great but it doesn’t save you from the “crap in, crap out” rule.
In a previous post, I talked about how to use embedded metadata to search for textures and images with Spotlight in OS X or Search in Windows. I was recommending Expression Media, a program I often use for project management, but maybe it was a tall order expecting people to have it also. So I’m just adding a post that this metadata embedding also works in Lightroom and Aperture, which many of you likely have for photo management:
That way, you won’t lose your custom hotkeys if Maya crashes. I know it’s hard to believe that Maya could crash but, you know, just in case it’s one of those ultra-rare instances when Maya decides your work session just wasn’t meant to be.
Updated – fixed Tumblr’s garbling of carets in code. You’ll need to write out the for n size line, since there doesn’t seem to be any way of putting a caret in code without it being eaten.
Just finished my taxes (well, my accountant did) and I was shocked to find out my buddy didn’t know you can depreciate assets, so I’m guessing he’s paying more than he should be. So that’s why I’m creating this post, since many people working freelance don’t know the first thing about saving money at tax time. I took accounting in high school (don’t ask, but it has come in really handy) so I’m going to post a few basics about expensing stuff.
Expenses, those beautiful things that take a chunk out of your revenue so you pay less tax, can be almost anything if it’s business related. The hotel, dinners, taxi and flight for SIGGRAPH? Expenses. Added warranties for products? Expenses. Anything like pencils, ink, paint, paper, canvas, etc. that is spent/wasted and can not be resold is an expense.
If you work at home, a portion of your rent or mortgage can be expensed. The amount depends on how much of your place is dedicated to work. Put another monitor on your wife’s side of the bed and run Maya on that thing.
Bad debt is an expense. This is a big one for freelancers. If you have a bum client, it’s a drag, but it’s good to know that you can declare the unpaid invoice as an expense, after a grace period.
If you design video games, the games you play and the systems you buy can be expensed. Anything that qualifies as research for a project you’re working on qualifies as an expense but remember that these are also subject to depreciation if they don’t fall into the disposable category.
If you take medication or go to the dentist for non-cosmetic work, it’s generally tax deductible. Check your tax code to see if your medication is deductible. Just make sure to keep receipts for everything.
Dinners with clients—pick up the cheque and look like the big wo/man. Then tell them “it’s deductible” to the high-roller status you just earned. Again, just make sure to keep receipts for everything.
Assets like computers, cameras, etc. are not an immediate expense – these depreciate, losing 100% of their value over three years (that’s the value in Canada but it’s probably the same in the US). This depreciation is declared as an expense for each year. Books (even ebooks that can’t be resold) and software like Maya, that Autodesk would love to convince you can’t be resold with illegal license terms, are also assets that depreciate. All software vendors like Adobe, Pixologic, Maxon, etc. all allow you to sell your purchased copies of their software, and provide a means of transferring those licenses to another individual. Video card die on you? Expense the remaining depreciated value. Depreciation is what makes up most of my expenses and it’s cut over $8,000 off of what I’m paying this year.
Also, here’s the most important part: do your taxes. I went to tax Hell and back about eight years ago because I had put off my taxes for a number of years, and then the government hit me with a bill based on the values they had on record, sans my expenses, so I’d have to scramble to not pay $15,000 in back taxes. Then I went back to Hell because my accountant was a loser, who went AWOL with my records. Stories of AWOL or drunk accountants are surprisingly common, from what I’ve been hearing. A bad accountant is worse than no accountant, so be sure to get one by referral. Get a good accountant and they will save you a good bit of money, so it’s worth the cost in the end. I don’t pay more than $150 for mine so it’s not as expensive as you might think it is. If you need a great accountant in Montreal, drop me an email. My guy is great and takes care of all the small credits like those related to common-law marriage and the more obscure provincial and federal credits.
If others have more tips, I’d be glad to hear them.