Open dialogue for several files at once


#1

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?


#2

http://www.scriptspot.com/bobo/mxs9/dotNet/OpenFileDialog.html


#3

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!


#4

sweet i know this will come in handy. Thanks bobo


#5

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.


#6

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.