sketchucation logo sketchucation
    • Login
    1. Home
    2. RichMorin
    3. Posts
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 41
    • Posts 104
    • Groups 1

    Posts

    Recent Best Controversial
    • "Automatic SketchUp" - review

      I just posted a blog entry about Matt Scarpino's new book:

      Automatic SketchUp: Creating 3-D Models in Ruby
      Matthew Scarpino
      Eclipse Engineering, 2010

      Executive Summary: Buy it.

      For details, see:

      "Automatic SketchUp: Creating 3-D Models in Ruby"
      http://www.cfcl.com/rdm/weblog/archives/001735.html

      -r

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • RE: Creating pulldown menus

      I'm not sure about the distinctions and terminology here, so:

      This is the dialog one gets by selecting a component and using the "Window > Component Options" menu bar item on a Mac.

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • Creating pulldown menus

      I need to create and populate a pulldown menu in the Component Options dialog. Making things somewhat more complicated, both the display text and the values for the options contain spaces and other oddball characters.

      I'd love to see some example code for doing this sort of thing. Suggestions?

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • SketchUp API consultants?

      I have occasional need for consulting help on the SketchUp API, above and beyond the help I can get on this forum and sketchupruby_at_googlegroups.com. I would be happy to hear about (or put up) a web page listing information on SketchUp API consultants.

      If you are (or know of) a consultant, please send me (rdm_at_cfcl.com) a note. Mark the information as private, if you don't want me to make it public.

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • RE: Support for data serialization formats

      I got the list of libraries I tried by typing $: in an irb session. I could try fiddling with the list to find a configuration that works, but that seems like it might be a snipe hunt...

      It would be really nice to hear from someone who has a working setup that uses the system's Ruby libraries on OSX...

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • Support for data serialization formats

      I have a bunch of configuration data that I want to serialize, write to a file, and have my plugin load.

      My initial plan was to use YAML for this, but I don't have a clear idea of how to get the YAML libraries to load (on a Mac Pro). I tried the following, but it causes SU to crash:

      
      lrs = '/Library/Ruby/Site'
      ulr = '/System/Library/Frameworks/' +
            'Ruby.framework/Versions/1.8/' +
            'usr/lib/ruby'
      [ "#{lrs}/1.8",
        "#{lrs}/1.8/powerpc-darwin9.0",
        "#{lrs}/1.8/universal-darwin9.0",
        "#{lrs}",
        "#{ulr}/1.8",
        "#{ulr}/1.8/powerpc-darwin9.0",
        "#{ulr}/1.8/universal-darwin9.0",
        "."
      ].each {|lib| $; << lib }
      
      require 'yaml'
      
      

      I'd be willing to recast my data as JSON, but I don't see a clear path there, either. One possible brute force solution would be to serialize the data as a Ruby statement and have the plugin eval it, but I'd really like to avoid that.

      Suggestions, anyone?

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • RE: How to detect duplicate edges?

      TIG-

      If you'll look at my code extract, you'll see that I'm already doing what you suggest. pph is a hash of "point pairs", indexed by the vertex positions (encoded as strings, to avoid object issues).

      However, my code isn't detecting any clashes, even though SU does (later) when it tries to save the model.

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • RE: How to detect duplicate edges?

      If I could print out the vertices for the edges SU is complaining about, I might be able to tell if it's a scale issue.

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • How to detect duplicate edges?

      I'm adding some edges to a model, in places where I really don't think it already has any. However, when I try to save the model, SU complains about duplicate edges, as:

      
      Results of Validity Check.
      
      CEdge (3749) and CEdge (3750) connect the same 2 vertices - fixed
      CEdge (4122) and CEdge (4123) connect the same 2 vertices - fixed
      
      

      I have tried a couple of hacks at discovering how I might be doing this. My current code looks like this:

      
      pph = {}
      loop, generating point pairs to define edges
        ...
        ppt = "#{ [ p1, p2 ].inspect }"
        puts "1; #{ppt}" if pph[ppt]
        pph[ppt] = true
      
        ppt = "#{ [ p2, p1 ].inspect }"
        puts "2; #{ppt}" if pph[ppt]
        pph[ppt] = true
      
        ents.add_line(p1, p2)
      end
      
      

      This doesn't print anything; suggestions, anyone?

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • RE: Importing and placing components

      Hmmm. I just tried a sleazy hack which seems to work:

      
          model.active_entities.add_instance(defn, tran)
          Sketchup.send_action('selectSelectionTool;')
      
      

      Selecting the Selection Tool seems to "wake up" SU, causing it to place and display the component without any user action.

      -r

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • RE: Importing and placing components

      Thanks, TIG! That almost works.

      If I just run the script, the component never shows up. However, if I click on the border of the main SU window (using the mouse), the component appears in the specified location. So, what do I have to do to mechanize the mouse click?

      -r

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • Importing and placing components

      I'm writing a Ruby script that (using AppleScript) causes SU to start up, open a file containing a "wall" (10' x 10' x 1' box), and import a component file. This all works, except that I don't know how to place the component against the wall.

      Clues?

      -r

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • RE: New API doc - typos and questions

      General

      Class and method names could be turned into links
      to the appropriate API page, for ease of navigation.

      Sentences should begin with a capital letter and end with
      a period (etc). Phrases should not.

      If a modifying phrase is used at the end of a sentence,
      a comma should be added for clarity:

      
        the name of the attribute dictionary  if successful
                                  dictionary,
      
      

      Specific

      http://code.google.com/apis/sketchup/docs/ourdoc/animation.html

      
      animation -> animation
      ruby      -> Ruby
      
      ... to pause, only certain ...
             pause;
      
      

      http://code.google.com/apis/sketchup/docs/ourdoc/appobserver.html

      
      ... a 2nd    model ...
            second
      
      Useful for if you need ...
      ---
      This is useful if you need ...
      
      

      http://code.google.com/apis/sketchup/docs/ourdoc/array.html

      
      The SketchUp Array class adds ...
      ---
      SketchUp adds ...
      
      Specifically, it contains methods ...
      ---
      Specifically, it adds methods ...
      
      ... arrays of 3     coordinate ...
                    three
      
      ... vector. it returns ...
                  It
      
      

      http://code.google.com/apis/sketchup/docs/ourdoc/attributedictionaries.html

      
      ... all of the attributes dictionaries.
                     attribute
      
      

      http://code.google.com/apis/sketchup/docs/ourdoc/attributedictionary.html

      Although the page does not discuss this, setting a
      custom attribute with a key that contains upper-case
      letters does not work.

      The page does not indicate how to set an attribute
      (eg, '=LenX+20') to be used as an expression.

      In the entry for AttributeDictionary.each, the "value"
      argument is being formatted as part of the description
      for the "key" argument.

      Ditto for AttributeDictionary.each_pair.

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • RE: Sub-component creation, decoration, etc?

      I already have a component with a lot of attributes, edges, faces, etc. My preference would be to collect these into assorted sub-components.

      It sounds like you are saying that this isn't a workable approach. So, I need to create a new component and sub-components, then copy the content of the first component into appropriate locations in it.

      I'm willing to try this, but I'm not at all sure how to proceed, what things I have to copy, etc. Can you provide a bit more detail and/or pointers to example code?

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • RE: Setting dynamic attributes to expressions?

      On a related note, if I use an attribute name which contains an upper-case letter, the attribute is created, but the value is empty.

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • Setting dynamic attributes to expressions?

      I've been playing a bit with setting dynamic attributes to expressions.
      I'm rather confused by the results. Here is a test plugin:

      
      # t1.rb - test code #1
      #
      require 'sketchup'
      
      def t1
        Sketchup.send_action('showRubyPanel;')
      
        sel   = Sketchup.active_model.selection
        cd    = sel[0].definition
        dict  = 'dynamic_attributes'
      
        { 'str' => 'abc',
          'num' => 42,
          'exp' => '=num+1'
        }.each {|k,v| cd.set_attribute(dict, k, v) }
      
        da = cd.attribute_dictionaries[dict]
        da.each {|k, v| puts "k='#{k}', v='#{v}'" }
      end
      
      UI.menu('PlugIns').add_item('T1') { t1 }
      
      

      When I select a component and run this plugin, the console prints:

      
      k='exp', v='=num+1'
      k='num', v='42'
      k='str', v='abc'
      
      

      If I then open up the Component Attributes window and re-select the component, I see my keys and values listed in the Custom section. However, this isn't exactly what I want.

      Specifically, I'd like exp to show up as 43 when the =fx button is selected and =num+1 if it is not. Instead, it shows up as =num+1 in both modes.

      However, if I then click on =fx, click in the exp text box, and hit return, I get the result I wanted. So, what do I have to do in the API to get this result?

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • Sub-component creation, decoration, etc?

      Let's say that the user has selected a single component and I have created edges in all of its faces where they intersect the X=5 plane. I would now like to create a pair of sub-components which contain everything to the left (right) of the intersection plane, adding assorted attributes.

      I'm not too worried about finding out which faces are on which side of the plane, but I am mystified by the way SU handles groups, components, etc. I see that I can create a group and turn it into a component, but I'm not sure how to add faces to the group (as opposed to creating new faces), add attributes, etc.

      Could someone provide a pointer to an example or a description of how to do this sort of thing?

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • RE: Creating edges where faces intersect a plane?

      Thanks; that was quite helpful!

      My only current question is how to handle situations where the plane intersects a vertex (rather than just an edge). This could happen, for example, if a square face had a triangular hole in the center and the plane just touched the top point of the triangle.

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • Creating edges where faces intersect a plane?

      I'm trying to write a tool that adds edges wherever a face in a component instance (@ci) intersects a specified X/Z or Y-Z axis "slicing plane".

      Anyway, the basic procedure I'm using is:

      Traverse a list of slicing planes: [1,0,0,-x1], [0,1,0,-y1], ...

      Traverse @ci.definition.entities:

      Bail out unless the entity is a face.

      Bail out unless plane passes through the face.

      Get the plane for the face.

      Call Geom.intersect_plane_plane().

      Bail out unless it returns a line.

      Call add_line().

      I'm currently stalled at the point where I call ents.add_line(). I've tried several variations:

      
      #     edge = ents.add_line(line)              # H0
      #     edge = ents.add_line(*line)             # H1
      #     edge = ents.add_line(line[0], line[0])  # H2
      #     edge = ents.add_line(line[0], line[1])  # H3
      
      

      Versions H0-H2 all give me the following output:

      
      p1 = 1, 0, 0, 2.4880390561432
      line = (-2.488039", 8.362949", 0")(0.0, -0.607450107570801, -0.794357832977193)
      Geom;;Point3d
      Geom;;Vector3d
      Error; #<ArgumentError; Cannot convert argument to Sketchup;;Point3d>
      
      

      I suspect that the error message is faulty and should refer to Geom::Point3d, rather than Sketchup::Point3d. If so, the problem is that SU isn't willing to accept a line in the (Point, Vector) format that Geom.intersect_plane_plane() returns.

      This is confirmed by Version H3, which doesn't complain because I'm actually handing in a pair of points (of course, the second point is bogus).

      Questions

      Is there an easier way to create these edges?

      Am I analyzing the nastygram correctly?

      How do I convert the line to an acceptable form?

      See http://pastie.org/729725 for a larger code snippet...

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • Evaluate a dynamic attribute in Ruby?

      Is it possible to evaluate a dynamic attribute from Ruby?
      For example, something like the following:

      
      foo     = '=box!LenY-1.125'
      foo_val = foo.value
      
      
      posted in Developers' Forum
      RichMorinR
      RichMorin
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 5 / 6