Taking content from arrays to open a .3ds file

This is part of my program. what it is intented to do is get the first
line of a txt file which is saved in a[0]. this will be the name of a
.3ds model which than has to be imported in sketchup, but to do so, .3ds
has to be added to the name. Something is wrong with my code I know it’s
something in the first line show but I can’t figure how to write it
correctly.

machine = “a[0].3ds”
model = Sketchup.active_model
show_summary = true
status = model.import machine, show_summary

Thanks

hello,

i may be misunderstanding what you want to do, but if not - try
something like this:

a = [“foo”, “bar”]
machine = a[0] + “.3ds”
puts machine

=> foo.3ds

or…

a = [“foo”, “bar”]
machine = “#{a[0]}.3ds”
puts machine

=> foo.3ds

  • j

On Thursday, March 17, 2011, stephanie borg [email protected] wrote:
[…]

machine = "a[0].3ds

machine = “{a[0]}.3ds”

See String interpolation.

What it’s outputing is :

foo
.3ds

I can’t seem to get them in the same line!!

On Thursday, March 17, 2011, stephanie borg [email protected] wrote:

What it’s outputing is :

foo
.3ds

I can’t seem to get them in the same line!!

Probably your a[0] contains a new line.

Your string may have “\n” at last.
How about this?

machine = “#{a[0].strip}.3ds”

String#strip removes whitespaces

What it’s outputing is :

foo
.3ds

I can’t seem to get them in the same line!!

Probably your a[0] contains a new line.

Sorry. Accidentally hit send before typing in the complete response.

Try String#chomp method.

“{a[0].chomp}.3ds”

yesss yesss yesss it worked!!! thankss all of you!! This forum is
really helpful! Thanks again everybody! :slight_smile:

yes it worked!! :slight_smile: thankss, you people are very helpful!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs