# Kullanıcının klasör seçmesi
imglocation = UI.select_directory(
title: "Select Image Directory",
directory: File.expand_path('~'), # Kullanıcının ana dizini
select_multiple: false # Sadece bir klasör seçmesini sağlar
)
# Eğer kullanıcı bir klasör seçtiyse
if imglocation
# Klasördeki JSON dosyalarını al
json_files = Dir[File.join(imglocation, "*.json")]
# Eğer hiç JSON dosyası yoksa
if json_files.empty?
UI.messagebox("Seçilen klasörde JSON dosyası bulunamadı!")
return
end
# JSON dosyalarını tek tek işleme
json_files.each do |file_path|
begin
# JSON dosyasını oku
json_data = File.read(file_path)
data = JSON.parse(json_data)
# JSON verisi ile işlem yapabilirsiniz
UI.messagebox("İşlenen dosya: #{file_path}")
# Burada işleme devam edebilirsiniz.
rescue JSON::ParserError => e
# Eğer JSON verisi geçerli değilse, kullanıcıya hata mesajı gösterilir
UI.messagebox("Hata: JSON verisi geçerli değil! Dosya: #{file_path}, Hata: #{e.message}")
end
end
else
# Klasör seçilmediyse, kullanıcıya bir mesaj gösterilir
UI.messagebox("Klasör seçilmedi!")
end
Is there a question you wanted help with?
I found a solution, I wanted to share it, multiple selection ruby, thank you.
For examples, the comments should be in English as Ruby is an English programming language.
Your topic title says “… example for multiple selections”
But the UI.select_directory
option is:
The window caption for the UI.select_directory
window is set to:
… but the code is finding JSON files:
Why not use json_path
instead of the imglocation
reference?
Lastly, I used it for json, sir. I used it for a photo. I shared it as a logic, sir. I changed it according to the situation. It was my working file. You are right, sir.
Will these explanations cause any problems in the Sketchup team’s plugin review? I tried a few times but was not accepted.
I would not think so, but then I am not part of the EW review team.
This topic was automatically closed after 186 days. New replies are no longer allowed.