We ask that you at the very least, make an attempt yourself at solving your challenges.
If your component files are SKP models, then your extension can download directly into the model’s component collection using the Sketchup::DefinitionList#load_from_url()
method.
Otherwise you will need to use Sketchup::Http::Request
to get the component file as the response body. If there were no errors, then you use Ruby core IO::write
(or IO::binwrite
) to save the response body as a file to the user’s local filesystem.
To get the path for saving SKP files use:
comp_folder = Sketchup.find_support_file("Components")
All SKP component files should be in a subfolder of the above folder so that they can be browsed using SketchUp’s Component Inspector panel.
save_path = File.join(comp_path, "AddySingh")
Dir.mkdir(save_path) if !File.exist?(save_path)
save_file = File.join(save_path, "some_file.skp")
IO.binwrite(save_file, response.body)
REF:
Sketchup.find_support_file()
File
class
Dir
class
Non-SKP files should likely be saved in the TEMP folder and then deleted later.
save_path = Sketchup.temp_dir
REF:
Once downloaded you can check that it exists, then use DefinitionList.import
if it is not a SKP file, or DefinitionList.load
if it is a SKP file. …
if File.exist?(save_file)
# load the component into the model's definitions collection:
if File.extname(save_file) !~ /skp/i
comp_def = model.definitions.import(save_file)
else
comp_def = model.definitions.load(save_file)
end
end
Once in the model’s definitions collection either the user can use it manually from the Component inspector panel (ie, it will appear in the “In Model” collection via the house button) or:
(a) you can insert it at a particular 3D point using Entities.add_instance
# Transform can be a point array or a transformation object:
model.active_entities.add_instance(comp_def, transform)
REF:
… or (b) you can have the user place it using Model.place_component
model.place_component(comp_def)
REF:
Take some some time to learn the basics …
…
It is advisable to know how the application works before extending it.