We are kind of getting off the topic here … or is there even a clear topic trend to this thread ?
Please post code correctly on the forum. For short one-liners you can use backtick delimiters, ie ` (it’s the key on the left above the TAB key and to the left of the 1 key.)
Once again, you DO NOT use Sketchup.find_support_file
to find YOUR OWN extension’s files.
So lets us say within a method in a rb file, evaluated from your extension subdirectory, you have the statement …
more = File.join(__dir__, "Textures", "More")
… then the string that more
references should be :
".../Plugins/AllanBlock_RetainingWall_3DModelingTools/Textures/More"
(where the .../Plugins
is the absolute path to the "Plugins"
directory for whatever version of SketchUp that is running.
In other words, the global __dir__
method returns the absolute path to the directory of the rb
file that it is called from.
Got it?
But if you extension is going to use this path many times, you might as well defined either a @more
var or a local constant within your extension submodule.
So from then on you reuse that path string like …
veggy_grass = File.join(@more, "VegetationGrass.rb")
load veggy_grass
Also if you are going to use the "VegetationGrass.rb"
multiple times, then you must use load()
as require()
will only load and run it once per session.
Ie, it looks like perhaps your material files might be sequential command-like scripts. But as I don’t know really what you’re trying to do, I cannot say for sure.
It just looks a bit weird what you’re doing from the outside. Most developers would never have a standalone rb
file for individual materials. A single Ruby method can be coded to create any material from a short list of parameters.
def create_material(matl_name, collection)
textures = File.join(__dir__, "Textures", collection)
fail(IOError,"Bad folder name.",caller) if !File.exist?(textures)
texture = File.join(textures, "#{matl_name}.png")
fail(IOError,"Bad texture name.",caller) if !File.exist?(texture)
matls = Sketchup.active_model.materials
material = matls.add(matl_name)
if material
material.texture= texture
# set other properties, etc. ...
end
return material
rescue => error
# Handle errors here ...
end
And then from elsewhere you call the method …
material = create_material("Vegetation Grass", "More")
if material
# always check for truthy after creating SketchUp resources as
# they can fail and be nil (falsey). Use it here if it's truthy ...
end