PDA

View Full Version : Select and Export multiple objects


em3
06-11-2011, 05:05 AM
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!

jonahhawk
06-11-2011, 07:22 AM
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:\temp\",
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

)
)

denisT
06-11-2011, 08:01 AM
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:\temp\",
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

)
)

First off your code can be simplified. :)

(
local dirName = @"f:\temp\"

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
06-12-2011, 01:05 AM
you guys are amazing, I thank you with vast hugeness!

CGTalk Moderation
06-12-2011, 01:05 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.