PDA

View Full Version : Open dialogue for several files at once


Krystman
05-25-2008, 03:32 PM
I want to create a script that lets me select a bunch of JPG files and that creates for each JPG a plane with a material of that JPG assigned to it. Now I've managed to do that with one File:


f = getOpenFileName caption:"Open JPGs" types:"JPG (*.jpg)|*.jpg|All Files (*.*)|*.*|"
myFile = filenameFromPath f
myPlane = plane()
myPlane.name = myFile
myPlane.length = 30
myPlane.width = 40
myPlane.material = standard diffuseMap:(myBitmap) showInViewport:true name:myFile Self_Illumination:100


Work perfectly but getOpenFileName lets me only select one JPG at a time. How do I do that if I want to select several JPGs at once?

Bobo
05-25-2008, 03:41 PM
http://www.scriptspot.com/bobo/mxs9/dotNet/OpenFileDialog.html

Krystman
05-25-2008, 04:05 PM
Ha! It works. This is my final code:


theDialog = dotNetObject "System.Windows.Forms.OpenFileDialog"
theDialog.title = "PLEASE Select One Or More Files"
theDialog.Multiselect = true
theDialog.Filter = "JPG Files (*.jpg)|*.jpg|All Files (*.*)|*.*"
theDialog.FilterIndex = 1
result = theDialog.showDialog()
result.ToString()
result.Equals result.OK
theFilenames = theDialog.fileNames

if result.Equals result.OK then
(
myZ = 0
for o in theFilenames do
(
myFile = filenameFromPath o
myPlane = plane()
myPlane.name = myFile
myPlane.length = 30
myPlane.width = 40
myPlane.pos.z = myZ
myBitmap = bitmaptexture()
myBitmap.filename = o
myBitmap.reload()
myPlane.material = standard diffuseMap:(myBitmap) showInViewport:true name:myFile Self_Illumination:100
myZ = myZ + 10
)
)


Thank you! Again. You have been a great help!

Gravey
05-26-2008, 10:01 AM
sweet i know this will come in handy. Thanks bobo

thatoneguy
05-26-2008, 06:03 PM
Just thinking out loud here krystman but you might want to check the aspect ratio of all the jpegs you're importing and respect that in the plane size as well. Just in case you have JPegs of different sizes to avoid stretching.

CGTalk Moderation
05-26-2008, 06:03 PM
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.