mod = Sketchup.active_model
ent = model.active_entities
centerpoint = Geom::Point3d.new
vector = Geom::Vector3d.new 0,0,1
vector2 = vector.normalize!
(0..20).each do |i|
#create a circle perpendicular to the normal or Z axis
centerpoint = [i*5,sin(i)*10,0]
edges = entities.add_circle centerpoint, vector2, 2
face = entities.add_face(edges)
face.pushpull -i*10
end
When I run the code though I get this message
NameError into String>
C:/Users/boone/AppData/Roaming/SketchUp/SketchUp 2017/SketchUp/Plugins/as_rubyeditor/as_rubyeditor.rb:346:in +' C:/Users/boone/AppData/Roaming/SketchUp/SketchUp 2017/SketchUp/Plugins/as_rubyeditor/as_rubyeditor.rb:346:in rescue in block in initialize’
C:/Users/boone/AppData/Roaming/SketchUp/SketchUp 2017/SketchUp/Plugins/as_rubyeditor/as_rubyeditor.rb:368:in block in initialize' SketchUp:1:in call’
Your snippet has several code errors, mainly involving not matching the name of a variable from one statement to another. Also, sin is not defined at the global level, it is in the Math module and needs a qualifier. As a general comment, no code, even a snippet like this, should define variables at the global level. Always wrap code in a module!
These errors do not explain why you got the specific errors you reported. They ones you saw appear to emerge from the as_rubyeditor, which may be choking while trying to parse your erroneous code.
Edit: out of curiosity I downloaded as_rubyeditor and took a look at the line called out in the error message you got. I think it is a bug in that extension, ironically similar to the error in your code! While rescuing an Exception, the editor code at line 346 says
r = 'Run aborted. Error: ' + e
but the variable e is not defined at that point in the code, so it can’t be converted to a string to support the + operator. That prevented the editor from reporting the actual cause of the failure of your code.
Thank you. By comparing your script to what I had done, I was able to see what I had done wrong. So, even if I had matched the names it would not have worked.
Is it possible that years ago sin would have worked like he wrote it?
This code was originally posted in 2010. Have rules changed since then?
You have recommended that I use Notepad ++ as a code editor, how do you recommend I test out each line as I am making the file. The only way I have now to test code is copy and paste it into as_rubyeditor.
The Sphere Tool should load when you restart SketchUp. If you do not want it to run, put the “ex_sphere_tool.rb” file into the sphere tool folder you created before restarting SketchUp.
You can modify code in NotePad++, save it, and restart SketchUp to test your changes.
If you want to use the Math methods without qualification, then you can can include Math into your extension submodule. Alex might have done this with his editor’s module.
I copy code from Notepad++ and paste it into SketchUp’s native Ruby Console all the time.
You can get an extension that helps you load and test code from development repositories:
I find it useful @ene_su extension called Eneroth Script Runner * Eneroth Script Runner | SketchUp Extension Warehouse . I code with Visual Studio Code, save my file after changed it and then I drag the file to Sketchup. It’s fast and easy.