aerilius / sketchup-bridge Goto Github PK
View Code? Open in Web Editor NEWA bidirectional communication system between WebDialogs and the SketchUp Ruby environment
License: MIT License
A bidirectional communication system between WebDialogs and the SketchUp Ruby environment
License: MIT License
Hi. Sorry for my english. I just espeak portuguese. So, lets go. I trying to use Bridge.call on Sketchup 2022 and I have this issue:
"undefined method
call' for PRBO::Devix::Bridge:Class (Line 1)" Error: #<TypeError: no implicit conversion of NoMethodError into String> C:/Users/paulo/AppData/Roaming/SketchUp/SketchUp 2022/SketchUp/Plugins/as_rubyeditor/as_rubyeditor.rb:346:in
+'
C:/Users/paulo/AppData/Roaming/SketchUp/SketchUp 2022/SketchUp/Plugins/as_rubyeditor/as_rubyeditor.rb:346:inrescue in block in initialize' C:/Users/paulo/AppData/Roaming/SketchUp/SketchUp 2022/SketchUp/Plugins/as_rubyeditor/as_rubyeditor.rb:344:in
block in initialize'my code:
module PRBO module Devix class DialogBox attr_accessor :dlg def initialize dialog = UI::HtmlDialog.new({ :dialog_title => "Plugin Devix", :preferences_key => "com.sample.plugin", :scrollable => true, :resizable => true, :width => 1000, :height => 1000, :left => 100, :top => 100, :min_width => 800, :min_height => 50, :style => UI::HtmlDialog::STYLE_DIALOG }) dialog.set_file('c:/DevixPlugin/html/index.html') @dlg = dialog end end load "c:/DevixPlugin/lib/bridge/bridge.rb" def self.showMenu dlg_menu = DialogBox.new dlg = dlg_menu.dlg Bridge.decorate(dlg) #Bridge.new(dlg) dlg.on('ponte') {|deferred, mensagemponte| p mensagemponte deferred.resolve(1000) } dlg.show Bridge.call('borogodo','testando') end showMenu end end############ my index.html
<!DOCTYPE html> <html lang="pt-br"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Devix - Tools</title> <style> * { margin: 0; padding: 0; } </style> <script type="text/javascript" src="./js/bridge.js"></script> </head> <body> <div class="container"> <div class="Button"> <button type="button" id="teste">Teste click</button> </div> </div> <script type="text/javascript"> var botao = document.getElementById('teste'); botao.addEventListener('click', function(event) { Bridge.get('ponte', 'mariola').then(function (testando) { window.alert(testando); }); }); function borogodo() { window.alert("Mensagem vinda do Sketchup"); }; </script> </body> </html>################
when a click on button on the html file, the Bridge works. I wanna make work from sketchup. On event, call a function on index.html and return some data.
Originally posted by @PRBO84 in #13 (comment)
Hi :)
I might have found a serialization bug.
I have this issue where some fields sent over from the Ruby side are missing on the JS side. After a lot of testing, it seems to be happening with mixed Ruby hashes (with both symbols and string keys) sent via call()
.
How to reproduce from the Ruby side:
hash1 = { # all symbols, will work fine
a: 1,
b: 'hello'
}
hash2 = { # all strings, will work fine
'a' => 1,
'b' => 'hello'
}
hash3 = { # mixed, b will be missing
'a' => 1,
b: 'hello'
}
call('test', hash1)
call('test', hash2)
call('test', hash3)
The output on the JS side:
test: Object {a: 1, b: "hello"}
test: Object {a: 1, b: "hello"}
test: Object {a: 1}
Interestingly, this does not happen when sending data via promise resolution:
on('test1') do |deferred|
deferred.resolve({ a: 1, b: 'hello' })
end
on('test2') do |deferred|
deferred.resolve({ 'a' => 1, 'b' => 'hello' })
end
# This time it works
on('test3') do |deferred|
deferred.resolve({ 'a' => 1, b: 'hello' })
end
So maybe there's a serialization inconsistency between call() and resolve()?
I tried poking a bit in the code but at first glance I cannot see what goes wrong.
It might be good to package this as a separate ES6 module to import. I'm not totally sure how to go from the IIFE that bridge.js
currently is to a module export.
To be clear, this would help my use case, though I expect that the current form is most useful to a general audience who will drop this in a script tag instead.
Would it be possible to add type declaration for Typescript?
constant RESERVED_NAMES is a frozen array, and thus can't be mutated with the <<
method.
sketchup-bridge/dist/bridge.rb
Lines 647 to 659 in 081cee7
Could either remove the call to freeze or refactor this to be a pure function that takes the old RESERVED_NAMES as an argument and returns a new array. What do you think?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.