sketchucation logo sketchucation
    • Login
    1. Home
    2. Dan Rathbun
    3. Posts
    πŸ›£οΈ Road Profile Builder | Generate roads, curbs and pavements easily Download
    Offline
    • Profile
    • Following 0
    • Followers 1
    • Topics 92
    • Posts 4,903
    • Groups 2

    Posts

    Recent Best Controversial
    • RE: Ruby scripted Dynamic Attributes reporting Issues

      @jh said:

      ... I dont get it why I cannot get the lenx, leny and leny to report in any
      Ruby- driven Report-Script I tried, until some User-Interaction with the
      Component-Options has been made, ...

      The default values are stored in the DC definition's "dynamic_attributes" dictionary and the DC instance just uses the defaults until the user changes them. When they are different than the default, the DC code will create instance specific attributes in the instance's "dynamic_attributes" dictionary.

      So the "rule of thumb" for Ruby coding DCs is to always first check the instance's "dynamic_attributes" dictionary, then check the definition's "dynamic_attributes" dictionary for dynamic attribute values.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Send action for DC Components options window?

      @pixero said:

      Is there a way of activating the Dynamic Component Options window through ruby?

      Yes and sample code is given here ...
      https://forums.sketchup.com/t/close-component-option-component-attribute-windows-using-ruby-script/83784/6

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Default Open Folder

      ❗
      This was written in 2012 for SketchUp v8 when Windows 7 was current. Please do not PM me in 2019 and tell me it does not work for current SketchUp versions. Things change as OSes and applications are revised.
      ❗

      Hold up a min! I Found a workaround to force SketchUp to use Windows MRU paths...

      ...[ drumroll ]...

      1) Open a File Explorer and create a "dummy" folder "C:/dummy"

      2) Open SketchUp.. goto "Preferences" > "Files" panel.

      Click the browse Folder button and choose this empty folder.
      Your Models path should say: "**C:\dummy**"

      3) Close SketchUp.

      4) Delete the "C:\dummy" folder.

      5) Restart SketchUp. It will now use MS Windows saved MRU paths for "*.skp" filetype.

      .. No custom button or menuitem needed.

      πŸ˜„

      ❗
      This was written in 2012 for SketchUp v8 when Windows 7 was current. Please do not PM me in 2019 and tell me it does not work for current SketchUp versions. Things change as OSes and applications are revised.
      ❗

      posted in Plugins
      Dan RathbunD
      Dan Rathbun
    • RE: Default Open Folder

      ❗
      This was written in 2012 for SketchUp v8 when Windows 7 was current. Please do not PM me in 2019 and tell me it does not work for current SketchUp versions. Things change as OSes and applications are revised.
      ❗

      The trick is to let MS Windows MRU filetypes handle what folder will be opened to select a file (of the extension asked for.)

      So you'll have to make your own toolbar button (or assign a hotkey to,) the following command:

      Sketchup.open_file UI.openpanel('*.skp')

      Windows itself will search it's own MRU list that it maintains (no matter what application is or was in use,) when that filetype was last saved. (MRU is an acronym for Most Recently Used.) If Windows has not yet logged a particular filetype, it's likely it will open either in "My Documents" or in the "Desktop" folder. Once a non-cancelled save has occured, an attribute with a path value, will be written into Windows MRU key.

      Subsequent calls using the MS Common Filesave and Fileopen dialogs, (which UI.openpanel and UI.savepanel uses,) with just the filetype, will use the paths stored in the MRU key attributes.

      πŸ’­

      ❗
      This was written in 2012 for SketchUp v8 when Windows 7 was current. Please do not PM me in 2019 and tell me it does not work for current SketchUp versions. Things change as OSes and applications are revised.
      ❗

      posted in Plugins
      Dan RathbunD
      Dan Rathbun
    • RE: Converting Su8 ruby 1.86 to Ruby 2

      Very unlikley. Trimble had to compile their own build of Ruby 2.0.0 for SU2014..2016 which had major issues with Unicode character support under Windows. They had to do patching and backporting themselves. The result is fondly called "FrankenRuby" by the SketchUp extensibility team.

      The old versions of SketchUp 2013 (and older) are looking for different entry points in the Ruby interpreter DLL than are used in the Ruby 2+ versions, so you cannot just replace the DLL.

      If your use of SketchUp is still Hobby as your profile suggests, then you can still download SU2016 Make or SU2017 Make. They use Ruby 2.0.0 and 2.2.4 respectively.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Applying color to circles?

      In order to see colored materials for faces, the rendering options (style) must be set to either "shaded" or "shaded with textures". See the RenderingOptions class:
      http://ruby.sketchup.com/Sketchup/RenderingOptions.html

      IF you are painting the circle's edges, then in order to see the edges colored, the EdgeColorMode by be set to "ByMaterial" rather than "AllTheSame" (black).

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: LD_LIBRARY_PATH ... call executables and dynamic libraries

      ENV["LD_LIBRARY_PATH"] is for standalone Ruby. I'm surprised if it works at all in embedded Ruby.
      Same for Open3. I've heard of nothing but problems with it under SketchUp embedded Ruby.

      Suggest you try to wrap Emp using the Ruby Fiddle library ...
      http://ruby-doc.org/stdlib-2.2.4/libdoc/fiddle/rdoc/Fiddle/Importer.html

      P.S. - Your code is hard to read on GitHub because your indents are being replaced with 8 spaced TABs. Ruby looks best with 2 space indents. Most code editors can replace TAB with space characters as you type, and you will not get these giants indents when you post code.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Potential Project

      I see at least 1 missing feature. The text label layer.
      (Imagine having to select all those text objects to change their layer?)

      Workaround is to create and change to a "Text" layer (named whatever you please) before creating the text.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: IFC and problem with rfa.

      @juju said:

      1: No direct Revit import. If you want to import Revit files you'll need to export from Revit to a format that SketchUp will import.

      • SketchUp User Guide: Using SketchUp Data with Other Modeling Programs or Tools

      @juju said:

      2: IFC export is possible from SketchUp Pro, not sure which was the earliest version (2016?)

      @unknownuser said:

      ](http://ruby.sketchup.com/Sketchup/Model.html#export-instance_method)":rm86pzh4]SketchUp Pro 2015+ added IFC export capability.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: SVG Toolbar Icons - Gradients Missing

      What about another editor like GIMP ?

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Detecting/selecting a temporary Drawing

      No one will attempt to even read you code until it is properly formatted within [ code ] ... [ /code ] tags.

      There is a button on the post edit toolbar to insert these tag sets, or highlight a bunch of text and click the button to wrap the text in these tags.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Socket.so sketchup 8 and 13

      Search this forum for discussions. This has been answered before ...

      http://sketchucation.com/forums/search.php?keywords=SKSocket&fid%5B0%5D=180

      ... which hits on ...

      http://sketchucation.com/forums/viewtopic.php?f=180&t=29836&p=271469&hilit=SKSocket#p271469

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Socket.so sketchup 8 and 13

      SketchUp Extension RBZ archive of Ruby 1.8.6 p287 Standard Library

      (Installs like any other SketchUp RBZ extension. Windows only. SketchUp versions 8 and 13 Only.)

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Trying to get a string

      @web said:

      That explains why I couldn't figure out how to do it.

      The real reason is because standard IO has been redirected to SketchUp's Ruby Console.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Small Green Box in scale tool

      @penpendrum said:

      I sorry if posted in a wrong forum
      can we just continue?

      I'll get a moderator to move the thread.

      @penpendrum said:

      i tried your advice but the codes written by the sketchup team. the thing is, The ruby scripts are incrypted written by sketchup team.

      The team examples are not encrypted.

      Link Preview Image
      SketchUp Extension Warehouse

      Your library of custom third-party extensions created to optimize your SketchUp workflow.

      favicon

      (extensions.sketchup.com)

      Link Preview Image
      SketchUp Extension Warehouse

      Your library of custom third-party extensions created to optimize your SketchUp workflow.

      favicon

      (extensions.sketchup.com)

      Link Preview Image
      SketchUp Extension Warehouse

      Your library of custom third-party extensions created to optimize your SketchUp workflow.

      favicon

      (extensions.sketchup.com)

      Link Preview Image
      SketchUp Extension Warehouse

      Your library of custom third-party extensions created to optimize your SketchUp workflow.

      favicon

      (extensions.sketchup.com)

      Link Preview Image
      SketchUp Extension Warehouse

      Your library of custom third-party extensions created to optimize your SketchUp workflow.

      favicon

      (extensions.sketchup.com)

      Link Preview Image
      SketchUp Extension Warehouse

      Your library of custom third-party extensions created to optimize your SketchUp workflow.

      favicon

      (extensions.sketchup.com)

      Link Preview Image
      SketchUp Extension Warehouse

      Your library of custom third-party extensions created to optimize your SketchUp workflow.

      favicon

      (extensions.sketchup.com)

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Small Green Box in scale tool

      You are in the wrong forum. (This is a specific project forum which is really a dead project.)

      Writing tools in SketchUp Ruby would mean you have to draw these kinds of boxes yourself.
      (Meaning, the native scale tool is not exposed to the Ruby API. So you would need to write a clone.)
      Search the main Developers forum for Ruby tools. Or read the examples that the SketchUp Team has in the Extension Warehouse.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Animation SUalive extension. May you test beta version?

      @jumpjack said:

      A double click on a .ydprj file would be much more comfortable.

      As far as I know, there is no way to implement a double-click for a specific extension.

      The ARGV array is empty after SketchUp loads. If we were running a system Ruby process (inside of one embedded in an application's process,) then all the command line parameters would be stuffed into the ARGV array, and an extension might be able to process the parameters.

      Link Preview Image
      Class: ARGF (Ruby 2.0.0)

      Class : ARGF - Ruby 2.0.0

      favicon

      (ruby-doc.org)

      BUT, ... the SketchUp development team decided NOT to pass SketchUp.exe's startup parameters into it's Ruby sub-process.


      There might be a kind of workaround. If a utility program or script could be associated with a double-click on a .ydprj file, and a system environment variable set to hold the path to the .ydprj file, then start SketchUp,... if the extension loads and checks the ENV hash for a value in a "YDPRJ" variable, ... said extension would be able to act upon it.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • [code] Calculate volume on manifold surface without grouping

      The question has been often raised on how to get the volume of manifold surface without temporarily grouping and then exploding it.

      With the release of SU2017 things got more difficult because the old references before the group and explode are no longer valid. (This happens because of persistant_id implementations in the SketchUp Core.)


      @TIG pointed me toward an old thread on SketchUcation (hiding in the "Plugins" forum) in which …
      @AdamB proposed a totally mathematical solution, without a temporary group.

      Following is my rendition of AdamB's "no temporary group" solution.

      Mine does not modify API class Geom::Point3d, but converts to an Array which already has a #dot method.

      Mine also uses #grep which is very fast when comparing class identity, ... instead of calling #is_a? on each and every object in the geometry collection on the Ruby-side, during each iteration.

      
      # calculate_volume(geometry)
      # Calculate volume on a set of faces without a temporary group.
      #
      # Based on an old SCF topic thread post by AdamB;
      # http://sketchucation.com/forums/viewtopic.php?p=14598#p14598
      #
      # @param geometry [Array<Drawingelement>] Array of collected geometry references.
      # @return [Float] the computed volume if successful, 0.0 if not.
      def calculate_volume(geometry)
        geometry.grep(Sketchup;;Face).map {|f|
          (2 * f.area * (f.vertices[0].position.to_a.dot(f.normal))) / 6      
        }.reduce(;+)
      rescue => e
        puts e.inspect
        return 0.0
      end
      
      

      If you are still using Ruby 1.8, you'll need to replace .reduce(:+) with .inject {|sum,n| sum+n } in the code above, like so ...

      
      # calculate_volume(geometry)
      # Calculate volume on a set of faces without a temporary group.
      #
      # Based on an old SCF topic thread post by AdamB;
      # http://sketchucation.com/forums/viewtopic.php?p=14598#p14598
      #
      # @param geometry [Array<Drawingelement>] Array of collected geometry references.
      # @return [Float] the computed volume if successful, 0.0 if not.
      def calculate_volume(geometry)
        geometry.grep(Sketchup;;Face).map {|f|
          (2 * f.area * (f.vertices[0].position.to_a.dot(f.normal))) / 6      
        }.inject {|sum,n| sum+n }
      rescue => e
        puts e.inspect
        return 0.0
      end
      
      

      Bonus method for a volume display string in model units:
      See: [code] format volume in model units

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • [code] format volume in model units

      Related from thread: Re: [Plugin] VolumeCalculator v1.8


      Scenario: Given a numeric value of cubic inches, … get a formatted string of volume in model units.

      Note: Also discussing this at the SketchUp forums:
      https://forums.sketchup.com/t/code-format-volume-in-model-units/58562


      VERSION 3
      Adds "hideunit" boolean argument to handle the "SuppressUnitsDisplay" switch.

      
      # format_volume_in_model_units( volume, spacing, precision )
      #
      # @param volume [Numeric] The volume in cubic inches.
      # @param hideunit [Boolean] Whether to hide the unit symbols, or not.
      #   Defaults to the current model units "SuppressUnitsDisplay" switch.
      # @param spacing [Integer] The spaces before unit symbol. (Default=0)
      # @param precision [Integer] The numbers shown after decimal point.
      #   Defaults to the current model units precision (Range 0..6). Allows higher.
      # @return [String] The volume in cubic model units.
      def format_volume_in_model_units(
        volume,
        hideunit = Sketchup;;active_model.options['UnitsOptions']['SuppressUnitsDisplay'],
        spacing  = 0,
        precision = Sketchup;;active_model.options['UnitsOptions']['LengthPrecision']
      )
        inch_side = Math;;cbrt(volume)
        unit_side = Sketchup;;format_length(inch_side).to_f
        unit_vol  = unit_side**3
        if hideunit
          "%.#{precision}f" % unit_vol
        else
          i = Sketchup;;active_model.options['UnitsOptions']['LengthUnit']
          unit = ['in','ft','mm','cm','m'][i]
          "%.#{precision}f%s%sΒ³" % [ unit_vol, ' '*spacing, unit ]
        end
      end
      
      

      VERSION 2
      Barebones but might fail if the "SuppressUnitsDisplay" switch is true.

      
      # format_volume_in_model_units( volume, spacing, precision )
      #
      # @param volume [Numeric] The volume in cubic inches.
      # @param spacing [Integer] The spaces before unit symbol. (Default=0)
      # @param precision [Integer] The numbers shown after decimal point.
      #   Defaults to the current model units precision (Range 0..6). Allows higher.
      # @return [String] The volume in cubic model units.
      def format_volume_in_model_units(
        volume,
        spacing = 0,
        precision = Sketchup;;active_model.options['UnitsOptions']['LengthPrecision']
      )
        inch_side = Math;;cbrt(volume)
        unit_side = Sketchup;;format_length(inch_side).to_f
        unit_vol  = unit_side**3
        unit = Sketchup;;format_length(1.0).split(/~?\s*\d+\.?\d*/).last
        unit = 'in' if unit == '"'       
        unit = 'ft' if unit == "'"
        "%.#{precision}f%s%sΒ³" % [ unit_vol, ' '*spacing, unit ]
      end
      
      

      (Note, Version 1, previously posted in another thread, was a β€œcutsie” one-liner that failed.)

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Rendering_options, "back edges"

      @tboy said:

      Any updated info for this topic?

      YES. (5 years after this thread ...)

      In the SketchUp 2015 release, a new key was added to the RenderingOptions hash:

      The key is: "DrawBackEdges"

      See API documentation:
      http://ruby.sketchup.com/Sketchup/RenderingOptions.html

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • 1 / 1