From: Richard Wilson Date: 2013-07-05T05:13:46+09:00 Subject: Re: Loading csv giving error --047d7b6dcdce2098d704e0b53776 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Why do you use the File class if you want to use the CSV class? You can use CSV::open instead. This would print out every row using the headers. CSV.open("test.csv", headers: true) do |csv| csv.each do |line| puts line["PARTNO"] + " and " line["PRICE"] end end On Thu, Jul 4, 2013 at 1:07 PM, Nithi anand wrote: > hi guys I am trying to compare some data so I create one file name > called "Price_lookup" in notepad then saved in plugin folder > "Price_lookup.csv". > Price_lookup.csv contain like below > > "PARTNO", "PRICE" > 600157,402.20 > 600163,424.16 > 600169,445.00 > 600175,468.96 > 600181,492.01 > 600187,516.69 > > then I wrote small ruby script for testing. when I start the sketchup > It's gives an error as follows "Error Loading File CSV_Test.rb no such > file to load -- csv". any idea what I am doing wrong here???? thank you > > here is my code. > > > > require 'sketchup.rb' > require 'csv' > > def csv_Test > > model =3D Sketchup.active_model > ent =3D model.active_entities > > csv_text =3D File.read('Price_lookup.csv') > csv =3D CSV.parse(csv_text, :headers =3D> true) > csv.each do |row| > result =3D csv.find {|row| row['PARTNO'] =3D=3D '600181'} > > UI.messagebox "Your Output #{result}" > end > end > > if (not $csv_Test_menu_loaded) > > UI.menu("Tools").add_item("CSV_TEST") { csv_Test } > > $csv_Test_menu_loaded =3D true > end > > -- > Posted via http://www.ruby-forum.com/. > > --=20 *Richard Wilson* Proteous Trading Group ph. - (604) 842 5318 Skype - r.crawfordwilson email - r.crawfordwilson@gmail.com =93*This email may contain confidential and/or privileged information. If y= ou are not the intended recipient or have received this email in error, please notify the sender immediately and destroy this email. Any unauthorized copying, disclosure or distribution of the information contained on this email is prohibited=94.* --047d7b6dcdce2098d704e0b53776 Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: quoted-printable
Why do you use the File class if you want to use the CSV c= lass?=A0

You can use CSV::open instead. This would print= out every row using the headers.

CSV.open(&qu= ot;test.csv", headers: true) do |csv|
=A0 csv.each do |line|
=A0 =A0 puts line["PARTNO"] + " an= d " line["PRICE"]
=A0 end
end
=A0
=


On Thu, Jul 4= , 2013 at 1:07 PM, Nithi anand <lists@ruby-forum.com> wro= te:
hi guys I am trying to compare some data so = I create one file name
called "Price_lookup" in notepad then saved in plugin folder
"Price_lookup.csv".
Price_lookup.csv contain like below

"PARTNO", "PRICE"
600157,402.20
600163,424.16
600169,445.00
600175,468.96
600181,492.01
600187,516.69

then I wrote small ruby script for testing. when I start the sketchup
It's gives an error as follows "Error Loading File CSV_Test.rb no = such
file to load -- csv". any idea what I am doing wrong here???? thank yo= u

here is my code.



=A0 =A0 require 'sketchup.rb'
=A0 =A0 require 'csv'

=A0 =A0 def csv_Test

=A0 =A0 =A0 =A0 =A0 =A0 model =3D Sketchup.active_model
=A0 =A0 =A0 =A0 =A0 =A0 ent =3D model.active_entities

=A0 =A0 =A0 =A0 =A0 =A0 csv_text =3D File.read('Price_lookup.csv')<= br> =A0 =A0 =A0 =A0 =A0 =A0 csv =3D CSV.parse(csv_text, :headers =3D> true)<= br> =A0 =A0 =A0 =A0 =A0 =A0 csv.each do |row|
=A0 =A0 =A0 =A0 =A0 =A0 result =3D csv.find {|row| row['PARTNO'] = =3D=3D '600181'}

=A0 =A0 =A0 =A0 =A0 =A0 UI.messagebox "Your Output #{result}"
=A0 =A0 =A0 =A0 =A0 =A0 end
=A0 =A0 end

=A0 =A0 if (not $csv_Test_menu_loaded)

=A0 =A0 =A0 UI.menu("Tools").add_item("CSV_TEST") { csv= _Test }

=A0 =A0 =A0 $csv_Test_menu_loaded =3D true
=A0 =A0 end

--
Posted via http://= www.ruby-forum.com/.




--
Richard Wilson
Proteous Trading Group
ph. - (604) 842 5318
Skype - r.crawfordwilson

=93This email may contain confidential and/or privileged information. If = you are not the intended recipient or have received this email in error, pl= ease notify the sender immediately and destroy this email. Any unauthorized= copying, disclosure or distribution of the information contained on this e= mail is prohibited=94.
--047d7b6dcdce2098d704e0b53776--