I am creating an extension in which I am passing my website having components in HtmlDialog. In the HtmlDialog after few clicks, the component( DWG/3G) file gets downloaded. I want to handle this download file and open it directly in the SketchUp model. I know similar kinds of extensions have been developed in past. Could you please help me with a sample script to achieve this scenario? I am new to Ruby and SketchUp. How can I use action_callback to open the file in SketchUp.
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.
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: