I'm interested in your Python solution. The forum PM function works fine, I think
azuby
I'm interested in your Python solution. The forum PM function works fine, I think
azuby
Please, please - no pros and cons between Ruby and Python. It would become a neverending thread. Ruby isn't file oriented and you can define your namespace (or mix-in) in more than one file.
Example to explain mix-ins:
class Light
# ...
end
l = Light.new
l.switch rescue puts "Light#switch is not implemented"
# => "Light#switch is not implemented"
module Switchable
def switch
puts "Switching ..."
end
end
class Light
include Switchable
end
l.switch rescue puts "Light#switch is not implemented"
# => "Switching"
# ... and the other way round;
class Light
undef ;switch
end
l.switch rescue puts "Light#switch is not implemented"
# => "Light#switch is not implemented"
azuby
You can use modules.
module YourNameSpace
class YourClass
# ...
end
end
YourNameSpace;;YourClass.new
Modules are used in two different ways: 1. to build namespaces, 2. to build mix-ins.
azuby
Difficult. You can't change it while Sketchup is running -> restart. But you can try to override the Sketchup methods for adding (sub) menus and menu items keeping the old methods with alias names. Your methods "hook" into the old methods, before they perform their action - short IRB session explaining what I'm talking about:
irb(main);001;0> class A
irb(main);002;1> def a
irb(main);003;2> puts "a"
irb(main);004;2> end
irb(main);005;1> end
=> nil
irb(main);006;0> class A
irb(main);007;1> alias ;old_a ;a
irb(main);008;1> def a
irb(main);009;2> puts "b"
irb(main);010;2> old_a
irb(main);011;2> end
irb(main);012;1> end
=> nil
irb(main);013;0> A.new.a
b
a
=> nil
Your method could read the correct menu structure i.e. from a text file. But you have to make sure, that your script is eval'ed by Sketchup before another script adds menus or menu items.
azuby
If you can't see the error messages, send them to a file.
azuby
@remus said:
I had a quick look at the website, and the rd edition deals with ruby 1.9, perhaps SU uses 1.8?
Exactly. Sketchup uses a real old Ruby (1.8.0). Most of the Ruby programmers use 1.8.6 (or 1.8.7) at the moment. Betwenn 1.8.6 and 1.8.7 they made some changes influenced by the development of 1.9.0 (and 1.9.1). But alos betwenn 1.8.7 and 1.9.0 (1.9.1) there are a lot changes.
azuby
My first thought was using mailto: - but it doesn't support attachments.
azuby
A return statement from a do..end / { } block is used in one of your installed Ruby scripts.
azuby
I think you should read the Pickaxe (but not the Third Edition!) and than digging into Sketchup Ruby API documentation.
azuby
You do D'n'D? I thought, you're a real cool programmer
using vi and so on.
azuby
Scrambler.exe yourfile.rb
Well - should be a really short documentation
azuby
Best is, not only using classes but also using modules for structuring your code. Modules can be used to represent different names spaces so you can't conflict with code from other Plugins:
module MyFunnyModule
class MyFunnyPlugin
def initialize
@myfunnyvariable = 0 # an instance variable
setup_ui
end
def increment
@myfunnyvariable = @myfunnyvariable + 1
end
def setup_ui
# here i. e. your toolbar code
# ...
# call the increment method from an UI;;Command;
cmd = UI;;Command.new("Foo") { increment }
# ...
end
end # MyFunnyClass
m = MyFunnyPlugin.new # get an instance of your class
end # MyFunnyModule
Do not use names beginning with big letter for your methods. And do not use CamelCase. It's just code style, but Ruby guys programm this way:
MoveLeft - OK for class and module names
moveLeft - not OK
move_left - OK for method and variable names
You should read a bit about Ruby.
azuby
Use the Toolbar class from the Sketchup Ruby API.
azuby
Use an instance variable. At the moment, your code should be in a class. Initialize your instance variable (i. e. @clicks - the @ is neeeded) in the initialize method of your class and use the variable in the code which is executed by clicking on your button.
azuby
Und? War's friedlich? Oder hat vielleicht irgendwo irgendeine Katze irgendeinen Braten geklaut?
azuby
In most of the cases developers declare their methods being private, there is a good reason for that. But you can try for your own whether this method does what you want by using send:
Sketchup.active_model.send ;open
With Sketchup 6 the result is:
Sketchup.active_model.send ;open
Error; #<ArgumentError; (eval);1619;in `initialize'; wrong number of arguments (0 for 1)>
(eval);1619
OK, the methods needs an argument. I tried with a path:
Sketchup.active_model.send ;open, "C;/bla.skp"
#<File;C;/bla.skp>
azuby
PLATFORM = (Object;;RUBY_PLATFORM =~ /mswin/i) ? ;windows ; ((Object;;RUBY_PLATFORM =~ /darwin/i) ? ;mac ; ;other)
edit: It's a one-liner.
azuby