3Ds Max simple export Macro

Hey Fellow Tech Artists,

I am writing a very simple Macro script that is supposed to take what ever object/s you have selected in 3Ds Max and export them to a single .ASE file. I have everything working the way that I want except for a small error. When ever I have a mesh and its collision hull selected the script will export both the mesh and its collision hull in two separate .ASE files giving me two files instead of just one.

One of the files has the mesh and its collision in it and the other file has just the collision hull in it. Any ideas or suggestions on what exactly I am doing wrong would be greatly helpful.

Cheers-

Sam

	-- This will place the exported mesh in the same location that the file is saved. 
	for o in $selection do ( exportFile ( maxFilepath + "/" + o.name + ".ASE") #noPrompt selectedOnly:True )

Because you have it in a for loop it does the process for each object in the selection.

You don’t need to do that as a loop if all you are doing is exporting the selection, just call exportFile with the selected only true as you have it.

[QUOTE=bclark;13733]Because you have it in a for loop it does the process for each object in the selection.

You don’t need to do that as a loop if all you are doing is exporting the selection, just call exportFile with the selected only true as you have it.[/QUOTE]

Okay I got the script working so that it will now only export one .ASE file. But in order to do that, I had to use the name of the Max file instead of the name of the object that was selected in the scene. Which is okay but I originally wanted the script to work so that you could export any selected object in the scene.

So any suggestions on how I go about getting 3Ds Max to export the object using the objects scene name instead of the file name. Here is the code that I have so far I know that its simple but it gets the job done.

exportFile(maxFilepath + maxFilename + ".ASE")#noPrompt selectedOnly:True

If you have multiple objects selected, which one do you want to use for the name?

How you handle the file export naming will depend largely on how you’re structuring the scene. In my case, I created a script that would export all selected objects individually based on object name, but this required that the artists also ensure that the collision meshes are named correctly as well (ie. UCX_ObjName01, UCX_ObjName02, etc would be exported alongside ObjName).

In a nutshell, my script does:

Deselect UCX_*
Store selection in array
deselect all
For [i]item[/i] in array
  Select [i]item[/i], selectmore UCX_[i]item[/i]*
  Export selected as [i]item[/i].ase
  deselect all

Which frees the artists from ensuring either all their collision meshes are selected, or making sure they haven’t accidentally selected a collision mesh.

With all of your input I have made quite some progress and now have the script working the way that I want to more or less.


(
	(
	-- Get both objects selected and put them into an arry	
	a = selection as array 
	
	-- DeSelect all UCX collision hulls.
	Deselect $UCX*
	
	--Add the current selected objects name here so that it can be used for export later.
	b = $.name

	-- Clear the selection
	clearSelection()

	-- Select the objects array that was just created and then select the 
	select a[1,2]
	
	--This will export the file out with the correct name and format.
	exportFile(maxFilepath + b + ".ASE")#noPrompt selectedOnly:True
	
)
	
)

If any one has any feedback on my code or suggestions on other things to do, it would be greatly appreciated:):.

I have been adding some error checking to my script and I have come across a problem and I was wondering if any one had any insite into why this is not working. Here is the code that I have so far.

(

	-- Check to see if we have a selection and if not tell the user to select something
	if selection == none  then ( messagebox "Please select something to export.") 
	
	-- If we have something selected then go ahead and do the export. 
	else if selection != none then
	(
	
	-- Get both objects selected and put them into an array.	
	a = selection as array 
	
	-- DeSelect all UCX collision hulls.
	Deselect $UCX*
	
	--Add the current selected objects name here so that it can be used for export later.
	b = $.name

	-- Clear the selection.
	clearSelection()

	-- Select the objects array that was just created.
	select a[1,2]
	
	--This will export the file out with the correct name and format.
	exportFile(maxFilepath + b + ".ASE")#noPrompt selectedOnly:True
	)
)

My problem is this, I added a if statement to the beginning of the script to check to see if anything was currently selected. If nothing was selected then a message would pop up telling the end user to select something. But no matter what I do the script will always fail if the user runs it and has nothing selected.

The reason that it’s failing is because further down the script I get the name of your current selection and store that name as a variable so that I can use it for naming later. But I thought that by adding the if statements like I have them if the user does not have anything selected then the script should just stop and not fail.

Obviously there is something wrong with the way that I have my if else statement set up but I am not sure what it is. Any ideas or suggestions would be greatly appreciated.

(

	-- Check to see if we have a selection and if not tell the user to select something
	if selection == none  then ( messagebox "Please select something to export.") 
	else -- If we have something selected then go ahead and do the export. 
	(
	
	-- Get both objects selected and put them into an array.	
	a = selection as array 
	
	-- DeSelect all UCX collision hulls.
	Deselect $UCX*
	
	--Add the current selected objects name here so that it can be used for export later.
	b = $.name

	-- Clear the selection.
	clearSelection()

	-- Select the objects array that was just created.
	select a[1,2]
	
	--This will export the file out with the correct name and format.
	exportFile(maxFilepath + b + ".ASE")#noPrompt selectedOnly:True
	)
)

Because of the comment and the gap between the if and the else in the beginning it did not see that the else was relative to the first if.

[QUOTE=Nysuatro;13783]

(

	-- Check to see if we have a selection and if not tell the user to select something
	if selection == none  then ( messagebox "Please select something to export.") 
	else -- If we have something selected then go ahead and do the export. 
	(
	
	-- Get both objects selected and put them into an array.	
	a = selection as array 
	
	-- DeSelect all UCX collision hulls.
	Deselect $UCX*
	
	--Add the current selected objects name here so that it can be used for export later.
	b = $.name

	-- Clear the selection.
	clearSelection()

	-- Select the objects array that was just created.
	select a[1,2]
	
	--This will export the file out with the correct name and format.
	exportFile(maxFilepath + b + ".ASE")#noPrompt selectedOnly:True
	)
)

Because of the comment and the gap between the if and the else in the beginning it did not see that the else was relative to the first if.[/QUOTE]

I tried out your suggestion but its still not working correctly, I still get the same error as before. Any other ideas on what I could possibly be doing wrong? I will continue to work on it on my end and post back if I figure it out.

Ah I finally figured it out. I was checking my current selection incorrectly. I was using…

 if selection == 0 then ()

When I should have been using…

if selection.count == 0 then

I dont think that I will be forgetting that any time soon. :):

(

	-- Check to see if we have a selection and if not tell the user to select something
	if selection.count == 0  then ( messagebox "Please select something to export.") 
	else -- If we have something selected then go ahead and do the export. 
	(
	
	-- Get both objects selected and put them into an array.	
	a = selection as array 
	
	-- DeSelect all UCX collision hulls.
	Deselect $UCX*
	
	--Add the current selected objects name here so that it can be used for export later.
	b = $.name

	-- Clear the selection.
	clearSelection()

	-- Select the objects array that was just created.
	select a[1,2]
	
	--This will export the file out with the correct name and format.
	exportFile(maxFilepath + b + ".ASE")#noPrompt selectedOnly:True
	)
)