/* CSV Viewer v0.1 Created: Dec 29, 2009 Last Updated: Feb 18, 2010 Author : John Rand (littl3fish@gmail.com) Version: written & tested in max2010 32&64bit, it may work in older versions. This macro will read a CSV file. Handy to check your Krakatoa generated CSV Channel Data. You can specify every Nth line, you may not want to load more than 1000 lines at a time, it will consume your maxscript heap. Install file CSVviewer.mcr in your "~\scripts\JRandom" folder. or wherever you want. Run it, it will create a category "JRandom" in you customize dialog, add a shorcut and run. Start the script, specify the every Nth lines to read, open a CSV file. It is a run once script, if you wish to open a new CSV run the script again. This is WSYWIG, what you see is what you get... *********************************************************************************************** MODIFY THIS AT YOUR OWN RISK */ --start macroScript CSVviewer category:"JRandom" ( try(destroyDialog CSVview_rollout)catch()--Comment this out if you want more than 1 window open rollout CSVview_rollout "CSV Viewer" ( global lineCount global lineVal = #() global theHeaders = #() global layout_def = #() global theOpenFile fn initListView lv = ( id = #("Count") lv.gridLines = true lv.View = (dotNetClass "System.Windows.Forms.View").Details lv.fullRowSelect = true headers = lineVal[1] as string theHeaders = filterString headers "," layout_def = id + theHeaders for i in layout_def do lv.Columns.add i 96 ) fn fillInSpreadSheet lv = ( escapeEnable = true theRange = #() theNth = CSVview_rollout.spn_theNth.value if (lineCount - 1) >= CSVview_rollout.spn_theMin.value then theMin = CSVview_rollout.spn_theMin.value else theMin = (LineCount - 1) if (lineCount - 1) >= CSVview_rollout.spn_theMax.value then theMax = CSVview_rollout.spn_theMax.value else theMax = (LineCount - 1) for i in theMin to theMax by theNth do ( li = dotNetObject "System.Windows.Forms.ListViewItem" (i as string) curVal = lineVal[i + 1] as string postVal = filterString curVal "," for n in 1 to layout_def.count do ( CSVview_rollout.prg_Bar.value = 100.0 * i / (theMax - theMin) sub_li = li.SubItems.add (postval[n] as string) ) append theRange li ) lv.Items.AddRange theRange ) dotNetControl lv_objects "System.Windows.Forms.ListView" width:864 height:260 align:#center label lbl_warning "WARNING - Consider Loading less than 1000 lines!" across:3 align:#left offset:[0,4] spinner spn_theMin "First Line" type:#integer width:120 range:[1,1000000000,1] pos:[300,272] spinner spn_theMax "Last Line" type:#integer width:120 range:[1,1000000000,1000] pos:[440,272] spinner spn_theNth "Load Every Nth Line" type:#integer width:120 range:[1,1000000000,1] pos:[640,272] button btn_Load "Load CSV" pos:[772,268] width:80 progressBar prg_Bar "Progress" height:8 pos:[6,294] on CSVview_rollout open do ( --Uncomment to auto-open the Open File Dialog /* theOpenFile = getOpenFileName \ caption:"CSV File" \ filename:(getDir #renderOutput + @"\") \ types:"Comma Seperated Value(*.csv)|*.csv" \ historyCategory:"Krakatoa CSV" if theOpenFile != undefined then ( theFile = openFile theOpenFile lineCount = ((dotnetClass "System.IO.File").ReadAllLines theOpenFile ).count lineVal = (dotnetClass "System.IO.File").ReadAllLines theOpenFile close theFile initListView lv_objects fillInSpreadSheet lv_objects ) */ ) on btn_Load pressed do ( theOpenFile = getOpenFileName \ caption:"CSV File" \ filename:(getDir #renderOutput + @"\") \ types:"Comma Seperated Value(*.csv)|*.csv" \ historyCategory:"Krakatoa CSV" if theOpenFile != undefined then ( theFile = openFile theOpenFile lineCount = ((dotnetClass "System.IO.File").ReadAllLines theOpenFile).count lineVal = (dotnetClass "System.IO.File").ReadAllLines theOpenFile close theFile initListView lv_objects fillInSpreadSheet lv_objects ) btn_Load.enabled = false ) on CSVview_rollout close do ( lineCount = undefined theOpenFile = undefined lineVal = #() theHeaders = #() layout_def = #() gc() ) ) createDialog CSVview_rollout 880 310 )