Notifications
Clear all

[Closed] Select and Export multiple objects

 em3

Hello, I am exporting a mesh as an .ase file like this


dirName = "e:\\projects\\PFMRTS\\ase\\"
(
Objs = for o in objects collect o
	
for o in Objs do
( 
	i=1
	select o

	exportFile (dirname + "\\" + o.name + ".ase") #noPrompt selectedOnly:true
	
)
)

no problem works great. Now, I have to export 2 objects. The original object AND an object with the same name but is prefaced with “OCX_”

Can someone suggest a method for accomplishing this?

Thanks!

3 Replies

First off your code can be simplified. objects is already a collection. It is not necessary to duplicate that collection by building a new array.

It is important to keep all variables local unless you have other scripts that will use that same variable or a variable inside a block needs to be visible outside of its scope. The variable dirName could exist in another tool that uses a completely different path/directory. These two variables could affect each other if they are global as you’ve written them. Look up scope of variables in the mxs help.

(
 	local dirName = @"e:\projects\PFMRTS\ase\"
 	
 	for o in Objs do
 	( 
 		select o
 		exportFile (dirname + o.name + ".ase") #noPrompt selectedOnly:true
 	)
 )

Here is a quick brute force method to do what you want. But there is no error checking. i.e. The tool will fail if there is an object that does not have an OCX mate to make a pair.

It would be a good start to only make a pair if OCX + object.name is a valid object (isValidObj)

(
 	local dirName = @"f:	emp\",
 			OCXpairs = #()
 	
 	for o in objects where not (MatchPattern o.name pattern:"OCX*") do 
 	(
 		thePair = #()
 		append thePair o 
 		append thePair (execute ("$" + "OCX" + o.name))
 		append OCXpairs thePair
 	)
 	print OCXpairs
 	
 	for p in OCXpairs do
 	( 
 		select p
 		exportFile (dirname + p[1].name + ".obj") #noPrompt selectedOnly:true
 		
 	)
 )
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

First off your code can be simplified.

(
  	local dirName = @"f:	emp\"
  	
  	for node in objects where isvalidnode (mate = getNodeByName ("OCX_" + node.name) firstonly:on) do 
  	(
  		select #(node,mate)
		exportFile (dirname + node.name + ".obj") #noPrompt selectedOnly:on
  	)
  )

 em3

you guys are amazing, I thank you with vast hugeness!