'-------------------------------------------------------------
'-------------------------------------------------------------
'AUTHOR:Jonathan Katoe
'NAME:SelectionSets
'CONTACT:jonkatoe@optonline.net
'VERSION:1.0
'DESCRIPTION:Makes a new toolbar with buttons to select any
'object in the original selection individually by name.
'-------------------------------------------------------------
'-------------------------------------------------------------
dim file
dim toolbar
dim command
dim path
dim oSel
dim oItem
dim scn
dim scnName
dim oFol1
dim oFol2
dim rc

set oSel = CreateObject("XSI.collection")
set oSel = GetValue("SelectionList")

'-------------------------------------------------------------
if oSel.count = 0 then
	ExitApp
else
	set scn = ActiveProject.activescene
	scnName = scn.name
	rc = InputBox("What would you like to name this toolbar?", "Create a selection set", scnName & "-SelectionSet") 
	if rc = "" then
		ExitApp
	else
		toolbar = CreateToolbar(rc)
		
			path = Application.InstallationPath(siUserPath)
			folder = "\Scripts\SelectionSets\"
			set fso = CreateObject("Scripting.FileSystemObject")
				if (fso.FolderExists(path & folder)) = 0 then
					set oFol1 = fso.CreateFolder(path & folder)		
				else
				end if
				if (fso.FolderExists(path & folder & "\" & scnName)) = 0 then
					set oFol2 = fso.CreateFolder(path & folder & "\" & scnName)
				else
				end if	
			file = path & folder & scnName & "\" & scnName & "-SelectionSet.vbs"	
			set selFile = fso.CreateTextFile(file, True)
			selFile.writeline("'Script Generated by SelectionSets script - Jonathan Katoe")
			selFile.close
		for each oItem in oSel
			set selFile = fso.OpenTextFile(file, 8, True)

			selFile.WriteLine("sub " & oItem.name)
			selFile.WriteLine("SelectObj " & chr(34) & oItem & chr(34) & ", , True")
			selFile.WriteLine("end sub")
			selFile.WriteLine(" ")
			selFile.Close
			logmessage file
			command = CreateScriptCommand(oItem.name & " selection" , oItem.name & "sel" , file, oItem.name, "Selects " & oItem.name)
			CreateToolbarButton toolbar, command
		next
	end if
end if

'-------------------------------------------------------------
sub ExitApp
	application.statusbar = "Nothing is selected!"
end sub

'-------------------------------------------------------------
