• Login
sketchucation logo sketchucation
  • Login
πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

How to make a component-placer tool?

Scheduled Pinned Locked Moved Developers' Forum
9 Posts 3 Posters 299 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.
  • D Offline
    draftomatic
    last edited by 24 Jun 2011, 17:40

    I need to write a simple plugin that will allow a user to place a pre-defined object in the same way they can place one from the Components panel.

    So, user clicks my menu item, my component appears on their cursor, they decide where to place it, click, and then it's in the model. I'll want to do some behind-the-scenes processing before and after, naturally.

    Can someone give me advice on this? I've never made Tool's before... is that what I need here?

    1 Reply Last reply Reply Quote 0
    • D Offline
      draftomatic
      last edited by 24 Jun 2011, 17:57

      Hmm, I suppose I could distribute a component library with my plugin and allow users to use the built-in component panel. I could observe the definition so that I can hook into when it's placed, but I won't know when they BEGIN to place it.

      It seems to me that writing a custom tool for this would be difficult. Someone please tell me I wouldn't have to use onMouseMove to make the component follow the cursor while being placed!

      1 Reply Last reply Reply Quote 0
      • T Offline
        thomthom
        last edited by 24 Jun 2011, 18:39

        Model.place_component
        http://code.google.com/intl/no/apis/sketchup/docs/ourdoc/model.html#place_component

        Thomas Thomassen β€” SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • T Offline
          TIG Moderator
          last edited by 24 Jun 2011, 19:21

          ...or... entities.add_instance(definition, transformation) ?

          TIG

          1 Reply Last reply Reply Quote 0
          • T Offline
            thomthom
            last edited by 24 Jun 2011, 19:36

            @tig said:

            ...or... entities.add_instance(definition, transformation) ?

            Then he'd have to replicate the whole of the Place Component functionality in a tool...

            Thomas Thomassen β€” SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • T Offline
              TIG Moderator
              last edited by 24 Jun 2011, 20:28

              @thomthom said:

              @tig said:

              ...or... entities.add_instance(definition, transformation) ?

              Then he'd have to replicate the whole of the Place Component functionality in a tool...

              But he was talking about a 'tool'...
              This way his tool can get a picked-point and then insert a component at that point, then repeat if desired...
              Your way is much easier, but it will dump him out of the plugin code at the insertion, so no chance of repeat inserts in the same instance of the class [at least without incredible convolution??] ?

              TIG

              1 Reply Last reply Reply Quote 0
              • D Offline
                draftomatic
                last edited by 26 Jun 2011, 03:27

                Thanks for the help fellas.

                @tig said:

                But he was talking about a 'tool'...
                This way his tool can get a picked-point and then insert a component at that point, then repeat if desired...
                Your way is much easier, but it will dump him out of the plugin code at the insertion, so no chance of repeat inserts in the same instance of the class [at least without incredible convolution??] ?

                I can listen to DefinitionObserver# onComponentInstanceAdded to get back into Ruby after insertion.

                This is a neat way to create a tool that's not a Tool. πŸ˜† πŸ˜† πŸ˜†

                1 Reply Last reply Reply Quote 0
                • T Offline
                  thomthom
                  last edited by 26 Jun 2011, 10:42

                  @draftomatic said:

                  Thanks for the help fellas.

                  @tig said:

                  But he was talking about a 'tool'...
                  This way his tool can get a picked-point and then insert a component at that point, then repeat if desired...
                  Your way is much easier, but it will dump him out of the plugin code at the insertion, so no chance of repeat inserts in the same instance of the class [at least without incredible convolution??] ?

                  I can listen to DefinitionObserver# onComponentInstanceAdded to get back into Ruby after insertion.

                  This is a neat way to create a tool that's not a Tool. πŸ˜† πŸ˜† πŸ˜†

                  And you also need to listen to the ToolsObsever to check if the user activates another tool - instead of actually placing the component.

                  Thomas Thomassen β€” SketchUp Monkey & Coding addict
                  List of my plugins and link to the CookieWare fund

                  1 Reply Last reply Reply Quote 0
                  • D Offline
                    draftomatic
                    last edited by 26 Jun 2011, 17:12

                    @unknownuser said:

                    And you also need to listen to the ToolsObsever to check if the user activates another tool - instead of actually placing the component.

                    That doesn't seem to be an issue. onComponentInstanceAdded gets fired when the component is placed, not when you activate the tool.

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

                    Advertisement