Hello!
I'm new here, I'm new in Sketchup, I'm new in Ruby... But I'm not new in programming.
So, I have one maybe too stupid question.
I'm trying to use iterators like 'for in', until and .each. But they don't work! I think this is simpliest things in any programming language... and they work in all languages I use...
What's wrong with my Sketchup Ruby?
I use Sketchup 8 free version
Iterators in Sketchup Ruby
5 posts
• Page 1 of 1
Re: Iterators in Sketchup RubyIt'd be much easier for us to understand - and reply - if you included actual text in the body of your post [copy+paste and use code-formatting tags].
Your screen-shots are not the most user friendly method... The iteration methods you desire are available in Ruby. e.g. https://www.skorks.com/2009/09/a-wealth ... iterators/ Most authors use them very frequently... To comment briefly on your issues...
I assume you meant '0' Other similar methods are:
Also don't use capital letters to start a 'variable' [aka 'reference'] name. Ruby assumes those are 'Constants' - they can still be reset, but then error messages appear in the Console. Use lower-case characters - e.g. xxx - to start normal references. Capitals - XXX - for Constants that do not change. use @xxx for references which are shared across methods in a Module , or those in an instance of a Class. Use @@xxx for references remembered across instances of a Class. Note that $xxx variables should be avoided, they apply globally, and are reserved to the core kernel use, and their use can always be replicated using @/@@ references anyway, limiting it to within your own 'name-space' module... TIG
Re: Iterators in Sketchup RubyHi, TIG!
Thank you very much for your detailed answer, it is very usefull for me because I'm just a beginner in Ruby. I'm sorry for bad pics. I post new But... about this problem. I just copy code from this book Automatic SketchUp Creating 3-D Models in Ruby by Matthew Scarpino 2010 It uses SketchUp 7.1 application programming interface (API) for count1 in 0..5 print count1, " " end This code doesn't work in Sketchup 6, Sketchup 8, Sketchup 8 PRO. But it works in Sketchup 2015PRO... Re: Iterators in Sketchup RubyThe error message is saying that the interpreter parsed the text "for count1 in 0..5" and didn't find a line ending that it could understand. It wanted "do", ";", or "\n" (LF) and got something else. The fact that it works in 2015 suggests to me that this is an issue with the Ruby version embedded in SketchUp. Before SketchUp 2014 it was a variant of Ruby 1.8. As of 2014 it changed to Ruby 1.9 and since to successive versions of Ruby 2.x. One of the most important parts of the change was to require unicode character encoding. At least one of your screens suggests your computer locale is Russia? If so, your computer may be feeding unicode line endings that the older Ruby versions don't understand.
Re: Iterators in Sketchup Rubytry a 'one liner' directly in SU's Ruby Console...
I think the errors are caused by RubyConsolePro rather than the snippet... on a PC, SU's Ruby Console has only recently accepted 'multiline' input... Mat always saves the snippets as files and loads those... john learn from the mistakes of others, you may not live long enough to make them all yourself...
5 posts
• Page 1 of 1
|
Who is online
Users browsing this forum: helijana and 15 guests