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

    Posts

    Recent Best Controversial
    • RE: How to import several models to designated positions

      Take a look at entities.add_instance:

      https://developers.google.com/sketchup/docs/ourdoc/entities#add_instance

      and the DefinitionList, especially DefinitionList.load and DefinitionList.load_from_url:

      https://developers.google.com/sketchup/docs/ourdoc/definitionlist

      --
      Karen

      posted in Developers' Forum
      K
      kwalkerman
    • Entities.intersect_with crash

      Hi - I'm having trouble with "entities.intersect_with"

      The code I'm using is:

      g.entities.intersect_with(false,g.transformation,g.entities,g.transformation,false,g.entities.to_a)
      

      where g is a group inside the Sketchup.active_model.entities collection.

      Most of the time my code progresses without issues, but sometimes it crashes and I can't figure out why.

      I can stop my code before this line and then manually intersect by selecting faces - without crashing SU. I have noticed that in cases where Sketchup crashes, when I manually intersect I end up with hidden lines on the intersected faces - as if the face is not planar. However, I can erase these lines without erasing the face.

      Any ideas?

      Thanks.

      --
      Karen

      posted in Developers' Forum
      K
      kwalkerman
    • RE: One Face that Should Be Two...

      @unknownuser said:

      ... would Sketchup.send_action("fixNonPlanarFaces:") do anything in this case?

      ... I should've saved the file with the messed up face to try it on!

      I ended up with something similar to TIG's suggestion,except that I found any vertices referenced more than two edges on the same face. Then I was able to re-create the faces using the original face's vertices.

      --
      Karen

      posted in Developers' Forum
      K
      kwalkerman
    • One Face that Should Be Two...

      Hi,

      I have code that takes loose geometry, groups it, intersects it and then does something with the pieces. Most of the time everything is groovy, but I'm having an issue I'm not sure how to resolve. In the image, you can see that the selected face is one face that "should" be two.The green faces should be two faces.

      I've tried intersecting entities, doing "edge.find_faces" on all the face's edges, but I haven't come up with a good solution yet (short of deleting the face and re-creating it, but that could cause other issues).

      Any ideas?

      Thanks!

      --
      karen

      posted in Developers' Forum
      K
      kwalkerman
    • RE: Retrive the tool selected before launching my plugin

      I think what you want to do is re-select the tool the user originally had selected when they activated your plugin. To do it:

      original_tool = Sketchup.active_model.tools.pop_tool
      
      myTool.activate
      
      # Now execute your code.  When you're finished, maybe in the tool's deactivate method;
      
      Sketchup.active_model.tools.push original_tool
      

      --
      Karen

      posted in Developers' Forum
      K
      kwalkerman
    • RE: Sketchup and ruby

      Depending on what you're trying to do, you might want to look at the SelectionObserver class. You can use a SelectionObserver to perform actions based on what is selected, regardless of what tool is currently being used.

      posted in Developers' Forum
      K
      kwalkerman
    • RE: Why is my Group deleted while trying to add entities to it?

      @tiktuk said:

      @thomthom said:

      I'm guessing it refer to line 58. I'm pretty sure it's because you make the containing group after you make the child entities. Refactor the code so you always create the container first - and then add the entities to the container.

      strut = create_strut edge, center, size frame_group.entities.add_group strut

      I think you are onto something there. I just noticed that I am creating an extra group in that line, that I don't want or need. create_strut is already returning a group and I have used add_group strut to add that group to my frame_group but while doing that I am creating another group.

      How do I add an existing entity (a group in this instance), to an existing group? I can't find any methods for that.

      I'm not aware of any way to do this directly. If it's a group you want to add you can say:

      new_group.entities.add_instance original_group.entities.parent
      

      (original_group.entities.parent will give you the original group's definition, so you add it like you're adding a component instance)

      as far as adding individual items to a group, you can do it this way, but it's a little iffy:

      entities_i_want_to_add = []   #array of entities you want to add to the new group
      new_group = entities.add_group entities_i_want_to_add
      

      then I guess you could find the definition of this new group and add it to whatever entities collection you want, then explode the original

      The most foolproof way to add entities to a group is to add the raw geometry using Entities.add_edges and Entities.add_face. You'd also need to copy the materials and any attributes you wanted to go along with them.

      posted in Developers' Forum
      K
      kwalkerman
    • RE: SketchUp API Wish List

      @pc0158 said:

      @kwalkerman said:

      *Allow me to selectively lock components - I'd like to be able to supply the user with a component they can move, rotate & copy, but can't edit the internal definition.

      Agree. For example, I have a sundial object that, once created, can be moved around via translation and still work find but will break if it is rotated on any axis. It would be nice to prevent users from rotating it, while permitting scaling and translation.

      Maybe this is possible with a DC (including some morphing when gross changes in latitude/longitude take place) but this is just a hobby with me; I'm not willing to shell out for the pro version.

      There are some things you can do with dynamic components. You can fix the rotation or the location, and restrict scaling. However, if the user can edit the component definition, they can still create problems.

      posted in Developers' Forum
      K
      kwalkerman
    • RE: Explode group, retrive all entities and recreate group

      "next unless" is ruby code - no Sketchup needed. TIG's code basically says "unless g is a Sketchup::Group, move on to the next item in each. It is functionally the same as the following, but reads a little cleaner:

      
      Sketchup.active_model.entities.each{|g|
        if g.is_a? Sketchup;;Group
          g.entities.each{|e|
            if g.is_a? Sketchup;;Group
              puts e
              # or whatever you want to do with 'e'
            end
          }
        end
      }
      
      
      posted in Developers' Forum
      K
      kwalkerman
    • RE: SketchUp API Wish List

      @thomthom said:

      @kwalkerman said:

      *Make it possible to explode components within Sketchup.active_model.start_operation and Sketchup.active_model.abort_operation tags... without crashing Sketchup

      Got an example of this? I've never experienced this.
      (Sure you don't have some observers attached that is misbehaving? Or that you are not holding on to stale entity references?)

      I have had this issue on various machines running both SU7 and SU8. After exploding a group, the program crashes on commit_operation. I am unable to reproduce it right this moment in the ruby console or webconsole, which is curious.

      posted in Developers' Forum
      K
      kwalkerman
    • RE: SketchUp API Wish List

      *Make it possible to explode components within Sketchup.active_model.start_operation and Sketchup.active_model.abort_operation tags... without crashing Sketchup

      *Allow me to selectively lock components - I'd like to be able to supply the user with a component they can move, rotate & copy, but can't edit the internal definition.

      posted in Developers' Forum
      K
      kwalkerman
    • RE: Detect User Access to Clipboard

      Thanks. The autohotkey option gets me the closest. Now I just need to find out if I can use AHK to detect all paste events, not just ctrl-v paste events...

      I am actually using the pasted text to create a ruby object unrelated and unconnected to a Sketchup Entity. I want the user to be able to simply paste whatever is on the clipboard into Sketchup, have a ruby script run and if the clipboard contains parsable text, I can create my ruby object. Another simpler, but less elegant way to do it is to have a large text field in a web dialog that the user can paste text to, and then run a script on that text.

      --
      Karen

      posted in Developers' Forum
      K
      kwalkerman
    • Detect User Access to Clipboard

      Hi,

      Is there any way within Sketchup to detect when the user has accessed the clip-board through CTRL-V or a paste event? I am trying to detect when a user may have copied and pasted text from another application into Sketchup. I'd like to be able to use a ruby script read the text and potentially do something with it.

      Thanks,

      --
      Karen

      posted in Developers' Forum
      K
      kwalkerman
    • RE: Mimic 'select' in custom tool

      Duh, brain fart - use onMButtonDown to detect user's selection of objects...

      posted in Developers' Forum
      K
      kwalkerman
    • Mimic 'select' in custom tool

      Hi,

      I am writing a script where I want the user to be able to select some entities, have code do something with those entities, then ask the user to select some more entities, have the user do something with those entities, and so-on.

      The best way to do this is by using a tool - have the user use the tool to select items, press a command to execute the ruby script, the tool will re-set itself and the user can select more items. However, I'm not sure how to have the user select within a custom tool.

      Thanks,

      --
      Karen

      posted in Developers' Forum
      K
      kwalkerman
    • RE: [Code] Change Axes of a Group

      OK, here is the solution for anyone who needs it in the future:

      
      # accepts either one or two arguments.  The first is always the group or component where the axes needs to be corrected
      # the second can be a parent group or component (something that has a transformation).  If nothing is passed in, the global
      # model x,y, and z axes will be used.  The parent attribute should be used any time there is a nested component.
      
      def change_axes_to_parent(*args)
      if args.length == 1
        g = args[0]
        p_t = Geom;;Transformation.new
      else
        g = args[0]
        p_t = args[1].transformation
      end
      t = g.transformation
      #p_t = parent.transformation
      if t.xaxis != p_t.xaxis || t.yaxis != p_t.yaxis || t.zaxis != p_t.zaxis
        o = t.origin
        # different axes, require that all components inside be rotated
        tran = Geom;;Transformation.axes o, t.xaxis,t.yaxis,t.zaxis
        t_o = Geom;;Transformation.new o
        if g.is_a? Sketchup;;Group
          ents = g.entities
        elsif g.is_a? Sketchup;;ComponentInstance
          ents = g.definition.entities
        end
        ents.transform_entities tran, ents.to_a
        ents.transform_entities t_o.inverse, ents.to_a
        g.transform! tran.inverse
        g.transform! o
      end
      end 
      
      
      
      posted in Developers' Forum
      K
      kwalkerman
    • RE: [Code] Change Axes of a Group

      Not quite sure how to do this. Can you give me any more details?

      Thanks.

      posted in Developers' Forum
      K
      kwalkerman
    • [Code] Change Axes of a Group

      Hi,

      I have a script that automatically creates groups out of existing elements. The only problem is that sometimes the axes don't match the global axes, and this is causing problems for me down the road. Is there any way to specify or change the axes of a group using ruby? I'd like to do it once when the group is created instead of having to deal with it forever down the road.

      Thanks,

      --
      Karen

      posted in Developers' Forum
      K
      kwalkerman
    • RE: Newbie to Sketchup / Ruby

      What about wrapping everything with "start_operation" and "commit_operation"

      (http://code.google.com/apis/sketchup/docs/ourdoc/model.html#start_operation)

      this can significantly improve execution time as the model is not trying to track all the changes as they are made, but only updates once, when "commit_operation" is called.

      --
      Karen

      posted in Developers' Forum
      K
      kwalkerman
    • RE: AutoHotKey shortcuts for the Ruby Console

      Hi Jim,

      This looks awesome. Sorry for the newbie question, but I can't figure out how to activate it. Where do I put the file? How do I start it from the ruby console?

      Thanks so much,

      --
      Karen

      posted in Developers' Forum
      K
      kwalkerman
    • 1 / 1