sketchucation logo sketchucation
    • Login
    1. Home
    2. danielbowring
    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 0
    • Topics 12
    • Posts 67
    • Groups 1

    Posts

    Recent Best Controversial
    • RE: [Question] DC Size and New Definitions

      I thought this might have something to do with situations that would require a new definition for varying size (LenX, LenY, LenZ) - but it seems that the COPIES method still deals with the situation (mostly) correctly. See the attached file for the example.

      Since the LenX and LenY modifies the definition of the component, you would expect there to be 3 variations of the component (at the three different sizes). In reality it generated 6 (each of the expected 3 has an identical pair, [i.e., each copy/instance has it's own definition]).


      dc_different_definition_copies.skp

      posted in Dynamic Components
      danielbowringD
      danielbowring
    • [Question] DC Size and New Definitions

      When making a Dynamic component, you'll often want to adjust the position (X, Y, Z) and size (LenX, LenY, LenZ). I'd always assumed this happened (at least for the value) at the instancelevel, but it appears for size this happens as the definition level for both formula and value.

      This means if you change the size of an instance, you can end up with an identical definition with one instance that just has a different transformation.

      To clarify, I can set the value and formula for any instances position to any value and it will effect only that instance. If I do the same for size, it copies to all instances, even though this should also only be a change in transformation. This means if I need to do a transformation that can involves size, I need to make a new definition for that instance.

      However, if I perform the same action using COPIES, I can get the desired result without any new definitions.

      So my question is: Why does positioning work the way I would expect it to, but sizing has a set of (seemingly arbitrary) special rules? Or am I misunderstanding something along the way?

      Attached is a sample file - try to get sample!small_a to be sample!small_size in all directions, and sample!big_a to be sample!small_size * sample!small_factor in all direction without making a new component definition. sample!implement_b shows an expected output (using COPIES, so there is only 1 definition required for it)


      dc_trans_sample.skp

      posted in Dynamic Components sketchup
      danielbowringD
      danielbowring
    • RE: Download RBZ file

      @dan rathbun said:

      Do you need to hex encode it?

      Unless you're sure there is no null character, you'll have to hex encode it or Sketchup will only store up to the first null character. Binary files will probably have plenty of nulls in them.

      Here's a sample of how SketchUp deals with the situation:
      ` nullstr = 'My Test ' + 0.chr + ' String'
      puts nullstr.inspect

      => "My Test \000 String"

      puts nullstr.length

      => 16

      Sketchup.active_model.set_attribute('test', 'nullstr', nullstr)
      nullstr2 = Sketchup.active_model.get_attribute('test', 'nullstr')
      puts nullstr2.inspect

      => "My Test "

      puts nullstr2.length

      => 8

      puts 'My Test '.length

      => 8`

      posted in Developers' Forum
      danielbowringD
      danielbowring
    • [Question] Manually Setting Instructor Content

      Is there anyway to set the instructor content aside from Tool.getInstructorContentDirectory? Trying to set it at arbitrary points in time.

      Thanks.

      posted in Developers' Forum
      danielbowringD
      danielbowring
    • RE: Retrieving parent definition

      The parent of every ComponentInstance
      Sketchup.active_model.definitions.map() {|e| e.instances }.flatten.map() {|e| e.parent}.uniq

      Every ComponentDefinition that has sub-components
      Sketchup.active_model.definitions.find_all() {|e| e.entities.find() {|e| e.class == Sketchup::ComponentInstance } }

      Every ComponentInstance that has sub-components
      Sketchup.active_model.definitions.find_all() {|e| e.entities.find() {|e| e.class == Sketchup::ComponentInstance } }.map() {|e| e.instances }.flatten

      To get the parent of a Entity, use entity.parent.

      posted in Developers' Forum
      danielbowringD
      danielbowring
    • [Utility] make-rbz

      Ruby-based tool to make RBZ files.
      Source and docs available at https://github.com/dbowring/make-rbz

      here's the contents of the README (converted to BBCode)

      @unknownuser said:

      make-rbz utility
      Make RBZ files for Sketchup
      (c) 2012 Daniel Bowring, released under GPL.

      Requirements

      • Ruby 1.8 (with rubyzip2) or Ruby 1.9 (with rubyzip)
      • Ruby gems

      Usage

      
      > $ make-rbz.rb -h
      > Usage ; ruby make-rbz.rb [OPTIONS]
      >     -v, --[no-]verbose               Run Verbosely
      >     -t, --[no-]strict                Run in strict mode
      >     -f, --[no-]force                 Force file overwrites
      >     -o, --outname=NAME               Set Output File Name
      >     -p, --outpath=PATH               Set Output File Path
      >     -s, --source=PATH                Set Source Directory Path
      >     -r, --read-stdin                 Set File name from STDIN
      >     -i, --ignore=PATTERNS            Ignore files matching glob pattern
      > 
      
      • -v, --[no]-verbose

        • Run in verbose mode
        • default OFF
        • This will print the name of every file added to the RBZ to STDOUT
      • -t, --[no-]strict

        • Run in strict mode

        • default ON

        • Catches common errors

          • Setting filename multiple times
          • Having a directory in the filename
      • -f, --[no-]force

        • Force overwriting the RBZ file if it already exists
        • default OFF
      • -o, --outname

        • Set the filename of the RBZ file
        • .rbz will be automatically added if excluded
        • defaults to the name of the active directory
      • -p, --outpath

        • Set the output directory for the RBZ file
        • Defaults to current directory, .
      • -s, --source

        • Set the source directory

        • defaults to src

        • Contents of this directory will be added to the RBZ file

        • Acts as the root of the RBZ file

          • that is, the directory itself will not be added to the RBZ file, but all of its contents will
      • -r, --read-stdin

        • Read the RBZ filename from STDIN

        • Example

          • git describe | ruby make-rbz.rb -r may produce v1.0.0.rbz
        • .rbz will be automatically added if excluded

      • -i, --ignore

        • Add given glob patterns (separated with a ,) to the ignore list

        • Files matching this pattern will not be added to the RBZ file

        • Example

          • ruby make-rbz.rb -i '.exe'* to exclude Windows executables
      posted in Developers' Forum
      danielbowringD
      danielbowring
    • RE: Migrating plugins to SketchUp 2013

      If changes are going to be made to the ruby package, I'd hope that:

      • Newer ruby version (1.9+)
      • Always use built-in package (same ruby on windows, mac)
      • Full library, not core (No external ruby installation needed)
      • rubygem support, including the ability to add new gems (possibly confirm with user first, eg Sketchup::Gem.install(name) shows a confirmation dialog to the user)
      • Better console (sketchup-developer-tools is headed in the right direction, but we still can't capture STDERR)
      posted in Developers' Forum
      danielbowringD
      danielbowring
    • RE: Reason why Sketchup 8 may crash

      Absolute confirm on this - went from about a minute to launch to a second or two.

      If you have python installed on your system, here's the script I used to remove the keys:
      Usage: (all values have reasonable defaults, so just executing the script is fine)

      
      $ clean_sketchup_reg.py -h
      usage; clean_sketchup_reg.py [-h] [--path PATH] [--root ROOT]
                                   [--pattern PATTERN] [--verbose VERBOSE]
      
      Sketchup Toolbar cleaner
      
      optional arguments;
        -h, --help         show this help message and exit
        --path PATH        registry path
        --root ROOT        root key
        --pattern PATTERN  remove pattern
        --verbose VERBOSE  verbosity
      
      

      Code:

      
      import _winreg as reg
      import re
      import sys
      import argparse
      
      def get_root_key(name);
          try;
              key = getattr(reg, name)
              return key
          except KeyError;
              pass
          raise ValueError('Root Key "%s" was not found' % name)
      
      class Cleaner(object);
          def __init__(self, root, path, pattern);
              self.root = reg.ConnectRegistry(None, root)
              self.set_path(path)
              self.pattern = pattern
      
          def set_path(self, path);
              current = self.root
              for p in path.split('/');
                  current = reg.OpenKey(current, p)
              self.active_path = current
      
          def clean(self, print_errors=False);
              removed = 0
              index = 0
              while True;
                  try;
                      key = reg.EnumKey(self.active_path, index)
                      if self.pattern.match(key);
                          try;
                              reg.DeleteKey(self.active_path, key)
                              removed += 1
                          except WindowsError, e;
                              index += 1
                              if print_errors;
                                  print 'Failed to remove', key, ';', e.message
                      else;
                          index += 1
                  except WindowsError, e;
                      return removed
      
      if __name__ == '__main__';
          parser = argparse.ArgumentParser(description='Sketchup Toolbar cleaner')
          parser.add_argument('--path', type=str, help='registry path', default='Software/Google/Sketchup8')
          parser.add_argument('--root', type=str, help='root key', default='HKEY_CURRENT_USER')
          parser.add_argument('--pattern', type=str, help='remove pattern', default='^ToolbarsUser(Custom)?\-Bar\d+$')
          parser.add_argument('--verbose', type=int, help='verbosity', default=1)
      
          args = parser.parse_args(sys.argv[1;])
          
          root = get_root_key(args.root)
          path = args.path
          try;
              pattern = re.compile(args.pattern)
          except Exception, e;
              raise ValueError('Invalid pattern ; ' + e.message)
      
          cleaner = Cleaner(root, path, pattern)
          result = cleaner.clean(args.verbose >= 2)
          if args.verbose >= 1;
              print 'removed', result, 'keys'
      
      

      Edit: Obligatory disclaimer, use at your own risk. I've tested it on my system and found no issues.

      You can also use this script to clean webdialog entries:

      
      clean_sketchup_reg.py --pattern "^WebDialog_.*$"
      
      
      posted in SketchUp Discussions
      danielbowringD
      danielbowring
    • RE: Upper Left Illustration in Component Options Menu

      Set the imageURL attribute of the dynamic component.

      @unknownuser said:

      The ImageURL attribute contains a URL to a GIF, JPG, or PNG file on the Internet that you want to appear in the Component Options dialog box. For example, if ImageURL is equal to http://mysite.com/myimage.gif, then 'myimage.gif' image would appear, instead of the SketchUp-generated thumbnail, inside the Component Options dialog box.

      posted in Dynamic Components
      danielbowringD
      danielbowring
    • RE: Model Operation blockform methods.

      @dan rathbun said:

      No not overlooking that.

      Of course it MIGHT be easier for the Trimblers to detect when a start_operation has been called a 2nd time, before the first has been committed, and ignore the 2nd.

      But I think the pitfall is that they will not find a consensus on whether they should ignore the next commit they "see" (assuming it's is paired with the 2nd start_operation,) and "hope" for getting the "outer" commit.

      I suspect that it will prove to be too confusing (if that's the correct word,) to attempt to compensate for poor programming practice.

      And that's the advantage of using code blocks - by definition they have a defined start and end πŸ˜„
      If you we're going for support, you'd have to assume that the scripter got it right - you shouldn't try to solve every problem they could cause. If an error is the result, that's because there was an error to begin with.

      posted in Developers' Forum
      danielbowringD
      danielbowring
    • RE: Model Operation blockform methods.

      @dan rathbun said:

      ....stuff...

      I think you're overlooking that I wrote this not to be implemented in ruby, but as something to be implemented in future Sketchup Versions.
      I too have tried to implement a "perfect" way of doing this in ruby, and the same pitfalls (of course) arise.

      posted in Developers' Forum
      danielbowringD
      danielbowring
    • RE: Model Operation blockform methods.

      Fairly late response, but here's my thoughts/responses:

      @dan rathbun said:

      here

      1. This is one advatage of a fallback system - the operation is aborted and then the error is allowed to propogate

      2. I believe the error should continue to be raised - an exception isn't (normally) what you're expecting, so execution should halt.

      3. My suggested nomenclature isn't set in stone. The reason I chose this is due to the duality of the object it may reference (the current operation for appending, or the (externally identical) interface for starting a new operation

      4. #abort aborts the operation as it is operating - erase! removes it after the fact. It should be noted erase can only be performed on the "most recent" operation (erasing any other doesn;t make sense)

      5. This I agree with - the handle would already be available (as the most recent operation, and as the argument to the block). The value returned should be the result of the block

      [6]) [which model to execute on]
      Ah, something I didn't think out very well - I think passing the active model is a good way, but I think the user should also be able to pass arguments, ie
      op.call(Sketchup.active_model, arg1, arg2, ...)
      to allow the user to perform operations on entities.
      But then again, when would you ever want it on anything other than the active model?

      @dan rathbun said:

      here

      Nesting means you don't have to worry if code your calling has its own operation. Some API operations, for example, will litter the undo stack.
      If you don't want to support this, you can just have calls to start a new operation do "nothing" except execute the block and return the value - the downside to this is you lose the ability to abort (with rollback).

      @dan rathbun said:

      here

      #erase! would only be applicable to the most recent (ie, top of the stack). Anything else would throw an error.
      The "code fantasy" is just that - you wouldn't nest operations "directly" like that - Imagine the operation is a method, the code becomes
      def root() #... child() #... end def child() #... end
      You can simulate this behaviour using clever transparency flags, or by ignoring the child operation (as noted before, with its disadvantage)

      @thomthom said:

      However I've also had tools where start and commit happens in different Tool events - block operations would not work there.

      Operations over different tool events? I was under the impression you had to finish your operation before control returned to sketchup (not that I ever tested, I have just assumed)
      Given this anyway, you could just keep "appending" to the previous operation by keeping its instance around (see Equiv. code in the description document) (or since its within the lifetime of the tool, even just using model.last_operation)

      posted in Developers' Forum
      danielbowringD
      danielbowring
    • RE: [Code] Print the transformation matrix
      
      def inspect_transformation(t)
          ta = t.to_a
          return (0...4).collect() {|i|
              ta[i*4, 4].join(', ')
          }.join("\n")
      end
      
      
      
      >>> point = Geom;;Point3d.new 11,22,33
      >>> tdd = Geom;;Transformation.new pointdd
      >>> puts inspect_transformation(tdd)
      1.0, 0.0, 0.0, 0.0
      0.0, 1.0, 0.0, 0.0
      0.0, 0.0, 1.0, 0.0
      11.0, 22.0, 33.0, 1.0
      
      

      Edit: And if you like things to line up:

      
      def inspect_transformation_adv(t, args={})
          format = "%.#{args[;places] || 3}f"
          ta = t.to_a.map() {|i|
              format%[i]
          }
          maxlength = ta.max() {|i, j| i.length <=> j.length }.length
          ta = ta.map() {|i|
              i.ljust(maxlength)
          }
          return (0...4).collect() {|i|
              ta[i*4, 4].join(args[;separator] || ', ')
          }.join("\n")
      end
      
      
      
      >>> point = Geom;;Point3d.new 11,22,33
      >>> tdd = Geom;;Transformation.new pointdd
      >>> puts inspect_transformation_adv(tdd)
      1.000 , 0.000 , 0.000 , 0.000 
      0.000 , 1.000 , 0.000 , 0.000 
      0.000 , 0.000 , 1.000 , 0.000 
      11.000, 22.000, 33.000, 1.000 
      
      

      Edit: although that's not the orientation you use

      posted in Developers' Forum
      danielbowringD
      danielbowring
    • RE: [Code] Print the transformation matrix

      Here's one in your format, although you should probably use one of the ones above (More info here)

      
      def inspect_transformation_adv(t, args={})
          format = "%.#{args[;places] || 3}f"
          ta = t.to_a.map() {|i|
              format%[i]
          }
          maxlength = ta.max() {|i, j| i.length <=> j.length }.length
          ta = ta.map() {|i|
              i.ljust(maxlength)
          }
          return (0...4).map() {|i|
              (0...4).map() {|j|
                  ta[j*4+i]
              }.join(args[;separator] || ', ')
          }.join("\n")
      end
      
      
      >>> point = Geom;;Point3d.new 11,22,33
      >>> tdd = Geom;;Transformation.new pointdd
      >>> puts inspect_transformation_adv(tdd)
      1.000 , 0.000 , 0.000 , 11.000
      0.000 , 1.000 , 0.000 , 22.000
      0.000 , 0.000 , 1.000 , 33.000
      0.000 , 0.000 , 0.000 , 1.000 
      >>> puts inspect_transformation_adv(t, {;separator => ' '})
      1.000  0.000  0.000  11.000
      0.000  1.000  0.000  22.000
      0.000  0.000  1.000  33.000
      0.000  0.000  0.000  1.000 
      
      
      posted in Developers' Forum
      danielbowringD
      danielbowring
    • RE: Capturing $sterr output

      @unknownuser said:

      In pas trials, I noticed that the SU error message (whether for syntax at load time or at run-time) are not handled by the console Ruby object, but send directly to the console at C level.

      @jim said:

      I can't get this to work now. I know it used to work, and had used it daily. Maybe the latest version of SketchUp changed somehow?

      @unknownuser said:

      It would nice if we could redirect all messages toward a known output stream.
      ...
      Maybe we should ask the SU team

      😐
      I'd assume then that we are unable to capture it, as irritating as that is.

      Thanks all πŸ˜„

      posted in Developers' Forum
      danielbowringD
      danielbowring
    • Capturing $sterr output

      Hey, wondering if Sketchup does anything special with $stderr?

      I need to redirect $stdout and $stderr to another stream, and it works fine for $stdout but for whatever reason what you would imagine is going to $stderr is going to the ruby console regardless of the value of $stderr.

      For example, if I overwrite $stderr, errors thrown in scripts will not be written to it, but instead will still appear in the ruby console.

      Thoughts?

      btw, here's a sample of what I'm using:

      
      class Sample
          def write(str)
              puts "stderr got " + str
          end
      end
      # don't worry, in the actual code I maintain the original Sketchup;;Console instance.
      $stderr = Sample.new() 
      
      
      posted in Developers' Forum
      danielbowringD
      danielbowring
    • [Help] Straight Skeleton Implementation

      Hey, I'm looking at making a straight skeleton implementation for Sketchup, similar to the one shown here.
      Anybody know of anything similar already existing that I can have a look at (sketchup/ruby specific or not) or any ideas on how to detect the correct order of events?

      Thanks in advance.

      posted in Developers' Forum
      danielbowringD
      danielbowring
    • RE: How can I create a 1 meter square plane in Ruby?

      Sketchup uses inches, but provides methods so you can use any measure you like -> http://code.google.com/apis/sketchup/docs/ourdoc/numeric.html

      
      val = 1.m # 1 meter
      pt1 = [0,0,0]
      pt2 = [val,0,0]
      pt3 = [val,val,0]
      pt4 = [0,val,0]
      
      my_face = entities.add_face [pt1, pt2, pt3, pt4]
      
      
      posted in Developers' Forum
      danielbowringD
      danielbowring
    • RE: Dynamic Components, 7.4cm in the negative X

      Attached is the file.

      Sorry for the slow response πŸ˜›

      Edit: Just remade the model from scratch and got the same issue.


      sketchup_odd.skp

      posted in SketchUp Discussions
      danielbowringD
      danielbowring
    • Dynamic Components, 7.4cm in the negative X

      I'll start with a video example - http://www.youtube.com/watch?v=ncGl_c505Oo

      This happens to me every so often when working with dynamic components. When I try to set the position through the attributes window, they jump to a different location.

      I've only checked the distance this time, but in this case its always 74mm. Any clues on whats going on and/or how to fix it?

      Thanks in advance.

      Edit: Running on Windows XP, Sketchup 8.0.4811. I know I've posted questions recently about DC's and ruby, but this is unrelated to that (and is on a different machine)

      posted in SketchUp Discussions sketchup
      danielbowringD
      danielbowring
    • 1 / 1