sketchucation logo sketchucation
    • Login
    1. Home
    2. Dan Rathbun
    3. Posts
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update
    Offline
    • Profile
    • Following 0
    • Followers 1
    • Topics 92
    • Posts 4,904
    • Groups 2

    Posts

    Recent Best Controversial
    • RE: Ruby Sketchup Programmatic Union of Multiple items

      @hank said:

      I think this = needs to be changed to == ...

      Right? It changed set all group names rather than testing for equivalence.

      Correct. My bad. I've fixed it in the above example.

      @hank said:

      Anyway, grep with a more complex block seems like such a more efficient way of getting objects than getting an array ...

      grep always first creates an array result from the pattern argument.

      If you read the description of the method in the docs, it is quite clear there will be a two stage operation if a block is used with grep. The drawback is that the block will process ALL the members returned by the pattern, and push the result of the block into the output array. This will not be a problem if you are not going to use the output array any further. (Ie, the output array might be a series of valid group objects [that passed the name property check,] and false references for any group that did not.)

      The most important part of grep'ing with a class identifier, is that it is extremely fast at filtering out any other item of other classes (that are not subclasses.)
      More specifically, text comparison in Ruby is slow, whilst class identity comparison is fast.

      @hank said:

      ... then looping it to test for certain properties, then looping THAT array to test for others, and so on... which is what I felt like I was doing before.

      It is not a big deal to do that once as I did in the above example, using grep to get all groups, then filtering out only those with a certain name.

      But, yes you can do compound conditional tests within iterator blocks:

      
      name_prefix = "MY_TARGET_GROUPS"
      starts_with = /\A#{name_prefix}/
      grps.each {|g|
        if g.name =~ starts_with && g.material.name = "Green"
          # Do something with matching group instance
        else
          # Do something else
        end
      }
      
      
      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Ruby Sketchup Programmatic Union of Multiple items

      @hank said:

      If I could get grep to do a Group check AND a name check, I could iterate with an accurate index. Can grep be passed multiple patterns in one call?

      grep() can be passed a block.

      OR, you can call another of the iterative filter methods from Enumerable.

      And read the Ruby core docs when you wish to know what a method can and cannot do.
      http://ruby-doc.org/core-2.2.4/Enumerable.html
      Enumerable is a mixin library module that is mixed into most all collection classes.

      Would something like this also work ?

      
      grps = ent.grep(Sketchup::Group).find_all {|g| g.name == 'MY_TARGET_GROUPS' }
      # check here to be sure grps is not empty
      @union = grps.shift # slice the first member from grps array
      grps.each do |item|
        next unless item.valid?
        @union = @union.union(item)
      end
      # after the loop, refs in "grps" are all likely invalid;
      grps.clear
      
      

      P.S. - Ruby uses 2 space indents. There is NO coding language in the world that uses odd number of spaces in indents. (Really annoying.)

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Copying files using "ftools.rb" library

      @mgate said:

      require 'ftools.rb'
      > ...
      > folder		= File.dirname( __FILE__ )
      > resources	= "Resources"
      > resource_name= "XXXXXX AT Template.skp"
      > resource_file	= File.join(folder, resources, resource_name).tr("\\","/")
      > ...
      > 
      

      Problem here.

      The "Resources" folder is not in a sub-folder of the "Plugins" folder, nor in a sub-folder of YOUR extension sub-folder (which should be in a sub-folder of "Plugins".)

      This should return the correct path:
      resource_path = Sketchup.find_support_file("Resources")

      The above script certainly creates the copy in the correct folder but SU crashes afterwards.[/quote]
      Do you get a BugSplat!, or is a Windows Error Report (WER) generated (ie, check Event Viewer) ?

      Secondly, your rescue clauses are not telling you what error is happening. Do something like this:

      
      begin
        # file operation
      rescue => e
        puts e.inspect # or UI.messagebox(e.inspect)
      else # change to more meaningful message;
        puts "file operation success!"
      end
      
      

      Thirdly, we used to tell users to run SketchUp as administrator because all users needed read and write permissions on folder in the SketchUp application's program path. (This can cause file drag and drop to stop working for SketchUp.)
      The alternative is to set permissions for SketchUp and all it's program sub-folders to allow all users full permissions.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Copying files using "ftools.rb" library

      Is the above code within a method? Using local variablesin the TOPLEVEL_BINDING of a script will not work. (They are removed from memory when the script ends.) They should be instance or class variables instead.

      @mgate said:

      require 'ftools.rb'

      Where did "ftools.rb" come from ?

      @mgate said:

      I tried to use Fileutils.rb instead but there are lots of errors when open SU v.8

      Where did you get the "FileUtils.rb" file from ?

      I have a properly versioned Ruby 1.8.6-p287 standard Ruby library packaged as an RBZ extension for SketchUp v8..13 here:

      Link Preview Image
      Release SketchUp Extension RBZ archive of Ruby 1.8.6 p287 Standard Library · DanRathbun/sketchup-ruby186-stdlib-extension

      Ruby 1.8.6 p287 Standard Library packaged as a SketchUp extension. - Release SketchUp Extension RBZ archive of Ruby 1.8.6 p287 Standard Library · DanRathbun/sketchup-ruby186-stdlib-extension

      favicon

      GitHub (github.com)

      @mgate said:

      (I'm using "!AdditionalPluginFolders.rb") and below doesn't work:
      FileUtils.copy_file(resource_file, desti_file, preserve = false, dereference = true)

      Using this just adds complexity to the issue at hand. I'd suggest removing it from the equation. And fix the underlying issue.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: How to implement entity selection "wizard"

      ... and new for SketchUp vers 2016 and higher is a rectangular window picking method:
      http://ruby.sketchup.com/Sketchup/PickHelper.html#window_pick-instance_method

      You should download the SketchUp Team's Examples extension to see how Tools are written.
      http://extensions.sketchup.com/en/content/example-ruby-scripts

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Copying files using "ftools.rb" library

      (1) SU v8 uses Ruby 1.8.x which does not have Unicode character support on Windows. So any unicode characters in the pathnames could cause issues.

      (2) Symbolic links require being logged into an administrator account on newer Windows version (I believe v6.0 [Vista] and higher.)

      Lastly, you haven't said what kind of file you are copying. ?

      Is the file currently in use by SketchUp or your extension ?

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Ruby Sketchup Programmatic Union of Multiple items

      Yes other coders use dummy groups, but usually just push a cpoint into it, which can be easily removed later.

      Iterating collections. You cannot modify the same collection that you are iterating, ie changing the number of members. The iteration loses it's way, and members are either skipped, or referenced after they've been deleted. (We've said this so many time here, you'll likely get search hits on "iterate" etc.)
      So we usually make a copy of the collection, and iterate the copy. Also check each iterative reference for validity and loop next if it's no longer valid. Ie:
      next unless item.valid?

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Polygon Positioning Tool

      @medeek said:

      ... so I went back to my basic Windows Notepad, ...

      How do you know what encoding it saves the file it ?
      How do you know what type of line ending characters it uses ?

      These are things easily set with a real code editor.

      In addition code editors use color lexing to help you spell keywords correctly, match up the begins and ends of code blocks, etc. They also can use autocomplete features to help fillout method calls.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Polygon Positioning Tool

      That is okay (whitespace). I use Notepad++ which automatically replaces TAB with spaces. Each language can have a different indent spacing. (I'd think most editors can [or should] do this.)

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Polygon Positioning Tool

      Nat, use 2 space characters for indents. Tabs will not come out well in the forum code blocks.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Polygon Positioning Tool

      Just an FYI, the posted code's improper indentation is so annoying I will not bother to read nor try it out.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Copy a Group within a Component in Ruby, preserve location

      @hank said:

      **@Dan Rathbun:**I am just using the layer as an easy selector for the groups I want within the component.

      This is fine. Ie, using the layer property as a filter.

      @hank said:

      Do you recommend another way?

      I recommend rereading what I wrote. It was just general information (triggered by incorrect terminology you chose to use in an earlier post.)

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Dynamic Component DCFunctionsV1 within in Module

      @michaelwhksg said:

      Hi TIG. Sorry, will use the "code" tags in future.

      (1) A better idea is to edit your previous post, and insert the code tags.

      (2) The example is STILL wrong in that the check for method definition still uses the name atan2.

      (3) Yes, please use a unique method name, as your implementation of the atan2 method (specifically the parameter list) is not how the rest of the world would define it for use by ALL coders.

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Copy a Group within a Component in Ruby, preserve location

      @hank said:

      What I would like to do is go into each component instance and copy the group ...

      You cannot "go into an instance" really, when you double-click manually you are actually editing the definition's entities collection. Instances do not have their own entities collection. The model engine just renders "display" copies using the definition's entities.

      @hank said:

      on the "WALL_PRIMITIVES" layer

      You should come to understand that the originators of SketchUp chose a poor word "layers", as in SketchUp they are not geometric entity collections at all. Therefore no entities can be "ON" any layer.
      The objects that SketchUp calls layers are just display property sheets can can be shared by multiple entities, so that all those objects "associated" / "assigned to" a layer will share the same display behavior(s).

      @hank said:

      to the root model context (I think this would be called Sketchup.active_model).

      The object reference of the root entities collection, is returned by:
      Sketchup.active_model.entities

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Adding edges to manual selection following a snake pattern.

      phpBB engined forums uses BBcode.
      Please wrap program code in code tags like:

      [pre:3asokg6p][ code ]

      code here

      [ /code ][/pre:3asokg6p]There is a "code" button on the post edit toolbar (2nd row, 3rd button)


      Read help on BBcode: http://sketchucation.com/forums/faq.php?mode=bbcode

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Material Attributes

      @avariant said:

      Ok. Has this been reported to SU as an official "bug"? It would be very nice to get it fixed some day.

      for SketchUp 2017

      @unknownuser said:

      (https://help.sketchup.com/en/article/141303)":2kct16r6]
      Fixes/Improvements General

      SketchUp API Release Notes

      • (Mac) Fixed issue where SKM files lost attribute dictionaries when saved from ‘In Model’ to local library.
      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Subtraction with Intersect Method

      All Solid Tools boolean API methods are Pro only. (This used to be indicated in the docs.)

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Its time to discuss an important subject: Plugins/Extensions

      @tig said:

      I suggest you try remaking your ZIP using another [known to be compatible] exe - like 7-Zip or Windows's own 'Send to > ZIP' context-menu.

      This is the second time you've told him that some zip makers do not work well with SketchUp.

      What was he using to make his Zip files ?

      And are his rb files properly UTF-8 (without BOM) encoded ?

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Its time to discuss an important subject: Plugins/Extensions

      @tomot said:

      @Dan If you have ever written a script, which used to work prior to 2016 you will find that the extension policy set to Unrestricted does nothing to help with the installation process.

      What is so difficult about right-clicking the RB file, choosing "Send to Zip folder", and then renaming the zip archive to ".rbz" ???

      What is so difficult about using the internal SketchUp Preferences > "Install Extension..." browser panel, to select a RBZ archive to install ???

      posted in Developers' Forum
      Dan RathbunD
      Dan Rathbun
    • RE: Its time to discuss an important subject: Plugins/Extensions

      @tomot said:

      I have not been able to figure out why my scripts, are no longer able to be read by SketchUp 2016?

      What is your extension loading policy (in SU2016) set to ?
      Window > Preferences > Extensions Policy

      It may be set to "Identified Extensions Only". If so, you'll need to set it to "Unrestricted" if you do intend to run scripts that have not been processed through the Trimble Developer portal for a security certificate.

      @tomot said:

      My scripts don't follow the .RBZ format which is simply a rename of a .ZIP file extension ... previously a simple How to Text file, was all that was needed to install a plugin.

      Previously ... was 6 years ago! SketchUp 8M1 and earlier.

      @tomot said:

      Some Background: AutoCad 2.5 came on 6 x 3.5" 2.44 diskettes. ...

      Irrelevant. SketchUp is not going to be distro'd on diskettes, no matter how much you like your old floppy drive. 😉

      @tomot said:

      1. NO user wants to waste his or her time, learning a new way.
        In the real world many users don't have time to learn something unfamiliar it reduces their productivity on the job.

      Sorry. The "real world" and life in general is full of challenges. That is just the way things are. There is always something new to learn around the corner.

      You will just have to "man up" and "bite the bullet" learn the new way (which is 5 years old by now,) ... or risk being "left in the dust" of everyone else

      @tomot said:

      Hence I find it a bit heavy handed that a small group here, without the benefit of such history, keep making trivial changes that in reality don't benefit all past and present SketchUp users.

      WHO is "a small group here" ? These security changes in SketchUp 2016 (and higher) were made by Trimble, not us! (And the Trimble team members do not spend much time here, now that the official Discourse forums are up and running. They actually would often say that they did not "officially monitor" the SCF forums.)

      And yes the new security certificates put a cramp in the "quick and dirty" script workflow.

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