CGTalk > Software > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 06-11-2013, 10:13 AM   #1
SamSed
Lord of the posts
 
SamSed's Avatar
portfolio
Sammy Sedrati
VR Developer
Doha, Qatar
 
Join Date: Feb 2005
Posts: 674
Loading a csv file with .net

Hello guys,

I must be missing something here, i can't clear my head and get this script work properly.( i'm a .net noob , bear with me please )
i'm having a problem with this particular function:
Code:
fn LoadCsv_fn lv = ( theRange = #() for h = 1 to lineVal.count do ( li = dotNetObject "System.Windows.Forms.ListViewItem" ThisVal = lineVal[h] as string ThatVal = filterString ThisVal "," for n in 1 to TheColumn.count do ( sub_li = li.SubItems.add (ThatVal[n] as string) ) append theRange li ) lv.Items.AddRange theRange )


the csv file looks like this:(object name, X coord, Y coord, Z coord)
Code:
box001,0,0,0 Teapot,10,0,0 Torus,3,2,-3 Cylinder,5,66,-9 Sphere,9,3,33 box002,150,125,36


The file loads just fine however with a one column shift in the .net listView
Here's the whole code so far:
Code:
if (ObjLoader != undefined) and (ObjLoader.isdisplayed ) do (destroyDialog ObjLoader) rollout ObjLoader "Object Loader" ( local align = dotNetClass "System.Windows.Forms.HorizontalAlignment" local ColItems = dotNetClass "ListViewItem" local TheColumn = #(#("Objects", 76, align.Center),#("X coord", 60, align.Center),#("Y coord", 60, align.Center),#("Z coord", 60, align.Center)) local ObjArr = #() label LBLoadF "Load CSV file :" pos:[5,10] button btn_Load "Load file" pos:[75,5] width:80 height:25 edittext ObjName "Name: " pos:[5,35] width:150 label LB_x "X :" pos:[23,60] spinner SpnrX "" pos:[42,60] range:[-9999,9999,0] type:#integer width:48 label LB_y "Y : " pos:[23,80] spinner SpnrY "" pos:[42,80] range:[-9999,9999,0] type:#integer width:48 label LB_z "Z : " pos:[23,100] spinner SpnrZ "" pos:[42,100] range:[-9999,9999,0] type:#integer width:48 button btn_add "Add to List" pos:[95,60] width:60 height:25 button btn_clr "Clear List" pos:[95,90] width:60 height:25 button btn_mrg "Merge max file" pos:[40,140] width:100 height:30 dotNetControl lv "system.windows.forms.listView" pos:[160,15] width:260 height:157 /*--------------Functions Start-------------*/ fn init_fn lv = ( lv.view=(dotNetClass "system.windows.forms.view").details lv.FullRowSelect = true lv.GridLines = true lv.IsAccessible = false lv.LabelEdit = true lv.checkboxes = false ) fn AddCol_fn MyLv Array = ( for col in Array do ( MyLv.columns.add col[1] col[2] col[3] ) ) fn Populate_fn MyLv txt_Input ObjCoordX ObjCoordY ObjCoordZ = ( TheName = txt_Input X = ObjCoordX Y = ObjCoordY Z = ObjCoordZ dt = #(TheName) local item = for i in dt collect ( dotNetObject ColItems #(i ,X, Y, Z) ) MyLv.items.AddRange item MyLV.Update() ) fn LoadCsv_fn lv = ( theRange = #() for h = 1 to lineVal.count do ( li = dotNetObject "System.Windows.Forms.ListViewItem" ThisVal = lineVal[h] as string ThatVal = filterString ThisVal "," for n in 1 to TheColumn.count do ( sub_li = li.SubItems.add (ThatVal[n] as string) ) append theRange li ) lv.Items.AddRange theRange ) /*--------------Operations--------------*/ on ObjLoader open do ( init_fn lv AddCol_fn lv TheColumn ) on btn_Load pressed do ( theOpenFile = getOpenFileName \ caption:"CSV File" \ filename:(getDir #Import + @"\") \ types:"Comma Seperated Value(*.csv)|*.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 LoadCsv_fn lv ) ) on btn_add pressed do ( ObjtName = ObjName.text Xval = SpnrX.value as string Yval = SpnrY.value as string Zval = SpnrZ.value as string ( Populate_fn lv ObjtName Xval Yval Zval ) ) on btn_clr pressed do ( SpnrX.value = 0 SpnrY.value = 0 SpnrZ.value = 0 ObjName.text = "" lv.items.clear() ) on btn_mrg pressed do ( ) ) createDialog ObjLoader 430 180 style:#(#style_titlebar, #style_sysmenu,#style_minimizebox)


Any ideas?
Appreciate your help and thank you !
__________________
LinkedIn
 
Old 06-11-2013, 01:02 PM   #2
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,334
Send a message via ICQ to denisT
Quote:
Originally Posted by SamSed
Hello guys,

I must be missing something here, i can't clear my head and get this script work properly.( i'm a .net noob , bear with me please )
i'm having a problem with this particular function:
Code:
fn LoadCsv_fn lv = ( theRange = #() for h = 1 to lineVal.count do ( li = dotNetObject "System.Windows.Forms.ListViewItem" ThisVal = lineVal[h] as string ThatVal = filterString ThisVal "," for n in 1 to TheColumn.count do ( sub_li = li.SubItems.add (ThatVal[n] as string) ) append theRange li ) lv.Items.AddRange theRange )


try this filter filterString ThisVal ",\n"

edited. it was another problem
this will fix you code
Code:
local lineVal fn LoadCsv_fn lv = ( theRange = #() for h = 1 to lineVal.count do ( ThisVal = lineVal[h] as string ThatVal = filterString ThisVal "," li = dotNetObject "System.Windows.Forms.ListViewItem" ThatVal[1] for n=2 to lv.columns.count do ( sub_li = li.SubItems.add (ThatVal[n] as string) ) append theRange li ) lv.Items.AddRange theRange )

fist item's subitem automatically adds with the item creation.

Last edited by denisT : 06-11-2013 at 01:14 PM.
 
Old 06-12-2013, 03:56 AM   #3
SamSed
Lord of the posts
 
SamSed's Avatar
portfolio
Sammy Sedrati
VR Developer
Doha, Qatar
 
Join Date: Feb 2005
Posts: 674
Thank you Denis, much appreciated
__________________
LinkedIn
 
Old 06-12-2013, 03:56 AM   #4
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 07:52 PM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.