Loading csv giving error

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 = Sketchup.active_model
        ent = model.active_entities

        csv_text = File.read('Price_lookup.csv')
        csv = CSV.parse(csv_text, :headers => true)
        csv.each do |row|
        result = csv.find {|row| row['PARTNO'] == '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 = true
end

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 [email protected]
wrote:

600181,492.01
require ‘sketchup.rb’
result = csv.find {|row| row[‘PARTNO’] == ‘600181’}
end


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


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

This email may contain confidential and/or privileged information. If
you
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.

On Jul 4, 2013, at 3:07 PM, Nithi anand [email protected] wrote:

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

What line number is appearing with that message?

This code works fine…

require “rubygems”
require “csv”

CSV.open("/home/user1/sample.csv", “r”, :headers => true) do |csv|
puts “got all contents from file #{csv}”

not iterate each row

csv.each do |row|
puts “Each row #{row}”
end
end

try this…if not let me know your ruby version and OS details…

tamouse m. wrote in post #1114463:

On Jul 4, 2013, at 3:07 PM, Nithi anand [email protected] wrote:

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

What line number is appearing with that message?

Line 2

I try your code doesnot work please see my attachment I am using ruby
2.0 and windows xp

Martin Jose wrote in post #1114476:

This code works fine…

require “rubygems”
require “csv”

CSV.open("/home/user1/sample.csv", “r”, :headers => true) do |csv|
puts “got all contents from file #{csv}”

not iterate each row

csv.each do |row|
puts “Each row #{row}”
end
end

try this…if not let me know your ruby version and OS details…
doesnot work
I am using sketchup pro 8 and os is windows xp not ruby or rubygems.
what I am trying to do here I have sunroom model it has doors and
windows
I set it up attribute like part number and price. but the price is will
change every year. that’s why I create simple csv file called
“price_lookup.csv” It will take part number and compare the price. this
way for me to easy to update just price in the csv file. I think you
will get the Idea now.let me know what I missing here
thanks for the reply

On Jul 5, 2013, at 12:39 PM, Nithi anand [email protected] wrote:

I try your code doesnot work please see my attachment I am using ruby
2.0 and windows xp

Attachments:
http://www.ruby-forum.com/attachment/8574/rubytest.jpg


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

Your problem is exactly this: you gave irb the name of the file of your
code, but irb doesn’t know what to do with that.

If you just want to run the file, give it to ruby instead:

C:> ruby CSV_test.rb

You can, as well, load your file into irb to work with:

irb(main):001:0> load ‘CSV_test.rb’

Am 05.07.2013 21:39, schrieb Nithi anand:

I try your code doesnot work please see my attachment I am using ruby
2.0 and windows xp

Attachments:
http://www.ruby-forum.com/attachment/8574/rubytest.jpg

Unless the code and error message is dozens of lines long, please
simply copy/paste them directly into the email.

Regards,
Marcus