sketchucation logo sketchucation
    • Login
    1. Home
    2. macumber
    3. Posts
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    M
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 4
    • Posts 16
    • Groups 1

    Posts

    Recent Best Controversial
    • Check which plugins are enabled in Preferences->Extensions

      I am trying to check which plugins are enabled in the Preferences->Extensions menu. The following code seems like it should work to me (it asks for variables that are in the registry, the checked plugins have value 1 and the unchecked ones have value 0) but it doesn't work (at least on Windows with SU 7). Does anyone know if we are blocked from reading/writing to the Extensions preferences? Is there another way to check if another plugin is enabled?

      ObjectSpace.each_object(SketchupExtension) do |p|
      variable = "#{p.name}"
      puts variable
      puts Sketchup.read_default("Extensions", variable, nil)
      variable = "#{p.name}#{p.version}"
      puts variable
      puts Sketchup.read_default("Extensions", variable, nil)
      end

      Thanks a lot,
      Dan

      posted in Developers' Forum
      M
      macumber
    • RE: Example of Compiled Extension with SWIG and CMake

      After working with the SDK for a little while I don't think it can be wrapped as quickly as I first thought. I have to get back to work on my real tasks so the SDK wrap project will have to wait for a while. But I did make another example using SWIG with directors to show how to pass Ruby objects into C++ code. We are looking into this to implement Ruby observers for events that happen in our own C++ code.

      Hope this helps,
      Dan


      Rename to .zip and extract

      posted in Developers' Forum
      M
      macumber
    • RE: Example of Compiled Extension with SWIG and CMake

      I started a project to wrap the SDK for Ruby at:

      Link Preview Image
      Google Code Archive - Long-term storage for Google Code Project Hosting.

      favicon

      (code.google.com)

      I am just getting started now and focusing only on Windows but hopefully this could be extended pretty quickly. Let me know if you are interested in helping/using.

      Dan

      posted in Developers' Forum
      M
      macumber
    • RE: SketchUp Command Line: RubyStartup

      This is very interesting, thanks for sharing, are there other command line arguments to SketchUp? SketchUp.exe --help, /?, etc just launches the program...

      Dan

      posted in Developers' Forum
      M
      macumber
    • Example of Compiled Extension with SWIG and CMake

      Sounds like there was enough interest in compiled extensions at Basecamp that I whipped up this small example. We have found the recipe of CMake + SWIG to be very useful in making cross-platform extensions (or any C++ project). I have only tested this example on Windows, I may have to update it for Mac, let me know if you have any problems with it. A great idea floated around at Basecamp was to wrap the C++ SDK for file access with Ruby, that way developers could write Ruby scripts to access skp files from within SketchUp or at the command line. I would suggest CMake + SWIG as a route to do that. As a final note, if you really don't like the generated interfaces you can always wrap the generated wrapper code from SWIG with your own pure Ruby to your heart's content.

      The attached file is really a zip file, rename the file extension to .zip and extract.

      Hope this helps,
      Dan


      Rename to .zip and extract

      posted in Developers' Forum
      M
      macumber
    • OnChangeActiveModel observer

      I have been looking around for an observer to fire when the active_model changes but haven't had any luck. Is there such a thing?

      posted in Plugins
      M
      macumber
    • RE: Adding child group while parent group is active

      Well I guess I will have to get off my butt and post the answer to my own question:

      
      # clear everything out
      Sketchup.active_model.entities.clear!
      
      # add the parent group
      group1 = Sketchup.active_model.entities.add_group
      
      # set parent’s transformation
      group1.transformation = Geom;;Transformation.translation(Geom;;Point3d.new(10.m, 0, 0))
      
      # add some points to the parent group
      group1.entities.add_cpoint(Geom;;Point3d.new(0.m, 0.m, 0.m))
      group1.entities.add_cpoint(Geom;;Point3d.new(5.m, 5.m, 3.m))
      
      # add the child group
      group2 = group1.entities.add_group
      
      # set child’s transformation
      group2.transformation = Geom;;Transformation.translation(Geom;;Point3d.new(0, 10.m, 0))
      
      # add some points to the child group
      group2.entities.add_cpoint(Geom;;Point3d.new(0.m, 0.m, 0.m))
      group2.entities.add_cpoint(Geom;;Point3d.new(5.m, 5.m, 3.m))
      
      # group transformations are now correct
      puts Sketchup.active_model.active_path
      puts group1.transformation.to_a.join(', ')
      puts group2.transformation.to_a.join(', ')
      puts Sketchup.active_model.edit_transform.to_a.join(', ')
      
      # from top level
      active_path = nil
      group1.transformation = [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 393.700787401575, 0.0, 0.0, 1.0]
      group2.transformation = [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 393.700787401575, 0.0, 1.0]
      edit_transform = [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]
      
      # open group1
      active_path = [group1]
      group1.transformation = [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]
      group2.transformation = [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 393.700787401575, 393.700787401575, 0.0, 1.0]
      edit_transform = [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 393.700787401575, 0.0, 0.0, 1.0]
      
      # open group2
      active_path = [group1, group2]
      group1.transformation = [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]
      group2.transformation = [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]
      edit_transform = [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 393.700787401575, 393.700787401575, 0.0, 1.0]
      
      
      posted in Plugins
      M
      macumber
    • RE: Adding child group while parent group is active

      I guess a simple question is which component are you editing when you are editing group2 inside of group1? Are you editing group2, group1, or both?

      posted in Plugins
      M
      macumber
    • RE: Adding child group while parent group is active

      Thanks ThomThom, do you have any information explaining edit_transform in more detail? In my case I have group1 with group2 inside of it. I sort of understand what this does when the active_path is '[group1]'. However, what happens when the active path is '[group1, group2]'? What I'm really after is some documentation like:

      when active_path is '[]', group1.transformation returns xxx, group2.transformation returns yyy, active_model.edit_transform returns zzz
      when active_path is '[group1]', group1.transformation returns xxx, group2.transformation returns yyy, active_model.edit_transform returns zzz
      when active_path is '[group1, group2]', group1.transformation returns xxx, group2.transformation returns yyy, active_model.edit_transform returns zzz

      posted in Plugins
      M
      macumber
    • RE: C Extension on OSX crashes SU

      I checked and have a similar problem. I have only been testing my extension in SketchUp on Windows and IRB on Windows/Mac. I'm going to look into it too and will post anything I find here.

      Dan

      posted in Developers' Forum
      M
      macumber
    • RE: Move child component in dynamic component

      Works great, thanks so much! I guarantee I would not have gotten that on my own.

      (PS I went with option 2 because the user can still move them on their own.)

      Thanks a lot,
      Dan

      posted in Plugins
      M
      macumber
    • RE: Ruby extension module using C/C++

      I think the main things are to link against the same version of the Microsoft Runtime library (MSVCRT.DLL, looks like Sketchup 7.1 uses MSVCRT 7.0.2600.5512) and same version of Ruby (1.8.0, although I have used 1.8.6 without problem so far...). There is a fork between MSVC and MinGW camps for Ruby on Windows, make sure you don't try to link against the MinGW build of Ruby.

      posted in Developers' Forum
      M
      macumber
    • RE: Ruby extension module using C/C++

      In case anyone tries this on Windows, this post helped me out when I was first starting:

      http://apocryph.org/2007/06/16/totally_bullshit_ruby_extension_experience_windows/

      posted in Developers' Forum
      M
      macumber
    • RE: Ruby extension module using C/C++

      You can download SWIG at http://www.swig.org/ and build some of the Ruby examples. Then you just put the compiled dll in the Ruby search path for SketchUp and require it like a Ruby script. To be binary compatible with the SketchUp Ruby you should compile with MSVC on Windows and gcc on Mac. You do have to compile separately for each platform, the makefiles/Visual Studio projects are not cross platform so you either need to maintain separate projects or use something like CMake (which is a cross platform makefile generator).

      I don't know if the dll will make it through as an attachment (rename 'example.txt' to 'example.dll') but I compiled the example 'C:\SWIG\Examples\ruby\class' using Visual Studio Express 2009 and attached the dll. You can put it in the plugins directory and use the following script:

      ###########################################
      require 'example'

      c = Example::Circle.new(1)
      puts c
      s = Example::Square.new(1)
      puts s
      ###########################################

      Hope that helps,
      Dan


      example.txt

      posted in Developers' Forum
      M
      macumber
    • RE: Ruby extension module using C/C++

      Just an FYI, I have used SWIG to generate Ruby extensions from C++ fairly easily.

      posted in Developers' Forum
      M
      macumber
    • Move child component in dynamic component

      I am attempting to move a child in a dynamic component through a Ruby script by setting the entity's transformation. This appears to work at first, but I get a really weird effect when I redraw (either through redraw_with_undo or using the hand icon). The objects seem to jump around, if I keep resetting the transformation and redrawing eventually it converges to the right place. Does anyone know why this is happening or a better way to move these sub components in a Ruby script(while still allowing the user to move them through the UI)? Here is my demo script and I have attached the problem component.

      Thanks a lot,
      Dan

      OpenStudio_DaylightingControls.skp

      import the component "OpenStudio_DaylightingControls.skp" and place at the origin

      select the component as the only component then run this script

      selection = Sketchup.active_model.selection
      view = Sketchup.active_model.active_view

      for i in 0..10
      puts selection[0].definition.entities[0].transformation.origin
      selection[0].definition.entities[0].transformation = Geom::Transformation.translation([0.m, -1.m, 0.m])
      puts selection[0].definition.entities[0].transformation.origin

      $dc_observers.get_latest_class.redraw_with_undo(selection[0])

      view.refresh

      sleep(1)
      end

      posted in Plugins
      M
      macumber
    • 1 / 1