Hello guys, a wanna-be programmer here. I’m a woodworker that uses a lot Dynamic Components to create my bespoke cabinets in my shop.
I know that there are thousands plugins like that, but I want to share my own components with my plugin and I’m having some trouble.
I’ve already created a html webpage and some models are up on a server, but I just can’t download them from the website. I can download them if I specify all the links in the *.rb file , but I believe this is not the deal.(this way the website became useless, right?)
I’ve read that I need to create an API to send data from website to Sketchup, but I really don’t know how to do it. Maybe somene could help me with a basic code?
I’m using a free website server by now, models are hosted at Amazon AWS S3 servers.
I just need a code (or the path to write it) that allows download data from amazon to sketchup, without coding it manually at *.rb file. Thank you guys! Sorry for bad english
Update: Here’s my actual .rb file code, as you guys can see, links are “open” to everyone that reads rb file.
# Solicitar API do Sketchup
require 'sketchup.rb'
require 'open-uri'
# Criar botão na barra de ferramentas
toolbar = UI::Toolbar.new 'Orbaneça Blocos Dinamicos'
# Comando para abrir a janela
cmd = UI::Command.new('Orbaneça Blocos Dinamicos') {
dialog = UI::HtmlDialog.new({
:dialog_title => "Janela de autenticação",
:preferences_key => "com.example.plugin",
:scrollable => true,
:resizable => true,
:width => 600,
:height => 400,
:left => 100,
:top => 100,
:min_width => 50,
:min_height => 50,
:max_width => 1000,
:max_height => 1000
})
# Defina a URL da janela HTML
dialog.set_url("https://orbaneca.000webhostapp.com/app.php")
# Adicionar um callback para receber a ação dos botões
dialog.add_action_callback('button_clicked') { |dialog, button_id|
# Aqui você pode verificar qual botão foi clicado e adicionar a lógica para carregar o componente dinâmico correspondente.
if button_id == 'button1'
# Carregar o componente dinâmico "gaveta.skp"
model = Sketchup.active_model
url = 'https://orbaneca-blocos.s3.sa-east-1.amazonaws.com/Gaveta.skp' # Substitua este URL pelo endereço da prateleira.skp em seu servidor
temp_file = Tempfile.new('temp.skp')
temp_file.binmode
open(url, "rb") { |read_file| temp_file.write(read_file.read) }
temp_file.close
definition = model.definitions.load(temp_file.path)
instance = model.entities.add_instance(definition, Geom::Point3d.new(0,0,0))
elsif button_id == 'button2'
# Carregar o componente dinâmico "painel.skp"
model = Sketchup.active_model
url = 'https://orbaneca-blocos.s3.sa-east-1.amazonaws.com/Painel+engrossado+tamburato.skp' # Substitua este URL pelo endereço da prateleira.skp em seu servidor
temp_file = Tempfile.new('temp.skp')
temp_file.binmode
open(url, "rb") { |read_file| temp_file.write(read_file.read) }
temp_file.close
definition = model.definitions.load(temp_file.path)
instance = model.entities.add_instance(definition, Geom::Point3d.new(0,0,0))
elsif button_id == 'button3'
# Carregar o componente dinâmico "prateleira.skp", este vem da internet
model = Sketchup.active_model
url = 'https://orbaneca-blocos.s3.sa-east-1.amazonaws.com/Prateleira+engrossada+tamburato.skp' # Substitua este URL pelo endereço da prateleira.skp em seu servidor
temp_file = Tempfile.new('temp.skp')
temp_file.binmode
open(url, "rb") { |read_file| temp_file.write(read_file.read) }
temp_file.close
definition = model.definitions.load(temp_file.path)
instance = model.entities.add_instance(definition, Geom::Point3d.new(0,0,0))
end
}
dialog.show
}
icon = File.join(__dir__, 'orbaneca', 'icon.png')
cmd.small_icon = icon
cmd.large_icon = icon
cmd.tooltip = 'Orbaneça Blocos Dinamicos'
cmd.status_bar_text = 'Este é meu primeiro app, boa sorte'
toolbar.add_item cmd
toolbar.show
# Adicionar o nome do plugin no menu de plugins do Sketchup
UI.menu('Plugins').add_item('Orbaneça') {
# Ao clicar na janela, o seguinte conteudo acontecerá:
UI.messagebox('Deu certo mesmo!')
}
# Mostrar o console ao abrir o Sketchup para verificar erros
SKETCHUP_CONSOLE.show