Automating Photoshop via 3DSMax with DotNet and Com Interop

Hrmm, I’m tempted to be lazy here and put in a feature request since you’re working on it but I really should follow your instructions and try and build this stuff myself. Your tutorial is that succinct it deserves it. Like a few people here, I’m using this to control a post-process, a bake in specific, and there is a couple of functions that I have to use work-around’s for (see PS droplets).

The image compositor, resizing and layer control are very helpful, but I don’t see (in showmethods dotnetobject “LoneRobot.Imaging.PhotoshopBot”) a simple way to delete an alpha map and turn the images mode to grayscale. I still haven’t had a good go at trying to save, maybe this will be how to fix this, save as grayscale + no alpha.
/edit
I guess I’m going to have to admit a deeper failure then the above, I can’t even figure out how to introduce variables such as; <LoneRobot.Imaging.PhotoshopBot+BlendMode>BlendMode … looks like I’m going to have to go through the tutorial step by step after all!

Hi James,

I am back on this project now so I have a few feature requests to work through and I will take a look. It should be straightforward to add the features that you need.

Coming back to this after a break has made me realise what a pain the photoshop API is. I’m programming a custom method that can take a character PSD file and extract each part to AI and save individual element maps. This has made a cutout automation for 2D characters and saved a bunch of time.

I’m still working on this in CS3 but am hoping I can afford my upgrade soon to test in the latest release.

Well it seems I’m just not so good at handling dotnetobjects. I’m even having trouble figuring out how to save a TGA with custom options despite the functionality being clearly there. I’ve gotten this far with my max script:


dotnet.loadassembly (@"location\Interop.Photoshop")
dotnet.loadassembly (@"location\Photoshop")
oPhotoShop = dotnetobject "LoneRobot.Imaging.PhotoshopBot"
ImageTGA = dotnetobject "LoneRobot.Imaging.ImageTypes+tga"
showmethods ImageTGA
TGASaveOptions = dotnetobject "Photoshop.TargaSaveOptionsClass"
showmethods TGASaveOptions

TGASaveOptions.CreateObjRef --Same as below
TGASaveOptions.Equals --Always returns false on vars such as "cmpr" 24, despite attempts to guess the variables or use ones in the scripting listener

What is the basic way to set values? Also, what are the nested types referenced in your image showing the methods?

Hi james,

It’s not anything you have done -There is an issue with the save type class that I have now rectified. Please download the updated class from here

the correct code to save a TGA via maxscript>photoshop interop is -


-- make sure this points to where your assembly is housed
dotnet.loadassembly ((getDir #scripts) +@"\LoneRobot\ClassLib\PhotoShop.dll")
dotnet.loadassembly ((getDir #scripts) +@"\LoneRobot\ClassLib\Interop.Photoshop.dll")

oPhotoShop = dotnetobject "LoneRobot.Imaging.PhotoshopBot"
--- Setup the TGA options
oTGA = dotnetobject "LoneRobot.Imaging.ImageTypes+TGA"
show oTGA
--  .AlphaChannels : <System.Boolean>
--   .BitsPerPixel : <LoneRobot.Imaging.ImageTypes+Tga+TGAResolution>
--   .RLECompression : <System.Boolean>

-- .bitsperpixel is an enumeration, so will need to be specified if you want an alpha channel to be saved
show (dotnetclass "LoneRobot.Imaging.ImageTypes+Tga+TGAResolution")
-- dotNetClass:LoneRobot.Imaging.ImageTypes+Tga+TGAResolution
--   .TGA16Bit : <LoneRobot.Imaging.ImageTypes+Tga+TGAResolution>, read-only, static
--   .TGA24bit : <LoneRobot.Imaging.ImageTypes+Tga+TGAResolution>, read-only, static
--   .TGA32bit : <LoneRobot.Imaging.ImageTypes+Tga+TGAResolution>, read-only, static

oTGA.AlphaChannels = true
oTGA.RLECompression = true
-- set the bit depth to include the 8 bit aplha channel
oTGA.BitsPerPixel = (dotnetclass "LoneRobot.Imaging.ImageTypes+Tga+TGAResolution").TGA32bit
oTGA.BitsPerPixel.value__
-- 32
oPhotoShop.saveas "c:\	est32" oTGA

There is an updated assembly on my site now. I have added a few new methods (namely feature requests from the community)
You will also notice these two methods per your previous post-

.Channels_DeleteAlpha()
.Convert_ImageToGrayscale()

there are a few extra things in there too, Including an action I wrote recently to extract a 2d segmented character to it’s requisite parts. I will post an official update on my blog explaining the new methods in due course.

hope this helps

Pete

This doesn’t just help … it makes my day! Thank you so much!
/edit
I meant that literally, with this & the ability to send javascripts directly to photoshop with your tool I was able to complete the post-render section of the tools I’ve been working on.

I will provide some examples for this thread of the code / methods I used in coming days if anyone is interested.

I’ve stumbled into another problem; on some XP64bit machines on the render farm, with basically the same setup, I’m getting a security issue when I load the dotnetobject from the assembly. I’ve found a method to register securities in DotNet, both through command line and through MS, but with the latter certain security terms seem required, like the hash code, original install directory etc. as ‘evidence’ to confirm that you want to load the dll. Have you had any experience with DotNet security with these assemblies? Do you know any of the evidence I might be seeking?

/edit

Nevermind on this, determined that the method for qualifying securities is much simpler then this; load the security assembly, make a string of the dll assembly type and Security.CreateQualifiedName DLLpath DLLassembly type as string

Hi all,

Just to inform you of a blog update post about the PS automation library, with details of a new custom action.

http://lonerobot.net/?p=1107

The full class listing image is just a thumbnail.

Cheers Dude, fixed now.