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 errors in Sketchup 2021

      @spring.freediver said:

      I was not able to find that it was deprecated.

      It was more than deprecated. It was removed in Ruby 2.0 and higher (which is SketchUp 2014 and up.)

      The CHANELOGs for the Ruby Core is at it's GitHub project repository.
      (But the logs are not that easy to read. They often create "Breaking Changes" synopsis in the NEWS files.)
      See: https://github.com/ruby/ruby/tree/master/doc

      @spring.freediver said:

      By the way, I was using http://ruby-doc.com/docs/ProgrammingRuby/ for Ruby documentation, and it still lists nitems as a method of the Array class.

      Can you recommend a better site for documentation of the version of Ruby Sketchup is now using?

      The ol' "Pick Axe" book you see online was written for Ruby 1.6 !
      (Even the first version of SketchUp that came with an API used Ruby version 1.8.0.)

      Use the Ruby core documentation for the proper version:
      https://ruby-doc.org/core-2.7.2/

      There is link at the top for the corresponding Standard Library docs that now also ships with SketchUp (since v2014.)

      Also I have an extensive Ruby Resources list at the official SketchUp forum.
      https://forums.sketchup.com/t/ruby-learning-resources-wikilists/22861/

      ~ regards ~

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Win32API is deprecated after Ruby 1.9.1

      This is not an error. It is a warning.

      Prior to Ruby 2.x, Win32API was a compiled .so file.

      Then they (the Ruby Core project) deprecated it and began (with Ruby 2.0 in SketchUp 2014 thru 2016) distributing Ruby with a " Win32API.rb" wrapper file that defined wrapper calls using the DL standard library.

      But later on (by Ruby 2.2.4 with SketchUp 2017 and higher,) even the DL standard library was deprecated, and the " Win32API.rb" wrapper file was rewritten to change the DL library calls into Fiddle library calls.

      So even now with Ruby on the latest SketchUp, we would still expect old Win32API method calls to be translated correctly into Fiddle library calls.

      The warning cannot be suppressed as it is stated at the top of the " Win32API.rb" wrapper file without condition. You will see it output to the console by the first extension that calls a require "Win32API".


      Okay, but there is always a chance things could have been broken as changes to the Fiddle library might change with Ruby version changes.

      The latest SketchUp 2021 is now up to Ruby version 2.7.2. SketchUp 2020 was using Ruby version 2.5.5.

      Did you see differences between loading under these 2 Ruby versions ?

      I would suggest using a Ruby Console opener like Eneroth's to see what other errors are output to the console. It is best when troubleshooting to switch off the extension so it does not load at startup, and then manually load it with the console open to see any other errors.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Ruby errors in Sketchup 2021

      Just a quickie to note that an alternative which does not create a new array object is:
      ary.count {|e| !e.nil? }

      Also, as the Enumerable library module is mixed into Array, you can easily test for nil members ...

      true if even 1 member is nil, false otherwise

      ary.any?(&:nil?)

      true if no nil members, false if even 1 is nil

      ary.none?(&:nil?)

      true if all members are nil, false if even 1 is not nil

      ary.all?(&:nil?)

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Win32API is deprecated after Ruby 1.9.1

      @dan rathbun said:

      The warning cannot be suppressed as it is stated at the top of the " Win32API.rb" wrapper file without condition.

      Actually (today) I myself decided to modify the "Win32API.rb" file in the Ruby library, and comment out that warning at the top of the file.

      To do this I had to start Notepad++ in Administrative mode because SketchUp has marked it's "Tools" folder files and all subfolder files as read only.

      @frankn said:

      I didn't check to see if there's a difference when loading different versions, just haven't had time and other than being annoying I don't see any problems in my plugin.

      I do not think that the "Win32API.rb" file has changed at all. If you do not see any issues, then likely there are none.

      The main takeaway here is that the "Win32API.rb" wrapper file is deprecated. This means such things could be (and are likely scheduled to be) removed in a future Ruby version. This would most likely happen in a major version release such as 3.0 which is now the stable active trunk.

      The current release is 3.0.2 and I've just now installed it and checked for the "Win32API.rb" wrapper file. It has been REMOVED from the Ruby standard library.

      So this means that coders will need to edit their code and either, use Fiddle calls directly, or copy the contents of the "Win32API.rb" file (minus the warning) into their own namespace module as a local class definition.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: How to set color for DIMENSION_TEXT

      @kimdv said:

      Hello everyone!
      How can I set the color of the stoke and background to be "white" or none?

      A Layout::LinearDimension object is a subclass of Layout::Entity, so it inherits the #style= setter method.

      Either create a new Layout::Style (or grab it's existing style via the #style getter,) and modify it. Then set it back upon the dimension object using the #style= setter.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: MAJ FollowMe. Every Sketchup user can use it.

      Plugin / Extension announcements belong in the "Plugins" subforum.

      You'll need to get admins to move all these announcements.

      posted in Plugins
      Dan RathbunD
      Dan Rathbun
    • RE: Delete and update add_note don't work

      Just tested Sketchup::Text#set_text on SU2020 and it (as Dezmo says) does not display the change until the view is redrawn. So Sketchup.active_model.active_view.invalidate is necessary to see the change.

      I'll open a documentation issue for this "quirk".

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Wrong distance and position of exploded dynamic component

      The result looks good.

      What were you expecting to be different ?

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: How can I use "createPopupMenu" to create a right click Menu

      @season_x said:

      I think Right - click menus are more important than toolbars and shortcut key.

      Doug Olivier (formerly a Trimble employee) is working on a popup button matrix called GhostMenu:

      There is a beta version available to test. https://app.ghost.menu/

      It uses a keyboard shortcut to popup the GhostMenu.

      (But I cobbled up a little script to insert a command for GhostMenu into the top of SketchUp's context menu.)

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Alternate API, Pioneers Wanted

      @jessejames said:

      I find the need to grab a group/comp by it's "bbox.center", "bbox.center_bottom", and "bbox.center_top" so important that i wrote a nice function to encapsulate all the calls required to retrieve these points. So maybe you would like to add this, maybe not. Let me know. It would be so nice to call obj.bounds.center('center'), obj.bounds.center('top'), or obj.bounds.center('bottom'), but that will have to wait.

      There is a plugin for this (that needs some language cleanup,) written by Sahi.
      It's called AxizComp.rb (Axis Components), see this thread (ther's some code snippets for other languages later in the thread.)
      http://forums.sketchucation.com/viewtopic.php?f=323&t=21635&hilit=axis#p181881


      EDIT: With the release of SketchUp 2020, grips on object bounding boxes are now native !
      https://help.sketchup.com/en/current-release-notes

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: How can I use "createPopupMenu" to create a right click Menu

      @season_x said:

      ... I want to create a right-click menu:

      What do you want to create a context menu for ?
      (There needs to be a context ... ie, something selected, or nothing selected, or a certain tool is active, etc.)

      Then you will wish to insert menu items onto the context menu. What kind of command(s) ?

      SketchUp's Ruby API already has this feature available, so you need to work WITH the API as it exposes SketchUp's native context menu handler.

      You cannot just brute force try to stomp over the native handler!

      * UI::add_context_menu_handler class method

      • UI::Command class
      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Inverse Selection - where is it?

      Invert Selection is now native for SketchUp 2019.2 and later.
      You'll find the command on the right-click context menu for the Select Tool.

      See https://help.sketchup.com/en/sketchup/older-release-notes#su19-m2-whats-new

      @unknownuser said:

      Invert Selection. Just like the title suggests, it's the small things that help your workflow! This new feature will allow you to select anything, then invert the selection of objects. This makes it simple to select items and then perform actions on their inverse. The keyboard shortcut for this will be: CTRL + SHIFT + I (Windows) or CMD + SHIFT + I (Mac).

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Webdialogs and Javascript void

      @martinrinehart said:

      Does void differ from return null?

      YES. (in the following, violet denotes javascript.)

      (1) return type: undefined and null are separate return types.
      ___http://msdn.microsoft.com/en-us/library/7wkd9z69(VS.85).aspx

      • void(whatever) always returns undefined* return( null ) obviously will return null (in this case.)A variable can have a null value, but not an undefined value, because undefined refers to the object, not it's value. You check undefined using quotes:
        %(#BF00BF)[if(typeof(var)=="undefined") //do something]
        You check null without quotes:
        %(#BF00BF)[if(var==null) //do something]
        The difference is subtle. Basically, if a symbol references a variable that has not been declared, or has been declared but never had a value assigned, then "undefined" is returned. If a symbol references a variable that has had any value (including null,) assigned to it, it will not return "undefined".
        But be careful! There's a gotcha (because of backward compatibility.)
        %(#BF00BF)[(object.prop==null)] will return true if the property has the value null or if the property does not exist! You can use in to be more specific:
        %(#BF00BF)[if ("prop" in object)] will return true if the property does exist.

      (2) Both are evaluation functions:

      • return( expression ) [called a Statement] Always returns the result (of whatever type,) that expression evaluates to.
        http://msdn.microsoft.com/en-us/library/22a685h9(VS.85).aspx
      • void( expression ) [called an Operator] Evaluates expression then always returns "undefined" (regardless of the result.) The expression is required or an argument error would be raised. The expression 0 is traditional, and comes from C language (where null and zero were interchangable; but in javascript, 0 is a number type, null is it's own type.)
        http://msdn.microsoft.com/en-us/library/e17c7cbe(VS.85).aspx
        The internal code might be represented as:
        %(#BF00BF)[function void( *expression* ) {] %(#F0F0F0)[___]%(#BF00BF)[eval( *expression* );] %(#F0F0F0)[___]%(#BF00BF)[return( undefined ); }]
        ___
      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Sketchup::model#import : Force "Use Image As" Image

      @alexms said:

      But, when I do like that, I'm depending on the last choice of Use image as the user's made in import dialog.

      You are correct there are no importer options for image file types exposed in the Ruby API.

      If you are still using SU2017 Make, then there is no way to change what the user's last setting was, whilst SketchUp is running. It is saved in the registry, and although SketchUp will immediately update the user's setting (if it changes,) SketchUp core will still use it's internal memory of the setting instead of checking the registry.
      This means if you attempt to tweak the registry whilst SketchUp is open, it will have no effect.

      @alexms said:

      Or should I make a full tool and use add_image ?

      This is likely your only option. I did post an example of dragging objects around within a tool at the SketchUp forums ... See links in this post:
      https://forums.sketchup.com/t/how-to-realize-the-drag-effect/125758/4

      Once the image is placed, you might try to push it's reference into the selection set alone and activate the ScaleTool.
      Sketchup.send_action("selectScaleTool:")

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Always face camera with View Observer - Would this work?

      A major drawback is that you'd be modifying the model entities with every change of the camera.

      Currently changing the camera position or even the active scene does not set the modified? flag.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Assigning DC attributes to nested components & groups

      DC attributes are set directly upon nested DC group instances.

      BUT, ... for component instances they are defined upon the definition along with a default value. If there are to be more than 1 instance of the DC and they differ, then the differing values are then set on the instance. (However the "smarts" of each DC attribute, ie, access, formula, label are only in the definition's DC dictionary.)

      If changing an instance's attribute(s) causes the definition's entities collection to change, then the DC engine will unique-ify the DC, by cloning the definition and making the instance the first instance of this new DC definition. (An example is when changing the DC so that more or less copies of a sub-component, like a stile are generated. This changes the DC definition's entities collection, so if there are more than 1 instance, the one needing a different number of stiles would need a new definition.)

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Using Shoes (ruby UI) in sketchup plugin

      @sminky said:

      Hi,
      Is there any way to use Shoes to make UI for a sketchup plugin?

      No. sorry. A special fork and compilation of the Shoes code would be required, afaik.
      I believe that no one has attempted it.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Component Axes

      FYI, You can change the insertion point insertion_point=.

      You can also apply a transform to the entire entities of the definition ...

      
      ctr = cdef.bounds.center # Center of untransformed bounds
      # Arrays are compatible with translational transformations;
      xform = [ctr.x, ctr.y, 0].vector_to(ORIGIN)
      cdef_ents = cdef.entities
      # Move all the entities so that the axis is in the bottom center;
      cdef_ents.transfrom_entities(xform, cdef_ents.to_a)
      
      
      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: How do I check if component name starts with a certain word?

      .

      Ruby 2.x+ (SketchUp 2014+)

      [String#start_with?](https://ruby-doc.org/core-2.0.0/String.html#method-i-start_with-3F)

      ie ...

      if e.definition.name.start_with?("MyComp")
      

      ... or ...

      if e.definition.name.start_with?("Door","Window")
      
      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Component definition has TWO names ???

      @didier bur said:

      Sketchup.active_model.name is NOT (always) the same as the SKP file name...

      Sketchup.active_model.name
      

      and

      Sketchup.active_model.description
      

      are used to set the name and description when you will be using the entire file as a component.

      Secondly, these 2 fields are used to set the name and description that will be displayed when using the file as a template.

      So it seems that someone who saved the file, renamed it using francais and resaved it under the old english filename.

      There are cases when the filename (minus extension) are used to set the component name. Importing an image is one case.

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