Hello, I am new to ruby and cannot understand why this code is not
working:
direction = doc.elements.each(“doc:iso_10303_28/uos/IfcCartesianPoint”)
{ |element| puts element.attributes[“id”] }
this produces [i1586,i1667,i1915,i2041,i2160]
result = []
direction.each do |z|
n = direction[z].attribute[“id”]
result << n
end
This gives me the following error: Error: #<TypeError: C:/Program Files
(x86)/Google/Google SketchUp 8/Plugins/examples/one.rb:61:in `[]’: can’t
convert REXML::Element into Integer>
However when I use the following code, which to me seems to do exactly
the same thing in a less sophisticated manner, it works without issue:
direction = doc.elements.each(“doc:iso_10303_28/uos/IfcCartesianPoint”)
{ |element| puts element.attributes[“id”] }
n=0
result = []
while n != direction.length
z = direction[n].attributes[“id”]
result << z
n=n+1
end
#output - > [“i1586”, “i1667”, “i1915”, “i2041”, “i2160”]
Any ideas?
Addition info - Ruby 1.8.6.