sketchucation logo sketchucation
    • Login
    1. Home
    2. MSP_Greg
    ℹ️ 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 2
    • Posts 46
    • Groups 1

    MSP_Greg

    @MSP_Greg

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

    MSP_Greg Unfollow Follow
    registered-users

    Latest posts made by MSP_Greg

    • RE: SVG Toolbar Icons - Gradients Missing

      @placidfury said:

      or manually edit the SVG code so SketchUp will read it properly

      Well, SVG is XML and Nokogiri would certainly be up to the task. Wouldn't even need SketchUp to do the processing...

      Greg

      posted in Developers' Forum
      M
      MSP_Greg
    • RE: Socket.so sketchup 8 and 13

      For windows, the file at https://dl.bintray.com/oneclick/rubyinstaller/ruby-1.8.7-p370-i386-mingw32.7z
      contains a socket so file.

      I'd suggest you thoroughly test it. I added it to both, it loaded, and Ruby responded correctly when I called a method with incorrect arguments.

      Greg

      posted in Developers' Forum
      M
      MSP_Greg
    • RE: Collaborate on develop an extension or two?

      @mingteck said:

      simple acoustical modelling

      It depends on what you mean by simple. Using standard formulas based on volume and surface area by absorption is one thing, much past that and the calc time might be a bit long...

      posted in Developers' Forum
      M
      MSP_Greg
    • RE: No output text on Windows 7 system command

      Jiva,

      It's complicated. I started using Ruby years ago with SketchUp. Been away from SketchUp for while, but I'm still using Ruby.

      As I recall, the files get split into two locations, you have to edit the SketchUp.exe file, etc.

      I've also been building Ruby for quite a while, so the files I used were my own and built with current compilers & toolchains. With SU 2017, it can only run with Ruby 2.3 due to the changes that occurred in Ruby 2.4.

      There may be a publicly available build of Ruby 2.3 in the (hopefully near) future...

      posted in Developers' Forum
      M
      MSP_Greg
    • RE: No output text on Windows 7 system command

      The problem is the ruby build currently included in SU 2017. Not sure why output varies by Windows version.

      If one replaces it with a different build, command output will appear in the console.

      posted in Developers' Forum
      M
      MSP_Greg
    • RE: Get mac address in ruby

      Over in that other place, there's a thread addressing some similar questions for OSX and Windows.

      Re Windows, since Ruby backticks don't work as expected, trying to grab return text from an external command is messy. In the other place, I think Dan posted code using cmd redirection to a file, which will work.

      If you want a Windows MAC address and can assume a version of SU with the Ruby std-lib included, I posted a WIN32OLE example here

      posted in Developers' Forum
      M
      MSP_Greg
    • RE: Module-class

      Mario,

      This might help (I reformatted your code a bit), see the last couple of lines --

      
      # require 'sketchup.rb'   # why?  not needed for this code
      module McF3D
        class McF3DTools 
          def initialize
            @mod = Sketchup.active_model  # Open model
            @ent = @mod.entities          # All entities in model
            @sel = @mod.selection         # Current selection
          end
          def perceOuv
            unless @sel[0].is_a?(Sketchup;;ComponentInstance) &&
                @sel[0].definition.behavior.cuts_opening?
              UI.messagebox "Sélectionnez un composant F3D !"
            end  
          end 
        end # class McF3DTools
      end # module McF3D
      obj = McF3D;;McF3DTools.new()
      obj.perceOuv()
       
      

      The topic of modules & classes in programming is very complex. Conversely, what most people writing a SketchUp extension need to do is a very small subset of that topic.

      HTH,

      Greg

      SUMD SketchUp Misc Docs

      posted in Developers' Forum
      M
      MSP_Greg
    • RE: Module-class

      Mario,

      Glad that helped.

      @mariocha said:

      is the def Initialize a must ?

      Technically, no. But, if there's no need for it, one might ask the question 'should this be a module?' The answer would vary amongst programmers, and isn't dependent on that single criteria.

      [EDIT] I should add that when you create a class, it is a Ruby Class object, which has a :new method, which calls initialize if it exists. Just in case you were wondering...

      Greg

      SUMD SketchUp Misc Docs

      posted in Developers' Forum
      M
      MSP_Greg
    • RE: UI.inputbox with Web Dialog

      Nathan,

      Simply put, the best solution is to have your program flow based on callbacks from the WebDialog. This often creates problems for people, as the UI.inputbox is blocking. So the code is something like this:

      
      def start_method
        # some code to initialize and load inputbox
        UI.inputbox(*args)
        # more code for operation
      end
      
      

      The above is very linear and not easily changed to an event driven style. Better to start with something like:

      
      def start_method
        # some code to initialize and load inputbox
        UI.inputbox(*args1)
        ui_input_done(args2)
      end
      
      def ui_input_done(*args2)
        # more code for operation
      end
      

      Then, if you decide a WebDialog is needed:

      
      def start_method
        @dlg = UI;;WebDialog.new()
        # load @dlg html, etc
        @dlg.add_action_callback { |dlg, ret|
          # gather data from dlg
          ui_input_done(*args2)
        }
        @dlg.show()
      end
      
      

      To really give the user a good UI experience, one has to write javascript for the WebDialog.

      Greg

      [anchor="1" goto="http://msp-greg.github.io/su_info/index.html":17i7mw7a]GitHub.io SketchUp Misc Docs[/anchor:17i7mw7a]

      posted in Developers' Forum
      M
      MSP_Greg
    • RE: Linear Algebra & Analytic Geometry

      @bomastudio said:

      Hi Guys, I have an agony-problem with a 3D rotation.

      The transform that TIG suggested (rotation) works for your need. The docs on transformations aren’t very clear, especially for people who aren’t familiar with 3D transforms or linear algebra. They’re also a little quirky, as the trans.to_a method returns a matrix that is the transpose of what I would expect. FWIW, I had a lot of linear algebra (long time ago)...

      Anyway, the rotation method returns a transformation based on a rotation in a plane, which is defined by the ‘axis’ parameter, which should be the normal to the plane of rotation.

      If the start and end vectors are parallel, they do not define a unique plane, hence, both my original ‘linear algebra’ algorithm and the rotation method fail. The code below accounts for that –

      Greg

      module SUMath
        def self.transVector2Vector(vStart, vEnd, pt = nil)
          ptRot = pt || [0,0,0]
      
          if vStart.samedirection?(vEnd)
            # return identity transformation, vectors are in the same direction
            Geom;;Transformation.new 
          elsif vStart.parallel?(vEnd)
            #return 180 transformation, vStart and vEnd in opposite direction
            Geom;;Transformation.axes(ptRot, [-1,0,0], [0,-1,0], [0,0,-1] )
          else
            # return rotation transform based on vStart and vEnd
            # vCross is normal to plane of rotation
            vCross = vStart.cross(vEnd)
            ang = vStart.angle_between(vEnd)
            Geom;;Transformation.rotation(ptRot, vCross, ang)
          end
        end
      
        def self.rotateFace(face, vector_end, pt = nil)
          # for demo purposes, the next 2 statements chose an arbitrary face
          # if no face passed
          unless face
            entities = Sketchup.active_model.entities
            faces = entities.grep(Sketchup;;Face)
            face = faces[0]
          end
      
          face_normal = face.normal
          t = transVector2Vector(face_normal, vector_end, pt)
          entities.transform_entities(t, face)
      
          # below is just for a demo confirmation
          sd = face.normal.samedirection?(vector_end)
          sVEnd = "[#{vector_end.join(",")}]"
          puts "face.normal.samedirection?(#{sVEnd}) = #{sd}"
        end
      end
      # load module thru console
      # type SUMath.rotateFace(nil, [0,0,1]) into console with whatever vector
      # you want, it can be typed as often as you'd like.
      # As a demo, best done with one face in the model
      
      posted in Developers' Forum
      M
      MSP_Greg