• Login
sketchucation logo sketchucation
  • Login
🔌 Quick Selection | Try Didier Bur's reworked classic extension that supercharges selections in SketchUp Download

Weird behavior with EntitiesObserver

Scheduled Pinned Locked Moved Developers' Forum
5 Posts 3 Posters 368 Views 3 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    robertokl
    last edited by 15 Mar 2014, 01:05

    Hi guys,

    I need to do a plugin that will be used to outline windows and doors in a matched photo. The idea is that the user click a button before starting the outlining, draw some rectangles and when he is finished, he clicks in the button again.

    It looks like a simple thing to do: When the user clicks the button for the first time, I add an EntitiesObserver and add all "onElementsAdded" to an array. When he clicks the button again, I loop through the array and do what I have to do (in my case, simply putting this entities in the deserved layer).

    The plugin works as expected when I create rectangles within a surface. The problem is when one of the edges of the rectangle touches one of the edges of a previous modeled object. Sketchup triggers the element added with the face of the previous modeled object.

    I know it maybe hard to understand the problem, but I'm leaving instructions on how to reproduce in the end of the post.

    I wonder if you guys have any ideas on what I could do.

    Thanks!

    To reproduce the error:

    1. Put the "bug.rb" file (uploaded here) in the plugin directory;
    2. Create a simple box;
    3. Click on plugin -> Start outlining window;
    4. Within a face of the box, draw a square, without touching any of the edges of the box;
    5. Click again on plugin -> Start outlining window;
    6. Take a look in the layers (activating the "Color by layer" helps a lot). The new square should be in the "Window" layer;
    7. Now, on another face of the box, redo step 3 to 5, but this time draw a rectangle and the bottom of the rectangle being drawn should touch the bottom of the box;
    8. Check the layers again, and the box's face should have gone to the window layer, while the window is in the main layer (sometimes it works though @_@);

    bug.rb

    1 Reply Last reply Reply Quote 0
    • D Offline
      driven
      last edited by 15 Mar 2014, 10:39

      hi

      to avoid clashes geometry clashes, you need to add a 'group' , assign it to your new layer, then add your entities to the group.

      have a look at linetool.rb and rectangle.rb for the 'tool' approach, and look at wrapping your code in your own namespace.

      john

      learn from the mistakes of others, you may not live long enough to make them all yourself...

      1 Reply Last reply Reply Quote 0
      • D Offline
        Dan Rathbun
        last edited by 15 Mar 2014, 11:27

        Yes as John said, in SketchUp, you ALWAYS should add primitives to Layer0, but within a group whose reference can be on ANY layer.

        But there is a trick to using a group. Just after you create the empty group, you need to temporarily add an object in the next Ruby statement. We usually add a cpoint at the ORIGIN
        temp_cpt = grp.entities.add_cpoint(ORIGIN)

        If you don't do this the SketchUp engine will delete the empty group, quite quickly.

        When done adding entities to the group, simply call temp_cpt.erase!

        Now, what all this means is, you cannot rely upon the native tools, for your plugin, because there is no way, via the API, to enter into a group (or component instance,) editing context. (The API only has a close context function.)

        So.. you will need to install the Examples (or Utilites,) from the SketchUp Team via the Extension Warehouse. An use the custom Ruby tool examples. Try modifying the LineTool or CylinderTool examples into you custom Rectangle Outline Tool. Or look search through this forum (or the SkechUcation Plugin Store,) for a custom rectangle tool that you might use as an example.

        With a custom tool, you receive the points the user chooses, and then your tool creates the actual geometry within the group.

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • D Offline
          Dan Rathbun
          last edited by 18 Mar 2014, 13:35

          @robert, the SketchUp Team has a rectangle tool available in the Extension Warehouse.
          At least it may give you ideas.

          http://extensions.sketchup.com/en/content/rotated-rectangle-tool

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • R Offline
            robertokl
            last edited by 19 Mar 2014, 18:15

            Hi Guys,

            Thanks for the replies.

            I wanted to do the way I described, cause that way the user could use any tool available to him. But, as it turns out, this seems undoable. I ended up creating my own line tool that would do what I wanted.

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            1 / 1
            • First post
              5/5
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement