Joshua Newman.

in 3D.

maxscript open bitmaps in photoshop.

This is an oldie but a goody. Put simply, it is a script that will open 3ds Max material maps in photoshop. I use it in my quad menu. If photoshop isn’t open, then it will open it for you.

I’ve recently updated it to work with class instances, a much more efficient and almost foolproof way of ensuring we get all the maps.

It has two methods of functioning.

1. if the material editor is open, it will open all the maps used in the current material

2.if the editor is closed, then it will load all the maps used in the materials of the selected objects.

This is really handy script if you want to quickly adjust some materials maps in photoshop

for installation, just drop the mzp file onto you max viewport and then add the script to your quad (or menu, or toolbar!).

customize | customize user interface | category : JNScripts

Download the installation file here

Here is a run through of what’s happening under the hood.

--------------------------------------------------------------------------------
--	Open bitmaps in photoshop
--	version 3.1
--	max version 2008, 2009, 2010
--	written by Joshua Newman
--	written		25/05/04
--	updated 	07/04/09
--	www.joshuanewman.net
--	copyright 2004, 2009
--------------------------------------------------------------------------------

-- if the material editor is open, the current materials bitmaps will be opened in photoshop.
-- otherwise all the bitmaps used in the current selection will be opened.

macroScript Photoshop category:"JN Scripts" tooltip:"Load bitmaps in Photoshop." icon:#("JNpshp",1)
(

	On isEnabled return (Try((Selection.count!=0 and selection[1].material!=undefined) or mateditor.isopen())Catch())
	On isVisible return (Try((Selection.count!=0 and selection[1].material!=undefined) or mateditor.isopen())Catch())
	On Execute Do
	(
		bitmaps=#()
		if mateditor.isopen() then
		(
			a=medit.getcurmtl()
			bitmaps=getClassInstances Bitmaptexture target:a
		) else
		(
			sel=selection as array
			for s in sel do
			(
				if s.material!=undefined then
				(
					newbitmaps=getclassinstances Bitmaptexture target:s.material
					for b in newbitmaps do if (finditem bitmaps b==0) then append bitmaps b
				)
			)
		)
		pshop=CreateOLEObject"Photoshop.Application"
		pshop.Visible=true
		for b in bitmaps do pshop.open b.filename
	)
)

Step by step.
macroscript definition.

macroScript Photoshop category:"JN Scripts" tooltip:"Load bitmaps in Photoshop." icon:#("JNpshp",1)
(

This defines the script as a macro, this allows you to add it as a keyboard shortcut, quad menu item, drop down menu item, or button on your tool bar.

	On isEnabled return (Try((Selection.count!=0 and selection[1].material!=undefined) or mateditor.isopen())Catch())
	On isVisible return (Try((Selection.count!=0 and selection[1].material!=undefined) or mateditor.isopen())Catch())

These two lines whether or not the tool is enabled or visible. For example, if it is in a quad menu, then at least one of these conditions must be met for the tool to be visible; 1. Either the material editor has to be open, 2. at least on object must be selected, 3. the first selected object must have a material.

	On Execute Do
	(

Where to start when the script is executed.

		bitmaps=#()

let’s define a variable to hold all the bitmaps we find

		if mateditor.isopen() then
		(

Is the material editor open?

			a=medit.getcurmtl()

if yes then lets get the currently selected material and place it in a temporary variable ‘a’

			newbitmaps=getClassInstances Bitmaptexture target:a

now use the getClassInstances function to get all dependents of the class Bitmaptexture and put them into our bitmaps variable. This will now contain an array.

		) else
		(

ok, so the material editor isn’t open then.

			sel=selection as array

Let’s convert the current selection into an array of objects.

			for s in sel do
			(

Now iterate through that selection object by object,

				if s.material!=undefined then
				(

and check to see if has a material assigned.

					newbitmaps=getclassinstances Bitmaptexture target:s.material

get all the bitmaps used in that material into a temporary variable, returns an array.

					for b in newbitmaps do if (finditem bitmaps b==0) then append bitmaps b

We then iterate through the array and check to see if the bitmap is already listed and add it if it isn’t. I’ve changed this line to remove the appendifunique function since this function was added to Max in version 2008. This will allow my script to work in earlier versions of max.

				)
			)
		)
		pshop=CreateOLEObject"Photoshop.Application"

This creates that OLE communication link with photoshop.

		pshop.Visible=true

This makes photoshop visible on the desktop, if it isn’t already.

		for b in bitmaps do if (doesfileexist b.filename) then pshop.open b.filename else (print b.filename)

Finally, we iterate through our array of bitmaps and check to see that the filenames are valid before opening them one by one in photoshop.

	)
)

Don’t forget to close your parenthesis!

3 Comments

  1. Michael Sharpe
    Posted July 16, 2009 at 1:23 am | Permalink

    Its probably a good idea to add a check to see if the texture paths are valid before sending them to photoshop

    for b in bitmaps do
    (
    fileExists = getfiles b.filename
    format “Fileexists : % n” fileExists
    if(fileExists.Count > 0) then
    (
    pshop.open b.filename
    )
    )

    cheers
    Mike

  2. Posted July 21, 2009 at 1:38 pm | Permalink

    Hello Michael,

    Thanks for your comment. You’re right, I need to test to see if the file exists before sending it to photoshop to avoid any errors.
    I prefer to use the inbuilt max command doesfileexist:

    for b in bitmaps do if (doesfileexist b.filename) then pshop.open b.filename else (print b.filename)

    I’ll adjust the script above and the download.

    Josh.

  3. Posted September 9, 2009 at 3:10 pm | Permalink

    Ok,

    In the interest of compatability I’ve changed one of the lines of code in the script;

    for b in newbitmaps do appendIfUnique bitmaps b

    with:

    for b in newbitmaps do if (finditem bitmaps b==0) then append bitmaps b

    the function appendifunique was added in Max2008 and this change will allow the script to work in earlier version.

    J.

Post a Comment

You must be logged in to post a comment.