sketchucation logo sketchucation
    • Login
    1. Home
    2. Elagym
    โ„น๏ธ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 3
    • Groups 1

    Elagym

    @Elagym

    10
    Reputation
    1
    Profile views
    3
    Posts
    0
    Followers
    0
    Following
    Joined
    Last Online

    Elagym Unfollow Follow
    registered-users

    Latest posts made by Elagym

    • RE: Launching ruby script from Java

      Ok I've found a workaround. It's not very clean but it works...

      I modified the AppObserver.rb located in my openstudio folder : in the function onOpenModel, I added a [load 'myScript.rb'] in order to inject my script in the sketchup scope.

      posted in Developers' Forum
      ElagymE
      Elagym
    • RE: Launching ruby script from Java

      @tig said:

      Have you tried also requiring the langhandler file?
      require 'C:\product\SketchUp\SketchUp 2016\Tools\langhandler.rb'

      Sorry I forgot to mention that I tryed to add this line too but I've the same error. I removed it because it is already required in sketchup.rb but I got an error in both cases.

      It looks like my script cannot access those ruby files if I run it from outside sketchup ๐Ÿ˜•

      I also tryed modifying the sketchup.rb file : I set the entire path in [require 'langhandler.rb'] and then I got this error :

      
      NameError; uninitialized constant LanguageHandler;;Sketchup
            const_missing at org/jruby/RubyModule.java;3309
        find_strings_file at C;/product/SketchUp/SketchUp 2016/Tools/langhandler.rb;110
                    parse at C;/product/SketchUp/SketchUp 2016/Tools/langhandler.rb;137
               initialize at C;/product/SketchUp/SketchUp 2016/Tools/langhandler.rb;36
                    <top> at C;/product/SketchUp/SketchUp 2016/Tools/sketchup.rb;16
                  require at org/jruby/RubyKernel.java;944
                   (root) at uri;classloader;/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb;1
                    <top> at uri;classloader;/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb;55
      javax.script.ScriptException; org.jruby.embed.EvalFailedException; (NameError) uninitialized constant LanguageHandler;;Sketchup
      	at org.jruby.embed.jsr223.JRubyEngine.wrapException(JRubyEngine.java;104)
      	at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java;121)
      	at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java;146)
      	at ProxyTester.main(ProxyTester.java;59)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java;95)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java;56)
      	at java.lang.reflect.Method.invoke(Method.java;620)
      	at com.intellij.rt.execution.application.AppMain.main(AppMain.java;144)
      Caused by; org.jruby.embed.EvalFailedException; (NameError) uninitialized constant LanguageHandler;;Sketchup
      	at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java;131)
      	at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java;118)
      	... 7 more
      Caused by; org.jruby.exceptions.RaiseException; (NameError) uninitialized constant LanguageHandler;;Sketchup
      	at org.jruby.RubyModule.const_missing(org/jruby/RubyModule.java;3309)
      	at RUBY.find_strings_file(C;/product/SketchUp/SketchUp 2016/Tools/langhandler.rb;110)
      	at RUBY.parse(C;/product/SketchUp/SketchUp 2016/Tools/langhandler.rb;137)
      	at RUBY.initialize(C;/product/SketchUp/SketchUp 2016/Tools/langhandler.rb;36)
      	at RUBY.<top>(C;/product/SketchUp/SketchUp 2016/Tools/sketchup.rb;16)
      	at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java;944)
      	at RUBY.(root)(uri;classloader;/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb;1)
      	at RUBY.<top>(uri;classloader;/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb;55)
      
      

      I think there's like a snowball effect, I guess that modifying all the sketchup's files is not the good way to proceed.

      posted in Developers' Forum
      ElagymE
      Elagym
    • Launching ruby script from Java

      Hi guys,

      I'm new to ruby and I wrote a script which automatize import of an .idf file in sketchup and exports it as a .dae file. WhenI load my script from the ruby code editor, there's no problem, but when I try to launch it from java, it seems like it cannot load the sketchup's dependencies I need.

      Here is my java code :

      
                  ScriptEngine jruby = new ScriptEngineManager().getEngineByName("jruby");
                  jruby.eval(new BufferedReader(new FileReader("C;\\product\\SketchUp\\SketchUp 2016\\Tools\\api_dev.rb")));
      
      

      (I added my script in this folder, don't know if its a good way to do...)

      Here is the content of api_dev.rb :

      
      require 'C;\product\SketchUp\SketchUp 2016\Tools\sketchup.rb'
      
      model = Sketchup.active_model
      model.close_active;
      show_summary = true
      status = model.import "C;/path/myIdfFile.idf", show_summary
      
      # Or for a COLLADA (.dae) file, using the default options
      
      options_hash = { ;triangulated_faces => true,
      				;doublesided_faces => false,
      				;edges => true,
      				;author_attribution => false,
      				;texture_maps => false,
      				;selectionset_only => false,
      				;preserve_instancing => true}
      model.export 'C;/path/exportedDaeFile.dae',  options_hash
      
      
      

      And here is the stacktrace I get :

      
      LoadError; no such file to load -- langhandler
        require at org/jruby/RubyKernel.java;944
        require at uri;classloader;/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb;55
          <top> at C;/product/SketchUp/SketchUp 2016/Tools/sketchup.rb;15
        require at org/jruby/RubyKernel.java;944
         (root) at uri;classloader;/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb;1
          <top> at uri;classloader;/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb;55
      javax.script.ScriptException; org.jruby.embed.EvalFailedException; (LoadError) no such file to load -- langhandler
      	at org.jruby.embed.jsr223.JRubyEngine.wrapException(JRubyEngine.java;104)
      	at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java;121)
      	at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java;146)
      	at ProxyTester.main(ProxyTester.java;60)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java;95)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java;56)
      	at java.lang.reflect.Method.invoke(Method.java;620)
      	at com.intellij.rt.execution.application.AppMain.main(AppMain.java;144)
      Caused by; org.jruby.embed.EvalFailedException; (LoadError) no such file to load -- langhandler
      	at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java;131)
      	at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java;118)
      	... 7 more
      Caused by; org.jruby.exceptions.RaiseException; (LoadError) no such file to load -- langhandler
      	at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java;944)
      	at RUBY.require(uri;classloader;/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb;55)
      	at RUBY.<top>(C;/product/SketchUp/SketchUp 2016/Tools/sketchup.rb;15)
      	at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java;944)
      	at RUBY.(root)(uri;classloader;/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb;1)
      	at RUBY.<top>(uri;classloader;/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb;55)
      
      

      I don't understand why it doesn't manage to find langhandler file because its located in the same folder than sketchup.rb ...
      Am I missing something when I try to retrieve the sketchup's ruby files ?

      Thanks for you attention,

      Elagym

      posted in Developers' Forum
      ElagymE
      Elagym