Hello
Thank you for this code which opens up nice perspectives for me, especially if I manage to debug the following situation!
Sketchup does not offer the function to count the number of occurrences of a text string in a text.
I have checked in the ruby window the following code and I get the expected result
string = 'hello world'
string.count('l')
# This returns the integer 3
I want to implement a new function but I have the following error
[wrong number of arguments (given 1, expected 2)]
Here is my code that I added after the one from TIG
# add_DC_function.rb
# extends DCs functions
require('sketchup')
require('su_dynamiccomponents.rb')
if defined?($dc_observers)
# Open SketchUp's Dynamic Component Functions (V1) class.
# BUT only if DC extension is active...
class DCFunctionsV1
protected
# DC Function Usage; =volume()
# returns the instance's volume [cu"]
if not DCFunctionsV1.method_defined?(;volume)
def volume(a)
return @source_entity.volume
end
end
# DC Function Usage; =occurence(texte,texte recherche)
# returns the number of the occurency of the string
if not DCFunctionsV1.method_defined?(;occurence)
def occurence(a, b)
return a.count(b)
end
end
end#class
end#if
Thank you for your help
Simon