ScriptSpot home

Forum topic · General Scripting

Display folder content in Listbox

By Alex Szabados · 2016-10-06

Description

Hi there!

I'm trying to build a small browser for published Assets.
What the script will do is showing all maxfiles in a certain folder so you can select the Asset you wanna reference. Later it will Xref the Asset, bring also in it's proxy, link a locator to it and lock the Xref.

The question is, how can I get the files of a folder in a rollout listbox?

This is what I came up with so far:

projectRoot = pathConfig.removePathLeaf maxfilepath + "\\"
pubPath = projectRoot + "Assets\PUB\\"
pubFiles = pubPath + "*PUB.max"
files = getFiles pubFiles

rollout Referencer "Referencer" width:394 height:426
(

label 'lbl9' "Reference Assets" pos:[157,17] width:93 height:39 align:#left

listbox objectToKill "Objects:" items:(for o in files collect o) pos:[31,61] width:330 height:20 align:#left
button 'refBtn' "Reference" pos:[119,358] width:139 height:40 align:#left
on refList selected sel do
(

)
on refBtn pressed do
(

)
)

So I get the content of the folder in the list. Now I guess I have to create an array which is corresponding with the list storing the file path informations. How can I create that and read it out?

Thanks :)

Comments (6)
Alex Szabados

Hi! Thanks for your reply! I got the naming working and spent some hours on finding out how to get the Xref selection, but unfortunately it seems like I don't understand how I can get it going. Sorry for asking again. I was reading through the batch script you posted, but as far as I saw the selection is set with #select flags, which doesn't work for Xrefs. Could you please help me with this? Thank you :)

Alex Szabados

Yes after the Xref comes in I wanna do some operations on it by maxscript. And by the way, there's another problem I step into. When I Xref objects by maxscript I get name clashes. So if I reference 3 times an object called "tree_001" it doesn't number up the object, so I get 3 Xref objects called "tree_001". Any Idea how to get around this?

this is the code I use:

.....
objectName = h3 + "_001"
proxyName = h3 + "_proxy"
proxyPath = c1 + "_proxy.max"
XrefImporter = xrefs.addNewXRefObject assetPath objectName
XrefImporter.proxyfilename = proxyPath
XrefImporter.proxyobjectname = proxyName
XrefImporter.useProxy = true
......

I couldn't find any way to change the Name of the XrefObject in the scene in the maxhelp, or did I just not see it?

Thanks

fajar

you mean select object after xref?

Alex Szabados

Thanks! I'm now at the point where everything with Xref is working so far.
I'm running into a different problem. When get in the Xref the object is not selected, but I also need to do an operation on it. I was trying to find a call to select or process in any way a xref which just got imported, but couldn't find any. Am I blind? Thanks :)

fajar

on Referencer open do (


--to fill list box
on Referencer  open do 
(
    objectToKill.items=files 
)

--to get listbox name
on refBtn pressed do
(
local txt= objectToKill.selected  
if txt!=undefined do messagebox txt --txt here is your file full path
)
--you can replace messagebox with any function you have